private void btnReserve_Click(object sender, EventArgs e) { Button oBtn = sender as Button; bool lsuccess = true; if (oBtn != null) { using (var context = new TTI2Entities()) { foreach (DataGridViewRow dr in dataGridView1.Rows) { if ((int)dr.Cells[5].Value > 0) { TLKNI_YarnOrderPallets yarnStat = new TLKNI_YarnOrderPallets(); var _Key = (int)dr.Cells[0].Value; yarnStat = context.TLKNI_YarnOrderPallets.Find(_Key); if (yarnStat.TLKNIOP_ReservedBy != 0 && yarnStat.TLKNIOP_ReservedBy != _KO) { continue; } yarnStat.TLKNIOP_ConesReserved = (int)dr.Cells[5].Value; yarnStat.TLKNIOP_NettWeightReserved = (decimal)dr.Cells[6].Value; yarnStat.TLKNIOP_ReservedBy = _KO; } } try { context.SaveChanges(); } catch (Exception ex) { MessageBox.Show(ex.Message); lsuccess = false; } } if (lsuccess) { MessageBox.Show("data saved to database successfully"); dataGridView1.Rows.Clear(); } } }
private void Check_Changed(object sender, DataGridViewCellEventArgs e) { DataGridView oDgv = sender as DataGridView; if (oDgv.Focused && oDgv.CurrentCell is DataGridViewCheckBoxCell) { if (e.ColumnIndex == 8 && (bool)oDgv.CurrentCell.EditedFormattedValue) { DialogResult res = MessageBox.Show("Please confirm transaction", "Warning", MessageBoxButtons.OKCancel, MessageBoxIcon.Question); if (res == DialogResult.OK) { using (var context = new TTI2Entities()) { TLKNI_YarnOrderPallets yarnStat = new TLKNI_YarnOrderPallets(); var _Key = (int)dataGridView1.Rows[oDgv.CurrentCell.RowIndex].Cells[0].Value; yarnStat = context.TLKNI_YarnOrderPallets.Find(_Key); yarnStat.TLKNIOP_ConesReserved = 0; yarnStat.TLKNIOP_NettWeightReserved = 0.00M; yarnStat.TLKNIOP_ReservedBy = 0; dataGridView1.Rows[oDgv.CurrentCell.RowIndex].Cells[5].Value = 0; dataGridView1.Rows[oDgv.CurrentCell.RowIndex].Cells[6].Value = 0.00M; dataGridView1.Rows[oDgv.CurrentCell.RowIndex].Cells[7].Value = dataGridView1.Rows[oDgv.CurrentCell.RowIndex].Cells[2].Value; dataGridView1.Rows[oDgv.CurrentCell.RowIndex].Cells[8].Value = dataGridView1.Rows[oDgv.CurrentCell.RowIndex].Cells[3].Value; try { context.SaveChanges(); } catch (Exception ex) { MessageBox.Show(ex.Message); } } } } } }
private void btnSave_Click(object sender, EventArgs e) { Button oBtn = sender as Button; TLADM_TranactionType tranType = null; if (oBtn != null && formloaded) { var YO = (TLSPN_YarnOrder)cmboKnitOrder.SelectedItem; if (YO != null) { using (var context = new TTI2Entities()) { var deptDetail = context.TLADM_Departments.Where(x => x.Dep_ShortCode == "SPIN").FirstOrDefault(); if (deptDetail != null) { tranType = context.TLADM_TranactionType.Where(x => x.TrxT_Department_FK == deptDetail.Dep_Id && x.TrxT_Number == 800).FirstOrDefault(); } foreach (DataGridViewRow Row in dataGridView1.Rows) { if ((bool)Row.Cells[1].Value == false) { continue; } TLSPN_YarnTransactions YarnT = new TLSPN_YarnTransactions(); YarnT.YarnTrx_YarnOrder_FK = YO.YarnO_Pk; YarnT.YarnTrx_SequenceNo = Convert.ToInt32(txtDelNo.Text); YarnT.YarnTrx_Date = dateTimePicker1.Value; if (tranType != null) { YarnT.YarnTrx_TranType_FK = tranType.TrxT_Pk; YarnT.YarnTrx_FromDep_FK = tranType.TrxT_FromWhse_FK; YarnT.YarnTrx_ToDep_FK = tranType.TrxT_ToWhse_FK; } var NettWeight = (Decimal)Row.Cells[4].Value; context.TLSPN_YarnTransactions.Add(YarnT); var index = (int)Row.Cells[0].Value; var PalletStore = context.TLSPN_YarnOrderPallets.Find(index); if (PalletStore != null) { PalletStore.YarnOP_NoOfConesSpun -= PalletStore.YarnOP_NoOfCones; PalletStore.YarnOP_Issued = true; PalletStore.YarnOP_DateDispatched = dateTimePicker1.Value; PalletStore.YarnOP_Store_FK = (int)tranType.TrxT_ToWhse_FK; PalletStore.YarnOP_YarnType_FK = YO.Yarno_YarnType_FK; PalletStore.YarnOP_NettWeight = NettWeight; PalletStore.YarnOP_ReservedBy = int.Parse(txtDelNo.Text); TLKNI_YarnOrderPallets KnitYOP = new TLKNI_YarnOrderPallets(); KnitYOP.TLKNIOP_Cones = PalletStore.YarnOP_NoOfCones; KnitYOP.TLKNIOP_PalletNo = PalletStore.YarnOP_PalletNo; KnitYOP.TLKNIOP_NettWeight = NettWeight; KnitYOP.TLKNIOP_YarnOrder_FK = YO.YarnO_Pk; KnitYOP.TLKNIOP_YarnType_FK = YO.Yarno_YarnType_FK; KnitYOP.TLKNIOP_ConesReserved = 0; KnitYOP.TLKNIOP_NettWeightReserved = 0.00M; KnitYOP.TLKNIOP_Grade = PalletStore.YarnOP_Grade; KnitYOP.TLKNIOP_Store_FK = (int)tranType.TrxT_ToWhse_FK; KnitYOP.TLKNIOP_OwnYarn = true; context.TLKNI_YarnOrderPallets.Add(KnitYOP); } } try { context.SaveChanges(); MessageBox.Show("Data saved to database successfully"); frmYarnwithdrawl_Load(this, null); } catch (Exception ex) { MessageBox.Show(ex.Message); } } /* * int TransNum = int.Parse(txtDelNo.Text); * frmKnitViewRep vRep = new frmKnitViewRep(8, TransNum); * int h = Screen.PrimaryScreen.WorkingArea.Height; * int w = Screen.PrimaryScreen.WorkingArea.Width; * vRep.ClientSize = new Size(w, h); * vRep.ShowDialog(this); */ } } }
private void btnSave_Click(object sender, EventArgs e) { TLSPN_YarnOrder YO = null; TLKNI_YarnTransaction YO3rdP = null; Button oBtn = sender as Button; if (oBtn != null && FormLoaded) { var KO = (TLKNI_Order)cmboKnitOrders.SelectedItem; using (var context = new TTI2Entities()) { if (rbOwnYarn.Checked) { YO = (TLSPN_YarnOrder)cmboYarnOrders.SelectedItem; } else { YO3rdP = (TLKNI_YarnTransaction)cmboYarnOrders.SelectedItem; } foreach (DataGridViewRow Row in dataGridView1.Rows) { if ((bool)Row.Cells[1].Value == false) { continue; } bool lSplit = false; TLKNI_YarnOrderPallets yarnStat = new TLKNI_YarnOrderPallets(); var _Key = (int)Row.Cells[0].Value; yarnStat = context.TLKNI_YarnOrderPallets.Find(_Key); if ((decimal)Row.Cells[4].Value > (decimal)Row.Cells[6].Value) { // We now need to start recording as and when a pallet is across orders //--------------------------------------------------------------------- DialogResult res = MessageBox.Show("Please confirm split transaction", "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); if (res == DialogResult.Yes) { TLKNI_YarnOrderPallets YarnSplit = new TLKNI_YarnOrderPallets(); YarnSplit.TLKNIOP_CommisionCust = yarnStat.TLKNIOP_CommisionCust; YarnSplit.TLKNIOP_Cones = yarnStat.TLKNIOP_Cones; YarnSplit.TLKNIOP_DatePacked = yarnStat.TLKNIOP_DatePacked; YarnSplit.TLKNIOP_Grade = yarnStat.TLKNIOP_Grade; YarnSplit.TLKNIOP_GrossWeight = yarnStat.TLKNIOP_GrossWeight; YarnSplit.TLKNIOP_HeaderRecord_FK = yarnStat.TLKNIOP_HeaderRecord_FK; YarnSplit.TLKNIOP_NettWeight = yarnStat.TLKNIOP_NettWeight; YarnSplit.TLKNIOP_SplitPallet = true; YarnSplit.TLKNIOP_ReservedBy = KO.KnitO_Pk; YarnSplit.TLKNIOP_ReservedDate = dtpTransactionDate.Value; YarnSplit.TLKNIOP_OrderConfirmed = yarnStat.TLKNIOP_OrderConfirmed; YarnSplit.TLKNIOP_OwnYarn = yarnStat.TLKNIOP_OwnYarn; YarnSplit.TLKNIOP_PalletNo = yarnStat.TLKNIOP_PalletNo; YarnSplit.TLKNIOP_Store_FK = yarnStat.TLKNIOP_Store_FK; YarnSplit.TLKNIOP_TareWeight = yarnStat.TLKNIOP_TareWeight; YarnSplit.TLKNIOP_YarnOrder_FK = yarnStat.TLKNIOP_YarnOrder_FK; YarnSplit.TLKNIOP_YarnType_FK = yarnStat.TLKNIOP_YarnType_FK; YarnSplit.TLKNIOP_NettWeight = (decimal)Row.Cells[6].Value; YarnSplit.TLKNIOP_ConesReserved = (int)Row.Cells[5].Value; YarnSplit.TLKNIOP_NettWeightReserved = (decimal)Row.Cells[6].Value; YarnSplit.TLKNIOP_Cones = (int)Row.Cells[5].Value; context.TLKNI_YarnOrderPallets.Add(YarnSplit); lSplit = true; } else { return; } } yarnStat.TLKNIOP_ConesReserved += (int)Row.Cells[5].Value; yarnStat.TLKNIOP_NettWeightReserved += (decimal)Row.Cells[6].Value; if (!lSplit) { yarnStat.TLKNIOP_ReservedBy = KO.KnitO_Pk; yarnStat.TLKNIOP_ReservedDate = dtpTransactionDate.Value; } } // Note for the file //----------------------------------- // The Yarn Order Number is either TTL own Yarn or that received // from a Third Party //---------------------------------------------------------------- var KnitOrder = context.TLKNI_Order.Find(KO.KnitO_Pk); if (KnitOrder != null) { KnitOrder.KnitO_YarnAssigned = true; if (rbOwnYarn.Checked) { KnitOrder.KnitO_YarnO_FK = YO.YarnO_Pk; } else { KnitOrder.KnitO_YarnO_FK = YO3rdP.KnitY_Pk; } } try { context.SaveChanges(); MessageBox.Show("Data saved to the database successfully"); } catch (Exception ex) { MessageBox.Show(ex.Message); } } dataGridView1.Rows.Clear(); FormLoaded = false; cmboKnitOrders.SelectedItem = -1; cmboYarnOrders.SelectedItem = -1; FormLoaded = true; btnSave.Enabled = false; } }
private void btnSave_Click(object sender, EventArgs e) { Button oBtn = sender as Button; TLADM_CustomerFile CommissionCust; TLKNI_YarnTransaction yarnT; TLKNI_YarnTransactionDetails yarnTD; //TLKNI_YarnStatus yarnStat; TLADM_TranactionType TranType = null; TLKNI_YarnOrderPallets PalletStore; int LastNumberUsed = 0; if (oBtn != null && formloaded) { var ErrorM = core.returnMessage(MandSelected, false, MandatoryFields); if (!String.IsNullOrEmpty(ErrorM)) { MessageBox.Show(ErrorM); return; } if (dataGridView1.RowCount == 0) { MessageBox.Show("Please enter a least one row in the datagrid"); return; } CommissionCust = (TLADM_CustomerFile)cmbCommissionCustomers.SelectedItem; using (var context = new TTI2Entities()) { //------------------------- // Yarn Header Record //---------------------------------------- yarnT = new TLKNI_YarnTransaction(); yarnT.KnitY_TransactionDate = dtpDateReceived.Value; yarnT.KnitY_Customer_FK = CommissionCust.Cust_Pk; yarnT.KnitY_Notes = rtbComments.Text; yarnT.KnitY_TransactionDoc = txtCustomerDoc.Text; yarnT.KnitY_ThirdParty = false; yarnT.KnitY_RTS = false; var LastNumber = context.TLADM_LastNumberUsed.Find(2); if (LastNumber != null) { LastNumberUsed = LastNumber.col1; yarnT.KnitY_GRNNumber = LastNumberUsed; LastNumber.col1 += 1; } var Dept = context.TLADM_Departments.Where(x => x.Dep_ShortCode.Contains("KNIT")).FirstOrDefault(); if (Dept != null) { TranType = context.TLADM_TranactionType.Where(x => x.TrxT_Department_FK == Dept.Dep_Id && x.TrxT_Number == 100).FirstOrDefault(); } try { context.TLKNI_YarnTransaction.Add(yarnT); context.SaveChanges(); foreach (DataGridViewRow dr in dataGridView1.Rows) { if (dr.Cells[1].Value == null) { continue; } var PalletNo = (int)dr.Cells[0].Value; PalletStore = new TLKNI_YarnOrderPallets(); PalletStore.TLKNIOP_CommisionCust = true; PalletStore.TLKNIOP_Cones = (int)dr.Cells[7].Value; PalletStore.TLKNIOP_DatePacked = dtpDateReceived.Value; PalletStore.TLKNIOP_Grade = string.Empty; PalletStore.TLKNIOP_GrossWeight = (decimal)dr.Cells[5].Value; PalletStore.TLKNIOP_TareWeight = 0.00M; PalletStore.TLKNIOP_NettWeight = (decimal)dr.Cells[6].Value; PalletStore.TLKNIOP_YarnType_FK = (int)dr.Cells[1].Value; PalletStore.TLKNIOP_PalletNo = PalletNo; PalletStore.TLKNIOP_Store_FK = (int)TranType.TrxT_ToWhse_FK; PalletStore.TLKNIOP_NettWeightReserved = 0.00M; PalletStore.TLKNIOP_HeaderRecord_FK = yarnT.KnitY_Pk; PalletStore.TLKNIOP_ConesReserved = 0; context.TLKNI_YarnOrderPallets.Add(PalletStore); context.SaveChanges(); yarnTD = new TLKNI_YarnTransactionDetails(); yarnTD.KnitYD_KnitY_FK = yarnT.KnitY_Pk; yarnTD.KnitYD_YarnType_FK = (int)dr.Cells[1].Value; yarnTD.KnitYD_PalletNo_FK = PalletStore.TLKNIOP_Pk; yarnTD.KnitYD_GrossWeight = (decimal)dr.Cells[5].Value; yarnTD.KnitYD_NettWeight = (decimal)dr.Cells[6].Value; yarnTD.KnitYD_NoOfCones = (int)dr.Cells[7].Value; yarnTD.KnitYD_TransactionDate = dtpDateReceived.Value; yarnTD.KnitYD_RTS = false; yarnTD.KnitYD_TransactionNumber = LastNumberUsed; if (TranType != null) { yarnTD.KnitYD_TransactionType = TranType.TrxT_Pk; } yarnTD.KnitYD_RTS = false; context.TLKNI_YarnTransactionDetails.Add(yarnTD); } context.SaveChanges(); dataGridView1.Rows.Clear(); MessageBox.Show("Records stored successfully to database"); frmKnitViewRep vRep = new frmKnitViewRep(1, yarnT.KnitY_Pk); vRep.ShowDialog(this); } catch (Exception ex) { MessageBox.Show(ex.Message); } } } }
private void btnSave_Click(object sender, EventArgs e) { Button oBtn = sender as Button; TLKNI_YarnTransactionDetails yarnTD; TLADM_TranactionType TranType = null; int LastNumberUsed = 0; bool success = true; if (oBtn != null && formloaded) { var ErrorM = core.returnMessage(MandatoryFieldsSelected, true, MandatoryFields); if (!string.IsNullOrEmpty(ErrorM)) { MessageBox.Show(ErrorM); return; } var YO = (TLKNI_YarnTransaction)cmboYarnOrder.SelectedItem; if (YO != null) { using (var context = new TTI2Entities()) { var LNU = context.TLADM_LastNumberUsed.Find(2); if (LNU != null) { LastNumberUsed = LNU.col3; LNU.col3 += 1; } var Dept = context.TLADM_Departments.Where(x => x.Dep_ShortCode.Contains("KNIT")).FirstOrDefault(); if (Dept != null) { if (_reportNo == 1) { TranType = context.TLADM_TranactionType.Where(x => x.TrxT_Department_FK == Dept.Dep_Id && x.TrxT_Number == 400).FirstOrDefault(); } else { TranType = context.TLADM_TranactionType.Where(x => x.TrxT_Department_FK == Dept.Dep_Id && x.TrxT_Number == 300).FirstOrDefault(); } } foreach (DataGridViewRow dr in dataGridView1.Rows) { if (!(bool)dr.Cells[1].Value) { continue; } yarnTD = new TLKNI_YarnTransactionDetails(); yarnTD.KnitYD_KnitY_FK = YO.KnitY_Pk; var TypeOfYarn = dr.Cells[3].Value; var YarnDetails = context.TLADM_Yarn.Where(x => x.YA_Description.Contains(TypeOfYarn.ToString())).FirstOrDefault(); if (YarnDetails != null) { yarnTD.KnitYD_YarnType_FK = YarnDetails.YA_Id; } yarnTD.KnitYD_PalletNo_FK = (int)dr.Cells[0].Value; yarnTD.KnitYD_GrossWeight = (decimal)dr.Cells[7].Value; yarnTD.KnitYD_NettWeight = (decimal)dr.Cells[8].Value; yarnTD.KnitYD_NoOfCones = (int)dr.Cells[9].Value; yarnTD.KnitYD_WriteOff = true; yarnTD.KnitYD_RTS = true; yarnTD.KnitYD_TransactionDate = dtpDateReceived.Value; yarnTD.KnitYD_TransactionNumber = LastNumberUsed; if (TranType != null) { yarnTD.KnitYD_TransactionType = TranType.TrxT_Pk; } context.TLKNI_YarnTransactionDetails.Add(yarnTD); //-------------------------------------------------------------------- // Now we have to keep the Status file uptodate //-------------------------------------------------------------------------- TLKNI_YarnOrderPallets palletStore = context.TLKNI_YarnOrderPallets.Find(yarnTD.KnitYD_PalletNo_FK); if (palletStore != null) { palletStore.TLKNIOP_Cones -= yarnTD.KnitYD_NoOfCones; palletStore.TLKNIOP_NettWeight -= yarnTD.KnitYD_NettWeight; palletStore.TLKNIOP_GrossWeight -= yarnTD.KnitYD_GrossWeight; palletStore.TLKNIOP_PalletAllocated = true; } } try { context.SaveChanges(); frmKnitViewRep vRep = new frmKnitViewRep(4, LastNumberUsed); int h = Screen.PrimaryScreen.WorkingArea.Height; int w = Screen.PrimaryScreen.WorkingArea.Width; vRep.ClientSize = new Size(w, h); vRep.ShowDialog(this); } catch (Exception ex) { MessageBox.Show(ex.Message); } } if (success) { dataGridView1.Rows.Clear(); MessageBox.Show("Data saved to database successfully"); SetUp(); } } } }
private void btnSave_Click(object sender, EventArgs e) { Button oBtn = sender as Button; int RecCount = 0; int LastNumberUsed = 0; TLADM_Suppliers CommissionCust; TLKNI_YarnTransaction yarnT; TLKNI_YarnTransactionDetails yarnTD; TLADM_TranactionType TranType = null; TLKNI_YarnOrderPallets PalletStore; if (oBtn != null && formloaded) { var ErrorM = core.returnMessage(MandFieldsSelected, false, MandatoryFields); if (!String.IsNullOrEmpty(ErrorM)) { MessageBox.Show(ErrorM); return; } if (dataGridView1.RowCount == 0) { MessageBox.Show("Please enter a least one row in the datagrid"); return; } foreach (DataGridViewRow dr in dataGridView1.Rows) { var tst = fieldEntered.Find(x => x.rownumber == dr.Index); if (tst.fieldComplete == null) { continue; } var cnt = tst.fieldComplete.Where(x => x == false).Count(); if (cnt == MandatoryRows.Length) { continue; } cnt = tst.fieldComplete.Where(x => x == true).Count(); if (cnt != MandatoryRows.Length) { MessageBox.Show("Line " + (1 + dr.Index).ToString() + " Has not been completed correctly"); return; } } CommissionCust = (TLADM_Suppliers)cmbCommissionCustomers.SelectedItem; using (var context = new TTI2Entities()) { yarnT = new TLKNI_YarnTransaction(); yarnT.KnitY_TransactionDate = dtpDateReceived.Value; yarnT.KnitY_Customer_FK = CommissionCust.Sup_Pk; yarnT.KnitY_Notes = rtbComments.Text; yarnT.KnitY_TransactionDoc = txtCustomerDoc.Text; yarnT.KnitY_ThirdParty = true; var LastNumber = context.TLADM_LastNumberUsed.Find(2); if (LastNumber != null) { LastNumberUsed = LastNumber.col2; yarnT.KnitY_GRNNumber = LastNumberUsed; LastNumber.col2 += 1; } var YarnLastNumber = context.TLADM_LastNumberUsed.Find(1); var Dept = context.TLADM_Departments.Where(x => x.Dep_ShortCode.Contains("KNIT")).FirstOrDefault(); if (Dept != null) { TranType = context.TLADM_TranactionType.Where(x => x.TrxT_Department_FK == Dept.Dep_Id && x.TrxT_Number == 200).FirstOrDefault(); } try { context.TLKNI_YarnTransaction.Add(yarnT); context.SaveChanges(); StringBuilder sb = null; int Counter = 0; foreach (DataGridViewRow dr in dataGridView1.Rows) { var tst = fieldEntered.Find(x => x.rownumber == dr.Index); if (tst.fieldComplete == null) { continue; } var cnt = tst.fieldComplete.Where(x => x == false).Count(); if (cnt == MandatoryRows.Count()) { continue; } var PalletNo = (int)dr.Cells[0].Value; PalletStore = new TLKNI_YarnOrderPallets(); PalletStore.TLKNIOP_CommisionCust = false; sb = new StringBuilder(); sb.Append(YarnLastNumber.col6.ToString()); sb.Append(" - "); sb.Append((++Counter).ToString()); PalletStore.TLKNIOP_TLPalletNo = sb.ToString(); PalletStore.TLKNIOP_Cones = (int)dr.Cells[7].Value; PalletStore.TLKNIOP_DatePacked = dtpDateReceived.Value; PalletStore.TLKNIOP_Grade = string.Empty; PalletStore.TLKNIOP_GrossWeight = (decimal)dr.Cells[5].Value; PalletStore.TLKNIOP_TareWeight = 0.00M; PalletStore.TLKNIOP_NettWeight = (decimal)dr.Cells[6].Value; PalletStore.TLKNIOP_YarnType_FK = (int)dr.Cells[1].Value; PalletStore.TLKNIOP_PalletNo = PalletNo; PalletStore.TLKNIOP_Store_FK = (int)TranType.TrxT_ToWhse_FK; PalletStore.TLKNIOP_NettWeightReserved = 0.00M; PalletStore.TLKNIOP_HeaderRecord_FK = yarnT.KnitY_Pk; PalletStore.TLKNIOP_ConesReserved = 0; context.TLKNI_YarnOrderPallets.Add(PalletStore); context.SaveChanges(); yarnTD = new TLKNI_YarnTransactionDetails(); yarnTD.KnitYD_KnitY_FK = yarnT.KnitY_Pk; yarnTD.KnitYD_YarnType_FK = (int)dr.Cells[1].Value; yarnTD.KnitYD_PalletNo_FK = PalletStore.TLKNIOP_Pk; yarnTD.KnitYD_GrossWeight = (decimal)dr.Cells[5].Value; yarnTD.KnitYD_NettWeight = (decimal)dr.Cells[6].Value; yarnTD.KnitYD_NoOfCones = (int)dr.Cells[7].Value; yarnTD.KnitYD_TransactionDate = dtpDateReceived.Value; yarnTD.KnitYD_RTS = false; yarnTD.KnitYD_TransactionNumber = LastNumberUsed; if (TranType != null) { yarnTD.KnitYD_TransactionType = TranType.TrxT_Pk; } yarnTD.KnitYD_RTS = false; context.TLKNI_YarnTransactionDetails.Add(yarnTD); RecCount += 1; } YarnLastNumber = context.TLADM_LastNumberUsed.Find(1); if (YarnLastNumber != null) { YarnLastNumber.col6 += 1; } context.SaveChanges(); formloaded = false; dataGridView1.Rows.Clear(); formloaded = true; MessageBox.Show("Records stored successfully to database"); frmKnitViewRep vRep = new frmKnitViewRep(3, yarnT.KnitY_Pk); int h = Screen.PrimaryScreen.WorkingArea.Height; int w = Screen.PrimaryScreen.WorkingArea.Width; vRep.ClientSize = new Size(w, h); vRep.ShowDialog(this); SetUp(); } catch (Exception ex) { MessageBox.Show(ex.Message); } } } }