public static int Update <TObject>(TObject obj) where TObject : class { using (var ctx = new AccountingSystem()) { ctx.Set(typeof(TObject)).Attach(obj); ctx.Entry(obj).State = System.Data.Entity.EntityState.Modified; ctx.SaveChanges(); return(0); } }
private void update_Click(object sender, EventArgs e) { splashScreenManager1.ShowWaitForm(); Thread.Sleep(1000); using (var db = new AccountingSystem()) { try { var Control = db.PermissionControls.First(x => x.CGroupId.Equals(GroupId.Text.ToString())); Control.CAdmin = Admin.Checked; Control.CSells = Sells.Checked; Control.CBuys = Buys.Checked; Control.CWarehouse = Warehouse.Checked; Control.CAccount = Account.Checked; Control.CVendorSupplier = VendorSupplier.Checked; Control.COther = Other.Checked; db.Entry(Control).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); } catch (System.Data.Entity.Validation.DbEntityValidationException dbEx) { Exception raise = dbEx; foreach (var validationErrors in dbEx.EntityValidationErrors) { foreach (var validationError in validationErrors.ValidationErrors) { string message = string.Format("{0}:{1}", validationErrors.Entry.Entity.ToString(), validationError.ErrorMessage); raise = new InvalidOperationException(message, raise); } } throw raise; } catch (Exception dbEx) { Exception raise = dbEx; var val = dbEx.InnerException; MessageBox.Show(val.ToString()); //throw raise; } } fillsearch(); splashScreenManager1.CloseWaitForm(); }
private void update_Click(object sender, EventArgs e) { splashScreenManager1.ShowWaitForm(); Thread.Sleep(1000); using (var db = new AccountingSystem()) { try { var Branch = db.Branches.First(x => x.BId.Equals(Id.Text.ToString())); Branch.BName = search.Text; Branch.BId = Id.Text; Branch.BStatus = Status.Checked.ToString(); Branch.BPhone1 = Phone1.Text; Branch.BPhone2 = Phone2.Text; Branch.BAddress = Address.Text; db.Branches.Add(Branch); db.Entry(Branch).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); } catch (System.Data.Entity.Validation.DbEntityValidationException dbEx) { Exception raise = dbEx; foreach (var validationErrors in dbEx.EntityValidationErrors) { foreach (var validationError in validationErrors.ValidationErrors) { string message = string.Format("{0}:{1}", validationErrors.Entry.Entity.ToString(), validationError.ErrorMessage); raise = new InvalidOperationException(message, raise); } } throw raise; } catch (Exception dbEx) { Exception raise = dbEx; var val = dbEx.InnerException; MessageBox.Show(val.ToString()); //throw raise; } } fillsearch(); splashScreenManager1.CloseWaitForm(); }
private void simpleButton1_Click(object sender, EventArgs e) { if (GroupName.Text.Trim().Equals(String.Empty)) { MessageBox.Show("الرجاء ادخال اسم المجموعة"); } else { using (var db = new AccountingSystem()) { var groupEntity = db.ItemGroups.Create(); groupEntity.Name = GroupName.Text; groupEntity.Type = groupStatus.Checked ? 1 : 0; try { if (isEditForm) { groupEntity.Id = i; db.Entry(groupEntity).State = System.Data.Entity.EntityState.Modified; } else { db.ItemGroups.Add(groupEntity); } db.SaveChanges(); if (!isEditForm) { GroupName.Text = ""; GroupId.Text = (int.Parse(GroupId.Text) + 1) + ""; groupStatus.Checked = false; } } catch (System.Data.Entity.Validation.DbEntityValidationException dbEx) { Exception raise = dbEx; foreach (var validationErrors in dbEx.EntityValidationErrors) { foreach (var validationError in validationErrors.ValidationErrors) { string message = string.Format("{0}:{1}", validationErrors.Entry.Entity.ToString(), validationError.ErrorMessage); raise = new InvalidOperationException(message, raise); } } throw raise; } catch (Exception dbEx) { Exception raise = dbEx; var val = dbEx.InnerException; MessageBox.Show(val.ToString()); } } } }
private void simpleButton1_Click(object sender, EventArgs e) { string ErrorMessage = ""; if (GroupName.Text.Equals("")) { ErrorMessage = "الرجاء ادخال الأسم"; } else if (StoreMobile.Text.Equals("")) { ErrorMessage = "الرجاء ادخال التلفون"; } else if (StoreSize.Text.Equals("")) { ErrorMessage = "الرجاء ادخال المساحة"; } else if (StoreAddress.Text.Equals("")) { ErrorMessage = "الرجاء ادخال العنوان"; } else if (StoreBranch.Text.Equals("")) { ErrorMessage = "الرجاء اختيار الفرع"; } using (var db = new AccountingSystem()) { var StoreEntity = db.Wharehouses.Create(); if (ErrorMessage.Equals("")) { StoreEntity.StoreName = GroupName.Text; StoreEntity.Status = StoreStatus.Checked; StoreEntity.Mobile = StoreMobile.Text; StoreEntity.Size = int.Parse(StoreSize.Text); StoreEntity.Address = StoreAddress.Text; StoreEntity.BranchID = int.Parse(StoreBranch.Text); if (isEditForm) { StoreEntity.Id = i; db.Entry(StoreEntity).State = System.Data.Entity.EntityState.Modified; } else { db.Wharehouses.Add(StoreEntity); } try { db.SaveChanges(); if (!isEditForm) { GroupName.Text = ""; StoreStatus.Checked = false; StoreMobile.Text = ""; StoreSize.Text = ""; StoreAddress.Text = ""; StoreBranch.Text = ""; GroupId.Text = (int.Parse(GroupId.Text) + 1) + ""; } } catch (System.Data.Entity.Validation.DbEntityValidationException dbEx) { Exception raise = dbEx; foreach (var validationErrors in dbEx.EntityValidationErrors) { foreach (var validationError in validationErrors.ValidationErrors) { string message = string.Format("{0}:{1}", validationErrors.Entry.Entity.ToString(), validationError.ErrorMessage); raise = new InvalidOperationException(message, raise); } } throw raise; } catch (Exception dbEx) { Exception raise = dbEx; var val = dbEx.InnerException; MessageBox.Show(val.ToString()); } } else { MessageBox.Show(ErrorMessage); } } }
private void update_Click(object sender, EventArgs e) { if (VendName.Text.Equals("") || VendName.Text.Equals(" ")) { DevExpress.XtraEditors.XtraMessageBox.Show("الرجاء ادخال اسم العميل"); } else if (VendBalance.Text.Equals("") || VendBalance.Text.Equals(" ")) { DevExpress.XtraEditors.XtraMessageBox.Show("الرجاء الرصيد الابتدائي"); } else if (VendLedger.Text.Equals("") || VendLedger.Text.Equals(" ")) { DevExpress.XtraEditors.XtraMessageBox.Show("الرجاء اختيار حساب الاستاذ"); } else if (VendSupplementingAccount.Text.Equals("") || VendSupplementingAccount.Text.Equals(" ")) { DevExpress.XtraEditors.XtraMessageBox.Show("الرجاء اختيار الحساب المكمل"); } else { splashScreenManager1.ShowWaitForm(); Thread.Sleep(1000); //Wait pleaseWait = new Wait(); //Application.DoEvents(); //pleaseWait.Show(); save.Visible = false; news.Visible = true; update.Visible = true; VendorSet Sup = new VendorSet(); //InitializeComponent(); using (var db = new AccountingSystem()) { try { var VendorSet = db.VendorSets.First(x => x.VendorId.Equals(VendCode.Text)); VendorSet.VendorId = VendCode.Text; VendorSet.VendorName = VendName.Text; VendorSet.VendorStartBalance = VendBalance.Text; VendorSet.VendorStartBlnsDate = VendDateBalance.Value.ToString(); VendorSet.VendorTypeOfBalance = VendTypeBalance.Text; VendorSet.VendorStatus = VendStatus.Checked.ToString(); VendorSet.VendorBranch = VendResponsbile.Text; VendorSet.VendorBranchCurrency = VendCurrency.Text; VendorSet.VendorSupplementingAccount = VendSupplementingAccount.EditValue.ToString(); VendorSet.VendorLedger = VendLedger.EditValue.ToString(); VendorSet.VendorCompanyName = VendNameCompany.Text; VendorSet.VendorResponsible = VendBranch.Text; VendorSet.VendorArea = VendArea.Text; VendorSet.VendorAddress = VendAddress.Text; VendorSet.VendorPhone1 = VendPhone1.Text; VendorSet.VendorPhone2 = VendPhone2.Text; VendorSet.VendorWebsite = VendWebsite.Text; VendorSet.VendorEmail = VendEmail.Text; VendorSet.VendorBankNoAccount = VendBankNoAccount.Text; VendorSet.VendorBankName = VendBankName.Text; VendorSet.VendorBankBranach = VendBankBranch.Text; db.Entry(VendorSet).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); } catch (System.Data.Entity.Validation.DbEntityValidationException dbEx) { Exception raise = dbEx; foreach (var validationErrors in dbEx.EntityValidationErrors) { foreach (var validationError in validationErrors.ValidationErrors) { string message = string.Format("{0}:{1}", validationErrors.Entry.Entity.ToString(), validationError.ErrorMessage); raise = new InvalidOperationException(message, raise); } } throw raise; } catch (Exception dbEx) { Exception raise = dbEx; var val = dbEx.InnerException; MessageBox.Show(val.ToString()); //throw raise; } } fillsearch(); splashScreenManager1.CloseWaitForm(); } }
private void update_Click(object sender, EventArgs e) { if (search.Text.Equals("") || search.Text.Equals(" ")) { DevExpress.XtraEditors.XtraMessageBox.Show("الرجاء ادخال اسم المستخدم"); } else if (Branch.Text.Equals("") || Branch.Text.Equals(" ")) { DevExpress.XtraEditors.XtraMessageBox.Show("الرجاء اختيار الفرع"); } else if (Password.Text.Equals("") || Password.Text.Equals(" ")) { DevExpress.XtraEditors.XtraMessageBox.Show("الرجاء ادخال كلمة المرور"); } else { save.Visible = false; news.Visible = true; update.Visible = true; VendorSet Sup = new VendorSet(); //InitializeComponent(); splashScreenManager1.ShowWaitForm(); Thread.Sleep(1000); using (var db = new AccountingSystem()) { try { var User = db.Users.First(x => x.UCode.Equals(Code.Text)); User.UCode = Code.Text; User.UName = search.Text; User.UStatus = Status.Checked.ToString(); User.UBranch = Branch.EditValue.ToString(); User.UPassword = Password.Text; User.UGroup = Group.Text; db.Entry(User).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); } catch (System.Data.Entity.Validation.DbEntityValidationException dbEx) { Exception raise = dbEx; foreach (var validationErrors in dbEx.EntityValidationErrors) { foreach (var validationError in validationErrors.ValidationErrors) { string message = string.Format("{0}:{1}", validationErrors.Entry.Entity.ToString(), validationError.ErrorMessage); raise = new InvalidOperationException(message, raise); } } throw raise; } catch (Exception dbEx) { Exception raise = dbEx; var val = dbEx.InnerException; MessageBox.Show(val.ToString()); //throw raise; } } fillsearch(); splashScreenManager1.CloseWaitForm(); } }
private void simpleButton1_Click(object sender, EventArgs e) { using (var db = new AccountingSystem()) { var debenturedetails = db.debenturedetails.Create(); //Master Object var Debenture = db.debentures.Create(); //Master Object Debenture.DebentureNo = DebentureNo.Text; Debenture.Notes = note.Text; Debenture.remarks = nodes.Text; Debenture.MDate = DateTime.Now; Debenture.UserID = 1; Debenture.Sequence = 1; Debenture.Amount = 1; Debenture.DebentureDate = date.DateTime; if (DetGridView != null && !isEditForm) { for (int b = 0; b < gridView1.RowCount; b++) { Purchase.debenturedetail DetailsEntity = new Purchase.debenturedetail(); var x = int.Parse(gridView1.GetRowCellValue(b, "Amount").ToString()); var y = int.Parse(gridView1.GetRowCellValue(b, "Payed").ToString()); DetailsEntity.Amount = int.Parse(gridView1.GetRowCellValue(b, "Amount").ToString()); DetailsEntity.Payed = int.Parse(gridView1.GetRowCellValue(b, "Payed").ToString()); DetailsEntity.AccountID = int.Parse(gridView1.GetRowCellValue(b, "AccountID").ToString()); DetailsEntity.ValueDate = DateTime.Now; Debenture.debenturedetails.Add(DetailsEntity);//add details in master object } } string Message = ""; if (DebentureNo.Text.Equals("")) { MessageBox.Show("الرجاء ادخال الرقم القيد", "تنبيه", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (note.Text.Equals("")) { MessageBox.Show("الرجاء ادخال البيان", "تنبيه", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (double.Parse(textcrd.Text) == 0 || double.Parse(textdebt.Text) == 0 || double.Parse(textcrd.Text) != double.Parse(textdebt.Text)) { MessageBox.Show("مجموع القيود الدائنة لايساوي المدينة", "تنبيه", MessageBoxButtons.OK, MessageBoxIcon.Error); gridView1.Focus(); return; } else { if (!isEditForm) { db.debentures.Add(Debenture); } else { int i = int.Parse(Id); // MessageBox.Show(i.ToString()); var Debentur = db.debentures.First(x => x.DebentureID.Equals(i)); Debentur.DebentureNo = DebentureNo.Text; Debentur.Notes = note.Text; Debentur.MDate = DateTime.Now; Debentur.remarks = nodes.Text; Debentur.UserID = 1; Debentur.Sequence = 1; Debentur.Amount = 1; Debentur.DebentureDate = date.DateTime; var widgets = db.debenturedetails.Where(x => x.DebentureID.Equals(i)); foreach (debenturedetail widget in widgets) { db.debenturedetails.Remove(widget); } if (DetGridView != null) { for (int b = 0; b < gridView1.RowCount; b++) { Purchase.debenturedetail DetailsEntity = new Purchase.debenturedetail(); var x = int.Parse(gridView1.GetRowCellValue(b, "Amount").ToString()); var y = int.Parse(gridView1.GetRowCellValue(b, "Payed").ToString()); DetailsEntity.Amount = int.Parse(gridView1.GetRowCellValue(b, "Amount").ToString()); DetailsEntity.Payed = int.Parse(gridView1.GetRowCellValue(b, "Payed").ToString()); DetailsEntity.AccountID = int.Parse(gridView1.GetRowCellValue(b, "AccountID").ToString()); DetailsEntity.ValueDate = DateTime.Now; Debentur.debenturedetails.Add(DetailsEntity); //add details in master object } } // Debentur.debenturedetails.Add(DetailsEntity); db.Entry(Debentur).State = System.Data.Entity.EntityState.Modified; } try { db.SaveChanges(); if (isEditForm) { Message = "تم التعديل بنجاح"; } if (!isEditForm) { Message = "تم الحفظ بنجاح"; note.Text = ""; date.DateTime = DateTime.Now; textcrd.Text = 0 + ""; textcrd.Text = 0 + ""; textdebt.Text = 0 + ""; sumcrd.Text = 0 + ""; sumdebt.Text = 0 + ""; nodes.Text = ""; for (int b = 0; b < gridView1.RowCount; b++) { gridView1.SelectRow(b); gridView1.DeleteRow(b); gridView1.SelectAll(); gridView1.DeleteSelectedRows(); } using (var dbs = new AccountingSystem()) { var dc = dbs.debentures.ToList().Max(i => Convert.ToInt32(i.DebentureNo)); DebentureNo.Text = (int.Parse(dc.ToString()) + 1) + ""; } } } catch (System.Data.Entity.Validation.DbEntityValidationException dbEx) { Exception raise = dbEx; foreach (var validationErrors in dbEx.EntityValidationErrors) { foreach (var validationError in validationErrors.ValidationErrors) { string message = string.Format("{0}:{1}", validationErrors.Entry.Entity.ToString(), validationError.ErrorMessage); raise = new InvalidOperationException(message, raise); } } throw raise; } catch (Exception dbEx) { Exception raise = dbEx; var val = dbEx.InnerException; //MessageBox.Show(val.ToString()); MessageBox.Show("هذا الحساب غير موجود", "تنبيه", MessageBoxButtons.OK, MessageBoxIcon.Error); //throw raise; } } if (Message != "") { MessageBox.Show(Message); } } }
private void update_Click(object sender, EventArgs e) { if (SubName.Text.Equals("") || SubName.Text.Equals(" ")) { DevExpress.XtraEditors.XtraMessageBox.Show("الرجاء ادخال اسم العميل"); } else if (SubBalance.Text.Equals("") || SubBalance.Text.Equals(" ")) { DevExpress.XtraEditors.XtraMessageBox.Show("الرجاء الرصيد الابتدائي"); } else if (SupLedger.Text.Equals("") || SupLedger.Text.Equals(" ")) { DevExpress.XtraEditors.XtraMessageBox.Show("الرجاء اختيار حساب الاستاذ"); } else if (SupSupplementingAccount.Text.Equals("") || SupSupplementingAccount.Text.Equals(" ")) { DevExpress.XtraEditors.XtraMessageBox.Show("الرجاء اختيار الحساب المكمل"); } else { splashScreenManager1.ShowWaitForm(); Thread.Sleep(1000); //Wait pleaseWait = new Wait(); //Application.DoEvents(); //pleaseWait.Show(); save.Visible = false; news.Visible = true; update.Visible = true; SupplierSet Sup = new SupplierSet(); //InitializeComponent(); using (var db = new AccountingSystem()) { try { var SupplierSet = db.SupplierSets.First(x => x.SupplierId.Equals(SubCode.Text)); SupplierSet.SupplierId = SubCode.Text; SupplierSet.SupplierName = SubName.Text; SupplierSet.SupplierStartBalance = SubBalance.Text; SupplierSet.SupplierStartBlnsDate = SubDateBalance.Value.ToString(); SupplierSet.SupplierTypeOfBalance = SubTypeBalance.Text; SupplierSet.SupplierStatus = SubStatus.Checked.ToString(); SupplierSet.SupplierBranch = SupBranch.Text; SupplierSet.SupplierBranchCurrency = SupCurrency.Text; SupplierSet.SupplierSupplementingAccount = SupSupplementingAccount.EditValue.ToString(); SupplierSet.SupplierLedger = SupLedger.EditValue.ToString(); SupplierSet.SupplierCompanyName = SubNameCompany.Text; SupplierSet.SupplierResponsible = SubResponsbile.Text; SupplierSet.SupplierArea = SubArea.Text; SupplierSet.SupplierAddress = SubAddress.Text; SupplierSet.SupplierPhone1 = SubPhone1.Text; SupplierSet.SupplierPhone2 = SubPhone2.Text; SupplierSet.SupplierWebsite = SubWebsite.Text; SupplierSet.SupplierEmail = SubEmail.Text; SupplierSet.SupplierBankNoAccount = SubBankNoAccount.Text; SupplierSet.SupplierBankName = SubBankName.Text; SupplierSet.SupplierBankBranach = SubBankBranch.Text; db.Entry(SupplierSet).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); } catch (System.Data.Entity.Validation.DbEntityValidationException dbEx) { Exception raise = dbEx; foreach (var validationErrors in dbEx.EntityValidationErrors) { foreach (var validationError in validationErrors.ValidationErrors) { string message = string.Format("{0}:{1}", validationErrors.Entry.Entity.ToString(), validationError.ErrorMessage); raise = new InvalidOperationException(message, raise); } } throw raise; } catch (Exception dbEx) { Exception raise = dbEx; var val = dbEx.InnerException; MessageBox.Show(val.ToString()); //throw raise; } } fillsearch(); splashScreenManager1.CloseWaitForm(); } //pleaseWait. ; //pleaseWait.Close(TimeSpan.FromSeconds(0)); //MessageBox.Show("تم التحديث بنجاح ", "تنبيه", MessageBoxButtons.OK, MessageBoxIcon.Information); }