protected void BTNSubmit_Click(object sender, EventArgs e) { Seller seller = new Seller(); seller.SellerCode = TXTCode.Text; seller.SellerName = TXTName.Text; seller.SellerAddress = TXTAddress.Text; seller.SellerCity = TXTCity.Text; seller.SellerProvince = DDLProvince.SelectedValue; seller.SellerPostalCode = TXTPostal.Text; seller.SellerPhone = TXTPhone.Text; seller.SellerOtherPhone = TXTOtherPhone.Text; seller.SellerFax = TXTFax.Text; seller.ContactFirstName = TXTFirstName.Text; seller.ContactLastName = TXTLastName.Text; seller.SellerGSTNumber = TXTGSTNumber.Text; seller.SellerIsPrivate = CHKPrivate.Checked; try { //Call DAL int id = sellerService.CreateSeller(seller); } catch (Exception ex) { AlertDiv.InnerHtml = "<div class=\"alert alert-danger fade in\">" + "<a href=\"#\" class=\"close\" data-dismiss=\"alert\">×</a>" + "<strong>Error! </strong><label id=\"Alert\" runat=\"server\">" + ex.Message + "</label></div>"; } }
//Get all Sellers public int CreateSeller(Seller seller) { int id = 0; MySqlConnection conn = new MySqlConnection(connectionString); conn.Open(); try { MySqlCommand cmd = new MySqlCommand(); cmd.CommandText = "ADD_SELLER"; cmd.Parameters.Add(new MySqlParameter("@N_SellerCode", seller.SellerCode)); cmd.Parameters.Add(new MySqlParameter("@N_SellerName", seller.SellerName)); cmd.Parameters.Add(new MySqlParameter("@N_SellerAddress", seller.SellerAddress)); cmd.Parameters.Add(new MySqlParameter("@N_SellerCity", seller.SellerCity)); cmd.Parameters.Add(new MySqlParameter("@N_SellerProvince", seller.SellerProvince)); cmd.Parameters.Add(new MySqlParameter("@N_SellerPostalCode", seller.SellerPostalCode)); cmd.Parameters.Add(new MySqlParameter("@N_SellerPhone", seller.SellerPhone)); cmd.Parameters.Add(new MySqlParameter("@N_SellerOtherPhone", seller.SellerOtherPhone)); cmd.Parameters.Add(new MySqlParameter("@N_SellerFax", seller.SellerFax)); cmd.Parameters.Add(new MySqlParameter("@N_ContactFirstName", seller.ContactFirstName)); cmd.Parameters.Add(new MySqlParameter("@N_ContactLastName", seller.ContactLastName)); //cmd.Parameters.Add(new MySqlParameter("@N_SellerFileNumber", seller.ConFile)); cmd.Parameters.Add(new MySqlParameter("@N_SellerPrivate", seller.SellerIsPrivate)); cmd.Parameters.Add(new MySqlParameter("@N_GSTNumber", seller.SellerGSTNumber)); MySqlParameter returnParameter = new MySqlParameter(); returnParameter.Direction = System.Data.ParameterDirection.ReturnValue; cmd.Parameters.Add(returnParameter); cmd.CommandType = CommandType.StoredProcedure; cmd.Connection = conn; cmd.ExecuteNonQuery(); id = Convert.ToInt32(returnParameter.Value.ToString()); } catch (Exception ex) { //Panic throw ex; } finally { //Tie the loose ends here conn.Close(); } return id; }
//Get all Sellers public int UpdateSeller(Seller seller) { int id = 0; MySqlConnection conn = new MySqlConnection(connectionString); conn.Open(); try { MySqlCommand cmd = new MySqlCommand(); cmd.CommandText = "UPDATE_SELLER"; cmd.Parameters.Add(new MySqlParameter("@N_SellerID", seller.SellerID)); cmd.Parameters.Add(new MySqlParameter("@N_SellerCode", seller.SellerCode)); cmd.Parameters.Add(new MySqlParameter("@N_SellerName", seller.SellerName)); cmd.Parameters.Add(new MySqlParameter("@N_SellerAddress", seller.SellerAddress)); cmd.Parameters.Add(new MySqlParameter("@N_SellerCity", seller.SellerCity)); cmd.Parameters.Add(new MySqlParameter("@N_SellerProvince", seller.SellerProvince)); cmd.Parameters.Add(new MySqlParameter("@N_SellerPostalCode", seller.SellerPostalCode)); cmd.Parameters.Add(new MySqlParameter("@N_SellerPhone", seller.SellerPhone)); cmd.Parameters.Add(new MySqlParameter("@N_SellerOtherPhone", seller.SellerOtherPhone)); cmd.Parameters.Add(new MySqlParameter("@N_SellerFax", seller.SellerFax)); cmd.Parameters.Add(new MySqlParameter("@N_ContactFirstName", seller.ContactFirstName)); cmd.Parameters.Add(new MySqlParameter("@N_ContactLastName", seller.ContactLastName)); //cmd.Parameters.Add(new MySqlParameter("@N_SellerFileNumber", seller.ConFile)); cmd.Parameters.Add(new MySqlParameter("@N_SellerPrivate", seller.SellerIsPrivate)); cmd.Parameters.Add(new MySqlParameter("@N_GSTNumber", seller.SellerGSTNumber)); cmd.CommandType = CommandType.StoredProcedure; cmd.Connection = conn; cmd.ExecuteNonQuery(); } catch (Exception ex) { //Panic throw ex; } finally { //Tie the loose ends here conn.Close(); } return id; }