private void button1_Click(object sender, EventArgs e) { // update selected.Count = txteditAmount.Text; using (GazOnDevEntities db = new GazOnDevEntities()) { db.Attach(selected); db.ObjectStateManager.ChangeObjectState(selected, EntityState.Modified); db.SaveChanges(); MessageBox.Show("נשמר בהצלחה "); } button1.Enabled = false; }
private void button1_Click(object sender, EventArgs e) { // update selected.lastname = txtEditlastname.Text; selected.firstname = txtEditFirstname.Text; selected.username = txtEditusername.Text; selected.password = txtEditpassword.Text; selected.isadmin = chknewadmin.Checked; using (GazOnDevEntities db = new GazOnDevEntities()) { db.Attach(selected); db.ObjectStateManager.ChangeObjectState(selected, EntityState.Modified); db.SaveChanges(); MessageBox.Show("נשמר בהצלחה "); } button1.Enabled = false; }
private void updateStockAmount(invoiceitem item) { using (GazOnDevEntities db=new GazOnDevEntities()) { int idd=Convert.ToInt32(item.typeid); Accompanying_stocks tepstock = db.Accompanying_stocks.SingleOrDefault(x => x.Id == idd); int amount= Convert.ToInt32(tepstock.Count) - Convert.ToInt32(item.amount); tepstock.Count = amount.ToString(); var entry = db.ObjectStateManager.GetObjectStateEntry(tepstock); if (entry.State == EntityState.Detached) { // Do Something db.Attach(tepstock); } db.ObjectStateManager.ChangeObjectState(tepstock, EntityState.Modified); db.SaveChanges(); } }
private void btnReportPrint_Click(object sender, EventArgs e) { using (GazOnDevEntities db = new GazOnDevEntities()) { if (edit) { db.Attach(_currentinvoice); db.ObjectStateManager.ChangeObjectState(_currentinvoice, EntityState.Modified); foreach (invoiceitem item in bindingSource1.List) { if (null != item.amount) { updateStockAmount(item); } db.Attach(item); db.ObjectStateManager.ChangeObjectState(item, EntityState.Modified); } } else { foreach (invoiceitem item in bindingSource1.List) { //invoiceitem item = new invoiceitem(); ////stocklist. // item.invoiceid = txtinvoiceid.Text; if (null != item.amount) { updateStockAmount(item); } db.AddToinvoiceitems(item); } } //} dbconf.invoicelastid = (Convert.ToInt32(dbconf.invoicelastid) + 1).ToString(); db.Attach(dbconf); db.ObjectStateManager.ChangeObjectState(dbconf, EntityState.Modified); if (edit) { } else { if (_currentinvoice == null) { _currentinvoice = new Invoice(); } _currentinvoice.address = txtAddress.Text; _currentinvoice.C_to = txtTo.Text; _currentinvoice.carnum = txtCarNum.Text; _currentinvoice.date = DatetimePicker.Value; _currentinvoice.invoiceNumber = txtinvoiceid.Text; _currentinvoice.tankNumber = tanktofix.TankNumber; _currentinvoice.tankDesc = txtTankDescription.Text; // increase invoice id number _currentinvoice.transporter = txtCarTransporter.Text; db.AddToInvoices(_currentinvoice); } if (db.SaveChanges() > 0) { // MessageBox.Show("פעולת ההוספה הצליחה"); frmReportTankRecipet tanko = new frmReportTankRecipet(Convert.ToInt32(_currentinvoice.invoiceNumber), "report3"); tanko.ShowDialog(); //btnOpenTank.Enabled = false; } else { MessageBox.Show("פעולת ההוספה נכשלה"); } } // btnOpenTank.Enabled = false; /* frmReportTankRecipet tanko = new frmReportTankRecipet(tanktofix.Id, "report3"); tanko.ShowDialog();*/ }
private void btnOpenTank_Click(object sender, EventArgs e) { using (GazOnDevEntities db = new GazOnDevEntities()) { if (edit) { db.Attach(newrecord); db.ObjectStateManager.ChangeObjectState(newrecord, EntityState.Modified); }else { newrecord = new Tank_Stocks(); newrecord.TankNumber = txtTankNumber.Text; newrecord.type = comboBox1.SelectedIndex.ToString(); newrecord.Datetime = txtdate1.Text; newrecord.GazCompanyName = txtGazCompanyName.Text; newrecord.GazCompanyAddress = txtGazCompanyAddress.Text; newrecord.GazDistributor = txtGazDistributor.Text; if (!string.IsNullOrEmpty(txtYear_of_manufacture.Text)) { newrecord.Year_of_manufacture = Convert.ToInt32(txtYear_of_manufacture.Text); } newrecord.Date_of_Fix = Date_Of_Fix.Text; newrecord.manufacture_name = txtmanufacture_name.Text; if (!string.IsNullOrEmpty(txt_Tank_Size.Text)) { newrecord.Tank_Size = txt_Tank_Size.Text; } if (!string.IsNullOrEmpty(txtLabel_Number.Text)) { newrecord.Label_Number =Convert.ToInt32(txtLabel_Number.Text); } newrecord.Address_Tank_From = txt_tank_fromAddress.Text; if (!string.IsNullOrEmpty(txtNumberOfZoklokPort.Text)) { newrecord.NumberOfZoklokPort = Convert.ToInt32(txtNumberOfZoklokPort.Text); } newrecord.tankStatus = combotankStatus.SelectedIndex.ToString(); newrecord.TankWithBase_baton = checkBox1.Checked ? true : false; // means that enabled at the stock newrecord.TankSystemStatus = "1"; db.AddToTank_Stocks(newrecord); dbconf.tanknumber = (Convert.ToInt32(dbconf.tanknumber) + 1).ToString(); db.Attach(dbconf); db.ObjectStateManager.ChangeObjectState(dbconf, EntityState.Modified); } if (db.SaveChanges() > 0) { MessageBox.Show("פעולת ההוספה הצליחה"); } else { } } }
private void button1_Click(object sender, EventArgs e) { // update int newamount = Convert.ToInt32(txteditAmount.Text) + Convert.ToInt32(txteditAmountCurrent.Text); selected.Count = newamount.ToString(); using (GazOnDevEntities db = new GazOnDevEntities()) { db.Attach(selected); db.ObjectStateManager.ChangeObjectState(selected, EntityState.Modified); db.SaveChanges(); MessageBox.Show("נשמר בהצלחה "); txteditAmount.Text = ""; //comboBox1.SelectedIndex = comboBox1.Items.IndexOf(selected); comboBox1.SelectedIndex = comboBox1.FindStringExact(selected.Title); } button1.Enabled = false; }
private void btnOpenTank_Click(object sender, EventArgs e) { using (GazOnDevEntities db = new GazOnDevEntities()) { if (string.IsNullOrEmpty(txtTankNumber.Text)) { MessageBox.Show("מספר צובר ריק נא להכניס מספר צובר תקין"); txtTankNumber.Text = ""; txtTankNumber.Focus(); return; } if(null !=newrecord) { if (string.IsNullOrEmpty(newrecord.TankNumber)) { MessageBox.Show("מספר צובר ריק נא להכניס מספר צובר תקין"); txtTankNumber.Text = ""; txtTankNumber.Focus(); return; } } if (null == newrecord) { edit = false; } if (edit) { // dbconf.tanknumber = (Convert.ToInt32(dbconf.tanknumber) + 1).ToString(); dbconf.tankfixformnum = (Convert.ToInt32(dbconf.tankfixformnum) + 1).ToString(); db.Attach(dbconf); db.ObjectStateManager.ChangeObjectState(dbconf, EntityState.Modified); db.Attach(newrecord); db.ObjectStateManager.ChangeObjectState(newrecord, EntityState.Modified); } else { newrecord = new Tank_Stocks(); } newrecord.TankNumber = txtTankNumber.Text; newrecord.TankFixNumber = txtfixnumber.Text; newrecord.type = comboBox1.SelectedIndex.ToString(); newrecord.Datetime = txtdate1.Text; newrecord.GazCompanyName = txtGazCompanyName.Text; newrecord.GazCompanyAddress = txtGazCompanyAddress.Text; newrecord.GazDistributor = txtGazDistributor.Text; if (!string.IsNullOrEmpty(txtYear_of_manufacture.Text)) { newrecord.Year_of_manufacture = Convert.ToInt32(txtYear_of_manufacture.Text); } newrecord.Date_of_Fix = Date_Of_Fix.Text; newrecord.manufacture_name = txtmanufacture_name.Text; if (!string.IsNullOrEmpty(txt_Tank_Size.Text)) { newrecord.Tank_Size =txt_Tank_Size.Text; } if (!string.IsNullOrEmpty(txtLabel_Number.Text)) { newrecord.Label_Number = Convert.ToInt32(txtLabel_Number.Text); } newrecord.Address_Tank_From = txt_tank_fromAddress.Text; if (!string.IsNullOrEmpty(txtNumberOfZoklokPort.Text)) { newrecord.NumberOfZoklokPort = Convert.ToInt32(txtNumberOfZoklokPort.Text); } newrecord.tankStatus = combotankStatus.SelectedIndex.ToString(); newrecord.TankWithBase_baton = checkBox1.Checked ? true : false; // means that enabled at the stock //status 2 means that the tank is ready for fix and not in the stock if (newrecord.TankSystemStatus != "3") { newrecord.TankSystemStatus = "2"; } //signed person if (!string.IsNullOrEmpty(txtName_of_recipient.Text)) { newrecord.PersonRecipetsignName = txtName_of_recipient.Text; } if (!string.IsNullOrEmpty(txtSign_of_recipient.Text)) { newrecord.PersonRecipetsignSigniture = txtSign_of_recipient.Text; } // transport Company if (!string.IsNullOrEmpty(txtTransportCompany.Text)) { newrecord.TransportCompanyName = txtTransportCompany.Text; } if (!string.IsNullOrEmpty(txtTransporterName.Text)) { newrecord.TransportCompanyTransportername = txtTransporterName.Text; } if (!string.IsNullOrEmpty(txtCarNumber.Text)) { newrecord.CarNumber = txtCarNumber.Text; } if (!edit) { dbconf.tanknumber = (Convert.ToInt32(dbconf.tanknumber) + 1).ToString(); dbconf.tankfixformnum = (Convert.ToInt32(dbconf.tankfixformnum) + 1).ToString(); db.Attach(dbconf); db.ObjectStateManager.ChangeObjectState(dbconf, EntityState.Modified); db.AddToTank_Stocks(newrecord); } if (db.SaveChanges() > 0) { MessageBox.Show("פעול הצליחה"); //foreach (Control item in this.Controls) //{ // item.Enabled = false; // //if(item.) //} //btnOpenTank.Enabled = false; } } }