protected void btnSaveSupplier_ServerClick(object sender, EventArgs e) { SupplierObject obj = new SupplierObject(); obj.Supplier_NameProp = txtSupplierName.Value; obj.Address_Line_1Prop = txtSupplierAddress.Value; obj.Address_Line_2Prop = txtSupplierAddressLine2.Value; obj.CityProp = txtSupplierCity.Value; obj.CodeProp = txtSupplierCode.Value; obj.Telephone1Prop = txtSupplierTelephone.Value; obj.Telephone2Prop = txtSupplierTelephone2.Value; obj.FaxProp = txtSupplierFax.Value; obj.EmailProp = txtSupplierEmail.Value; obj.RepresentativeProp = txtSupplierRepresentative.Value; obj.VAT_NumberProp = txtSupplierVATNumber.Value; obj.CK_NumberProp = txtSupplierCKNumber.Value; obj.DisableProp = chkBoxSupplierDisable.Checked; obj.Wholesale_SupplierProp = chkSupplierWholesale.Checked; ManageSupplier supplierObj = new ManageSupplier(); bool success = supplierObj.updateASupplier(ConfigurationManager.ConnectionStrings["MVSSqlDev2008ConnectionString"].ConnectionString, obj, Convert.ToInt32(Session["rowIndex"])); Session.Remove("rowIndex"); if (success) { divSuccess.Visible = true; } else divFailure.Visible = true; }
public List<SqlParameter> insertParameters(SupplierObject supplierObj) { List<SqlParameter> insertParamsArray = new List<SqlParameter>(); insertParamsArray.Add(new SqlParameter("@Supplier_name", supplierObj.Supplier_NameProp)); insertParamsArray.Add(new SqlParameter("@Address_Line_1", supplierObj.Address_Line_1Prop)); insertParamsArray.Add(new SqlParameter("@Address_Line_2", supplierObj.Address_Line_2Prop)); insertParamsArray.Add(new SqlParameter("@City", supplierObj.CityProp)); insertParamsArray.Add(new SqlParameter("@Code", supplierObj.CodeProp)); insertParamsArray.Add(new SqlParameter("@Telephone1", supplierObj.Telephone1Prop)); insertParamsArray.Add(new SqlParameter("@Telephone2", supplierObj.Telephone2Prop)); insertParamsArray.Add(new SqlParameter("@Fax", supplierObj.FaxProp)); insertParamsArray.Add(new SqlParameter("@Email", supplierObj.EmailProp)); insertParamsArray.Add(new SqlParameter("@Wholesale_Supplier", supplierObj.Wholesale_SupplierProp)); insertParamsArray.Add(new SqlParameter("@Cellphone", supplierObj.Cellphone1Prop)); insertParamsArray.Add(new SqlParameter("@VAT_Number", supplierObj.VAT_NumberProp)); insertParamsArray.Add(new SqlParameter("@Representative", supplierObj.RepresentativeProp)); insertParamsArray.Add(new SqlParameter("@CK_Number", supplierObj.CK_NumberProp)); insertParamsArray.Add(new SqlParameter("@Disable", supplierObj.DisableProp)); return insertParamsArray; }
public Boolean updateASupplier(string connectionString, SupplierObject supplierObj, int rowIndex) { try { conn = DBUtility.createConnection(connectionString); SqlCommand cmdIns = DBUtility.PrepareSPCommand("sp_UpdateSupplier", insertParameters(supplierObj), conn); cmdIns.Parameters.Add(new SqlParameter("@Supplier_Code", rowIndex)); int rowsUpdated = cmdIns.ExecuteNonQuery(); cmdIns.Dispose(); DBUtility.Close(conn); conn.Dispose(); if (rowsUpdated > 0) { return true; } else return false; } catch (Exception ex) { throw new Exception(ex.ToString(), ex); } finally { DBUtility.Close(conn); conn.Dispose(); } }
public bool insert(SupplierObject SupplierObj, string connectionString) { try { conn = DBUtility.createConnection(connectionString); SqlCommand cmdIns = DBUtility.PrepareSPCommand("sp_InsertSupplier", insertParameters(SupplierObj), conn); int rowsUpdated = cmdIns.ExecuteNonQuery(); // cmdIns.Parameters.Clear(); // cmdIns.CommandText = "SELECT @@IDENTITY"; // // Get the last inserted id. // int insertID = Convert.ToInt32(cmdIns.ExecuteScalar()); cmdIns.Dispose(); DBUtility.Close(conn); conn.Dispose(); if (rowsUpdated > 0) { return true; } else return false; } catch (Exception ex) { throw new Exception(ex.ToString(), ex); } finally { DBUtility.Close(conn); conn.Dispose(); } }