📄 service1.asmx.cs
字号:
{
//Generate the Order Number
string OrderNo;
string error;
error="";
OrderNo = GenerateOrder();
string InsStr;
InsStr = "Insert Into DTOrders Values( @IN, @ON, @DO, @CN, @CA1, @CA2, @CC, @CS, @OB, @ST, @CT, @CCN)";
try
{
SqlCommand InsCom;
InsCom = new SqlCommand(InsStr, sqlConnection1);
sqlDataAdapter1.InsertCommand = InsCom;
sqlDataAdapter1.InsertCommand.Parameters.Add("@IN", SqlDbType.Char,10).Value = ISBN;
sqlDataAdapter1.InsertCommand.Parameters.Add("@ON", SqlDbType.Char,5).Value = OrderNo;
sqlDataAdapter1.InsertCommand.Parameters.Add("@DO",SqlDbType.DateTime,8).Value = Convert.ToDateTime(DateOrder).Date ;
sqlDataAdapter1.InsertCommand.Parameters.Add("@CN", SqlDbType.VarChar ,50).Value= CustName;
sqlDataAdapter1.InsertCommand.Parameters.Add("@CA1", SqlDbType.VarChar,50).Value= CustAddr1;
sqlDataAdapter1.InsertCommand.Parameters.Add("@CA2",SqlDbType.VarChar,50).Value=CustAddr2;
sqlDataAdapter1.InsertCommand.Parameters.Add("@CC",SqlDbType.VarChar,20).Value = CustCity;
sqlDataAdapter1.InsertCommand.Parameters.Add("@CS", SqlDbType.VarChar ,10).Value = CustState;
sqlDataAdapter1.InsertCommand.Parameters.Add("@OB",SqlDbType.VarChar , 50).Value=OrdBy;
sqlDataAdapter1.InsertCommand.Parameters.Add("@ST",SqlDbType.VarChar,20).Value=OrdStat;
sqlDataAdapter1.InsertCommand.Parameters.Add("@CT",SqlDbType.Char,10).Value=CardType;
sqlDataAdapter1.InsertCommand.Parameters.Add("@CCN",SqlDbType.VarChar,20).Value=CardNum;
if(sqlConnection1.State== ConnectionState.Closed )
{
sqlConnection1.Open ();
}
sqlDataAdapter1.InsertCommand.ExecuteNonQuery();
sqlConnection1.Close();
}
catch(Exception E1)
{
error = E1.Message;
}
string result;
if (error.Length != 0)
{
result = "Record Not Inserted due to the following reason: \n"+ error;
}
else
{
result = "Record Inserted!!";
}
return result;
}
[WebMethod(Description="This method searches for the details of all books published by Deepthoughts Publications.")]
public DataSet SearchALL()
{
string SelStr;
SelStr = "Select * from DTCatalog";
SqlCommand SelCom;
SelCom = new SqlCommand(SelStr, sqlConnection1);
sqlDataAdapter1.SelectCommand = SelCom;
sqlConnection1.Open();
sqlDataAdapter1.SelectCommand.ExecuteNonQuery();
sqlDataAdapter1.Fill(dsDetails1,"Details");
sqlConnection1.Close();
return dsDetails1;
}
[WebMethod(Description="This method searches for the details of the book based on the " +
" ISBN Number of the book")]
public DataSet SrchISBN(string ISBN)
{
string SelStr;
SelStr = "Select * from DTCatalog where ISBNNo = @ISB";
SqlCommand SelCom;
SelCom = new SqlCommand(SelStr, sqlConnection1);
sqlDataAdapter1.SelectCommand = SelCom;
sqlDataAdapter1.SelectCommand.Parameters.Add("@ISB",SqlDbType.Char, 10).Value = ISBN;
sqlConnection1.Open();
sqlDataAdapter1.SelectCommand.ExecuteNonQuery();
sqlDataAdapter1.Fill(dsDetails1,"Details");
sqlConnection1.Close();
return dsDetails1;
}
[WebMethod(Description="This method searches for the details of the book based on the " +
" the name of the Author")]
public DataSet SrchAuthor(string Author)
{
string SelStr;
SelStr = "Select * from DTCatalog where Author = @AU";
SqlCommand SelCom;
SelCom = new SqlCommand(SelStr, sqlConnection1);
sqlDataAdapter1.SelectCommand = SelCom;
sqlDataAdapter1.SelectCommand.Parameters.Add("@AU",SqlDbType.VarChar , 50).Value = Author;
sqlConnection1.Open();
sqlDataAdapter1.SelectCommand.ExecuteNonQuery();
sqlDataAdapter1.Fill(dsDetails1,"Details");
sqlConnection1.Close();
return dsDetails1;
}
[WebMethod(Description="This method searches for the details of the book based on the " +
" the Catalog of the books")]
public DataSet SrchCategory(string Catalog)
{
string SelStr;
SelStr = "Select * from DTCatalog where Category = @CA";
SqlCommand SelCom;
SelCom = new SqlCommand(SelStr, sqlConnection1);
sqlDataAdapter1.SelectCommand = SelCom;
sqlDataAdapter1.SelectCommand.Parameters.Add("@CA",SqlDbType.Char , 10).Value = Catalog;
sqlConnection1.Open();
sqlDataAdapter1.SelectCommand.ExecuteNonQuery();
sqlDataAdapter1.Fill(dsDetails1,"Details");
sqlConnection1.Close();
return dsDetails1;
}
[WebMethod(Description="This method searches for the details of the book based on the " +
" the Title of the books")]
public DataSet SrchTitle(string BkTitle)
{
string SelStr;
SelStr = "Select * from DTCatalog where BookTitle = @BT";
SqlCommand SelCom;
SelCom = new SqlCommand(SelStr, sqlConnection1);
sqlDataAdapter1.SelectCommand = SelCom;
sqlDataAdapter1.SelectCommand.Parameters.Add("@BT",SqlDbType.VarChar , 50).Value = BkTitle;
sqlConnection1.Open();
sqlDataAdapter1.SelectCommand.ExecuteNonQuery();
sqlDataAdapter1.Fill(dsDetails1,"Details");
sqlConnection1.Close();
return dsDetails1;
}
[WebMethod(Description="This method returns the order number of a customer")]
public string GenerateOrder()
{
string SelStr;
SelStr = "Select Count(*) From DTOrders";
SqlCommand SelCom;
SelCom = new SqlCommand(SelStr, sqlConnection1);
sqlConnection1.Open();
sqlDataAdapter1.SelectCommand = SelCom;
sqlDataAdapter1.Fill(dsDetails1,"Details");
sqlConnection1.Close();
string str;
str = dsDetails1.Tables["Details"].Rows[0][0].ToString ();
int val;
val = Convert.ToInt32(str);
val= val+1;
if(val>0 & val<=9)
{
str = "O000" + Convert.ToString(val);
}
else if(val>9 & val<=99)
{
str ="O00" + Convert.ToString (val);
}
else if(val>99 & val <=999)
{
str = "O0" + Convert.ToString (val);
}
else
{
str = "O" + Convert.ToString (val);
}
return str;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -