private void dgvPatner_CellDoubleClick(object sender, DataGridViewCellEventArgs e) { address = (AddressBook)dgvPatner.Rows[e.RowIndex].DataBoundItem; supplier = contxt.SupplierMasters.FirstOrDefault(o => o.AddressBookId == address.id); ShowContents(); state = FORMSTATE.EDIT; isNew = false; isEdit = true; SetButtons(); panelMid.Enabled = true; }
private void Save() { if (isNew) { address.CreatedBy = 1; address.CreatedDate = DateTime.Now; contxt.AddressBooks.Add(address); contxt.Entry(address).State = System.Data.Entity.EntityState.Added; contxt.SaveChanges(); contxt.Entry(address).Reload(); supplier.CreatedDate = DateTime.Now; supplier.CreatedBy = 1; supplier.AddressBookId = address.id; contxt.SupplierMasters.Add(supplier); contxt.Entry(supplier).State = System.Data.Entity.EntityState.Added; contxt.SaveChanges(); } if (isEdit) { // Update mechanism should be coded AddressBook book = contxt.AddressBooks.Where(o => o.id == address.id).FirstOrDefault(); if (book != null) { book.AddressLine01 = address.AddressLine01; book.AddressLine02 = address.AddressLine02; book.AddressName = address.AddressName; book.AddressType = address.AddressType; book.City = address.City; book.ModifiedBy = 1; book.ModifiedDate = DateTime.Now; contxt.Entry(book).State = System.Data.Entity.EntityState.Modified; contxt.SaveChanges(); SupplierMaster master = contxt.SupplierMasters.Where(o => o.id == supplier.id).FirstOrDefault(); if (master != null) { master.AddressBookId = address.id; master.ModifiedBy = 1; master.ModifiedDate = DateTime.Now; master.RegNo = supplier.RegNo; master.SavingRegDate = supplier.SavingRegDate; master.SavingRegistered = supplier.SavingRegistered; master.WelfareId = supplier.WelfareId; master.WelfareRegDate = supplier.WelfareRegDate; master.WelfareRegistered = supplier.WelfareRegistered; master.Status = supplier.Status; contxt.Entry(master).State = System.Data.Entity.EntityState.Modified; contxt.SaveChanges(); } } } }
private void ShowContents() { dtTrnDate.Value = ledger.TrnDate; product = products.FirstOrDefault(o => o.id == ledger.ProductId); SupplierMaster supplier = contxt.SupplierMasters.FirstOrDefault(o => o.id == ledger.SupplierId); partner = partners.FirstOrDefault(o => o.id == supplier.AddressBookId); cboSup.SelectedItem = partner; cboProduct.SelectedItem = product; cboSup.SelectedItem = partner; nQty.Value = ledger.Quantity; nAmt.Value = (decimal)ledger.TotalPrice; tbRef.Text = ledger.Ref02; //throw new NotImplementedException(); }
private void FormSupplierMaster_Load(object sender, EventArgs e) { contxt = new PMModel(); bookType = new AddressBookType(); bookTypes = new List <AddressBookType>(); addresses = new List <AddressBook>(); routes = new List <AddressBook>(); factories = new List <FactoryMaster>(); address = new AddressBook(); route = new AddressBook(); factory = new FactoryMaster(); supplier = new SupplierMaster(); //TypeName = "Suppliers"; GetAddressBookTypeList(); GetRoutes(); GetFactories(); state = FORMSTATE.NOOP; SetButtons(); panelMid.Enabled = false; AdjustFields(); LoadPartners(); isFormLoading = false; }
private void ImportOldData() { //System.Data.OleDb.OleDbConnection olecn; //System.Data.OleDb.OleDbCommand olecmd; //System.Data.OleDb.OleDbDataAdapter oleda; //string oldcn = System.Configuration.ConfigurationManager.ConnectionStrings["blold"].ConnectionString; //olecn = new System.Data.OleDb.OleDbConnection(oldcn); string sql = "Select * from Main_Reg"; DataTable olds = new DataTable(); Application.UseWaitCursor = true; OldBlObj old = new OldBlObj(); olds = old.GetDataTable(sql); int reccnt = olds.Rows.Count; int intval = reccnt / 100; int newsup = 0; reccnt = 0; foreach (DataRow dr in olds.Rows) { supplier.RegNo = int.Parse(dr["RegNo"].ToString()); supplier.PayMode = dr["PayMode"].ToString(); supplier.BankAccount = dr["AcNumber"].ToString(); supplier.SavingRegistered = int.Parse(dr["SavingReg"].ToString() == "True" ? "1" :"0"); supplier.WelfareRegistered = dr["WelfareReg"].ToString() == "Yes" ? 1 : 0; supplier.FactoryId = factory.id; DateTime rd; if (DateTime.TryParse(dr["RegDate"].ToString(), out rd)) { supplier.RegDate = rd; } route = routes.Where(o => o.AddressName.Trim() == dr["RouteName"].ToString().Trim()).FirstOrDefault(); if (route == null) { throw new Exception("The route is not registered"); } else { supplier.RouteId = route.id; } //if (dr["WelfareReg"].ToString() == "Yes") // supplier.WelfareRegDate= DateTime.Parse(dr[]) SupplierMaster stemp = contxt.SupplierMasters.FirstOrDefault(o => o.RegNo == supplier.RegNo); if (stemp == null) { isNew = true; isEdit = false; address.CreatedBy = 1; address.CreatedDate = DateTime.Now; contxt.AddressBooks.Add(address); contxt.Entry(address).State = System.Data.Entity.EntityState.Added; contxt.SaveChanges(); contxt.Entry(address).Reload(); supplier.CreatedDate = DateTime.Now; supplier.CreatedBy = 1; supplier.AddressBookId = address.id; contxt.SupplierMasters.Add(supplier); contxt.Entry(supplier).State = System.Data.Entity.EntityState.Added; newsup++; } else { isNew = false; isEdit = true; AddressBook atemp = contxt.AddressBooks.Where(o => o.id == stemp.AddressBookId).FirstOrDefault(); if (atemp == null) { address.AddressType = bookType.id; address.FactoryId = factory.id; address.AddressName = dr["RegName"].ToString(); address.AddressLine01 = dr["Address"].ToString(); address.TP01 = dr["TPno"].ToString(); address.CreatedBy = 1; address.CreatedDate = DateTime.Now; contxt.AddressBooks.Add(address); contxt.Entry(address).State = System.Data.Entity.EntityState.Added; contxt.SaveChanges(); contxt.Entry(address).Reload(); } address.AddressType = bookType.id; address.FactoryId = factory.id; address.id = atemp.id; address.AddressName = dr["RegName"].ToString(); address.AddressLine01 = dr["Address"].ToString(); address.TP01 = dr["TPno"].ToString(); address.ModifiedBy = 1; address.ModifiedDate = DateTime.Now; contxt.Entry(atemp).CurrentValues.SetValues(address); contxt.SaveChanges(); // Here we are going to update supplier supplier.id = stemp.id; supplier.AddressBookId = address.id; supplier.ModifiedBy = 1; supplier.ModifiedDate = DateTime.Now; contxt.Entry(stemp).CurrentValues.SetValues(supplier); contxt.SaveChanges(); } reccnt++; int upd = reccnt % 100 == 0 ? pgb.Value++ : 0; pgb.Refresh(); address = new AddressBook(); supplier = new SupplierMaster(); } Application.UseWaitCursor = false; MessageBox.Show(" Suppliers imported =" + newsup); }