private static void InsertData(Product obj, string newDB) { if (CheckData(obj, newDB) == false) { obj.Product_name = Checks.Escape(obj.Product_name); obj.Producttype_id = CProducttype_exten.GetId_Name(obj.Producttype_id); obj.Hsncode_id = CHsncode_exten.GetId_Name(obj.Hsncode_id); obj.Unit_id = CUnit_exten.GetId_Name(obj.Unit_id); CProduct.Insert(obj, new DAL()); } ; }
private static bool CheckData(Product obj, string newDB) { string q = "USE " + newDB + "; "; q += "SELECT * FROM " + PRODUCT.PRODUCT_TBL + " WHERE " + PRODUCT.PRODUCT_NAME + " = '" + obj.Product_name + "'; "; using (IDataReader redr = new DAL().Listreader(q)) { while (redr.Read() == true) { obj.Product_id = redr[PRODUCT.PRODUCT_ID].ToString(); obj.Product_name = Checks.Escape(obj.Product_name); obj.Producttype_id = CProducttype_exten.GetId_Name(obj.Producttype_id); obj.Hsncode_id = CHsncode_exten.GetId_Name(obj.Hsncode_id); obj.Unit_id = CUnit_exten.GetId_Name(obj.Unit_id); CProduct.Update(obj, new DAL()); return(true); } return(false); } }
private void Save_Event() { if (Validation() != false) { switch (fAction) { case BtnEvent.Open: this.Hide(); Form_NeedToRefresh(); break; case BtnEvent.New: try { var vData = CollectData(); dalsession = new DAL(); dalsession.BeginTransaction(); CProduct.Insert(vData, dalsession); dalsession.Commit(); MessageBox.Show(this.FindForm(), "Record Saved Successfully.", "Save...", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); this.Hide(); Form_NeedToRefresh(); } catch (Exception ex) { if (dalsession != null) { dalsession.Rollback(); } MessageBox.Show(this.FindForm(), "Something Goes Wrong \r\n" + ex.Message, "Could Not Save...", MessageBoxButtons.OK, MessageBoxIcon.Error); SetFocus(); return; } break; case BtnEvent.Edit: try { var vData = CollectData(); dalsession = new DAL(); dalsession.BeginTransaction(); CProduct.Update(vData, dalsession); dalsession.Commit(); MessageBox.Show(this.FindForm(), "Record Updated Successfully.", "Update...", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); this.Hide(); Form_NeedToRefresh(); } catch (Exception ex) { if (dalsession != null) { dalsession.Rollback(); } MessageBox.Show(this.FindForm(), "Something Goes Wrong \r\n" + ex.Message, "Could Not Update...", MessageBoxButtons.OK, MessageBoxIcon.Error); SetFocus(); return; } break; case BtnEvent.Delete: try { dalsession = new DAL(); dalsession.BeginTransaction(); CProduct.Delete(vId, dalsession); dalsession.Commit(); MessageBox.Show(this.FindForm(), "Record Deleted Successfully.", "Delete...", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); this.Hide(); Form_NeedToRefresh(); } catch (Exception ex) { if (dalsession != null) { dalsession.Rollback(); } MessageBox.Show(this.FindForm(), "Something Goes Wrong \r\n" + ex.Message, "Could Not Update...", MessageBoxButtons.OK, MessageBoxIcon.Error); SetFocus(); return; } break; case BtnEvent.Print: this.Hide(); Form_NeedToRefresh(); break; } } }