To add materials, you must bind the materials type, device name, province, end customer, and other information. The front-end page is as follows:
Foreground. aspx
<Asp: Content ID = "content2" contentplaceholderid = "maincontent" runat = "server">
<P>
Barcode: <asp: textbox id = "txt_barcode" runat = "server"> </ASP: textbox>
</P>
<P>
Materialtype: <asp: dropdownlist id = "ddlmaterialtype" runat = "server" Height = "16px"
Width = "125px" autopostback = "true">
</ASP: dropdownlist>
</P>
<P>
Terminalname: <asp: dropdownlist id = "ddlterminal" runat = "server" Height = "16px"
Width = "126px" autopostback = "true">
</ASP: dropdownlist>
</P>
<P>
Provinces: <asp: dropdownlist id = "ddlprovince" runat = "server" Height = "16px"
Width = "111px">
</ASP: dropdownlist>
</P>
<P>
Devicename: <asp: dropdownlist id = "ddldevice" runat = "server"
Height = "16px" width = "125px">
</ASP: dropdownlist>
</P>
<P>
Usetime:
<Asp: textbox id = "tb_usetime" runat = "server"> </ASP: textbox>
</P>
<P>
Status: <asp: radiobuttonlist id = "rbstatus" runat = "server" autopostback = "true"
Repeatdirection = "horizontal">
<Asp: listitem selected = "true" value = "0"> sended </ASP: listitem>
<Asp: listitem value = "1"> inbox </ASP: listitem>
<Asp: listitem value = "2"> used </ASP: listitem>
</ASP: radiobuttonlist>
</P>
<P>
<Asp: button id = "btnok" runat = "server" onclick = "btnok_click" text = "comfirm"/>
& Nbsp;
<Asp: button id = "btncancel" runat = "server" onclick = "btncancel_click"
TEXT = "cancel"/>
</P>
</ASP: content>
Backend Aspx. CS:
Private sqlconnection conn;
Private sqlcommand cmd;
Private const string connstr = "Data Source = szxy1zwx2166591 \ sqlexpress; initial catalog = dbdevice; Integrated Security = true ";
Protected void page_load (Object sender, eventargs E)
{
If (! Ispostback)
{
This. tb_usetime.text = datetime. Now. tostring ("yyyy-mm-dd hh: mm: SS ");
Bindmaterialtype ();
Bindterminal ();
}
}
Void bindterminal ()
{
String terminalsql = "select M. terminalid, M. terminalname from tbl_terminal M ";
Datatable dt = gettable (terminalsql );
If (DT! = NULL & DT. Rows. Count> 0)
{
This. ddlterminal. datasource = DT;
This. ddlterminal. datatextfield = "terminalname ";
This. ddlterminal. datavaluefield = "terminalid ";
This. ddlterminal. databind ();
}
}
Void bindmaterialtype ()
{
String SQL = "select T. typeid, T. typename from tbl_comsumermaterialtype t ";
Datatable dt = gettable (SQL );
If (DT! = NULL & DT. Rows. Count> 0)
{
This. ddlmaterialtype. datasource = DT;
This. ddlmaterialtype. datatextfield = "typename ";
This. ddlmaterialtype. datavaluefield = "typeid ";
This. ddlmaterialtype. databind ();
}
}
# Region database operations
/// <Summary>
/// Link
/// </Summary>
/// <Returns> </returns>
Private sqlconnection getconn ()
{
If (conn = NULL)
Conn = new sqlconnection (connstr );
If (conn. State = connectionstate. Closed)
Conn. open ();
Else if (conn. State = connectionstate. Broken)
{
Conn. Close ();
Conn. open ();
} Return conn;
}
/// <Summary>
/// Add, delete, modify, and query operations
/// </Summary>
/// <Param name = "SQL"> </param>
/// <Returns> </returns>
Private int executenonquery (string SQL)
{
Try
{
Cmd = new sqlcommand (SQL, getconn ());
Return cmd. executenonquery ();
}
Catch
{
Return 0;
}
Finally
{
Conn. Close ();
}
}
/// <Summary>
/// Read data
/// </Summary>
/// <Param name = "SQL"> </param>
/// <Returns> </returns>
Private sqldatareader executereader (string SQL)
{
Try
{
Cmd = new sqlcommand (SQL, getconn ());
Return cmd. executereader ();
}
Catch
{
Return NULL;
}
Finally
{
Conn. Close ();
}
}
/// <Summary>
/// The table data
/// </Summary>
/// <Param name = "SQL"> </param>
/// <Returns> </returns>
Private datatable gettable (string SQL)
{
Try
{
Sqldataadapter da = new sqldataadapter (SQL, getconn ());
Dataset DS = new dataset ();
Da. Fill (DS );
Return Ds. Tables [0];
}
Catch
{
Return NULL;
}
Finally
{
Conn. Close ();
}
}
# Endregion
Protected void btncancel_click (Object sender, eventargs E)
{
}
Protected void btnok_click (Object sender, eventargs E)
{
String serialnumber = getdate () + getrandom (). tostring ();
String status = This. rbstatus. selectedvalue;
String Terminal = This. ddlterminal. selecteditem. value;
String materialtype = This. ddlmaterialtype. selectedvalue;
}
Private int getrandom ()
{
Random rad = new random (); // instantiate the random number generator rad;
Int value = rad. Next (1000,100 00 );//
Return value;
}
Private string getdate ()
{
String date = datetime. Now. tostring ("yyyymmddhhmmss ");
Return date;
}