private void btnSave_Click(object sender, EventArgs e) { Button oBtn = (Button)sender; Boolean IsTicked; TLCSV_WhseTransfer WhseTrans = null; frmCSViewRep vRep = null; TLADM_LastNumberUsed LNU = null; if (oBtn != null && FormLoaded) { // Check that the user ie the blonde has checked at least one record //-------------------------------------------------------------------- var SingleRow = (from Rows in dataGridView1.Rows.Cast <DataGridViewRow>() where (bool)Rows.Cells[1].Value == true select Rows).FirstOrDefault(); if (SingleRow == null) { MessageBox.Show("Please select at least one record"); return; } using (var context = new TTI2Entities()) { foreach (DataGridViewRow Row in dataGridView2.Rows) { IsTicked = (bool)Row.Cells[1].Value; var Pk = (int)Row.Cells[0].Value; TLCSV_WhseTransferDetail WhseDetail = context.TLCSV_WhseTransferDetail.Find(Pk); if (!IsTicked && WhseDetail != null) { context.TLCSV_WhseTransferDetail.Remove(WhseDetail); } else if (WhseDetail != null) { if (WhseTrans == null) { WhseTrans = context.TLCSV_WhseTransfer.Find(WhseDetail.TLCSVWHTD_WhseTranfer_FK); } var SOH = context.TLCSV_StockOnHand.Find(WhseDetail.TLCSVWHTD_TLSOH_Fk); if (SOH != null && WhseTrans != null) { if (InterWhseDel && oChkConfirmation.Checked) { SOH.TLSOH_WareHouse_FK = WhseTrans.TLCSVWHT_ToWhse_Fk; SOH.TLSOH_InTransit = false; } else { if (!InterWhseDel) { SOH.TLSOH_WareHouse_FK = WhseTrans.TLCSVWHT_ToWhse_Fk; SOH.TLSOH_InTransit = false; } else { SOH.TLSOH_InTransit = true; } } } if (InterWhseDel) { WhseDetail.TLCSVWHTD_DeliveryNote = true; } else { WhseDetail.TLCSVWHTD_Receipted = true; } } } var Dept = context.TLADM_Departments.Where(x => x.Dep_ShortCode == "CSV").FirstOrDefault(); if (Dept != null) { LNU = context.TLADM_LastNumberUsed.Where(x => x.LUN_Department_FK == Dept.Dep_Id).FirstOrDefault(); if (InterWhseDel) { WhseTrans.TLCSVWHT_DeliveryNo = LNU.col7; LNU.col7 += 1; WhseTrans.TLCSVWHT_DeliveryNote = true; WhseTrans.TLCSVWHT_Date = DateTime.Now; if (oChkConfirmation.Checked) { WhseTrans.TLCSVWHT_ReceiptNo = LNU.col8; LNU.col8 += 1; WhseTrans.TLCSVWHT_Receipted = true; WhseTrans.TLCSVWHT_Receipt_Date = DateTime.Now; } } else { WhseTrans.TLCSVWHT_ReceiptNo = LNU.col8; LNU.col8 += 1; WhseTrans.TLCSVWHT_Receipted = true; WhseTrans.TLCSVWHT_Receipt_Date = DateTime.Now; } } try { context.SaveChanges(); MessageBox.Show("data successfully saved to database"); } catch (Exception ex) { MessageBox.Show(ex.Message.ToString()); } } if (oChkConfirmation.Checked) { InterWhseDel = false; } if (InterWhseDel) { vRep = new frmCSViewRep(19, WhseTrans.TLCSVWHT_Pk); } else { vRep = new frmCSViewRep(20, WhseTrans.TLCSVWHT_Pk); } int h = Screen.PrimaryScreen.WorkingArea.Height; int w = Screen.PrimaryScreen.WorkingArea.Width; vRep.ClientSize = new Size(w, h); vRep.ShowDialog(this); this.Close(); } }
private void btnSubmit_Click(object sender, EventArgs e) { Button oBtn = sender as Button; if (oBtn != null && FormLoaded) { var FromWhse = (TLADM_WhseStore)cmboFromwarehouse.SelectedItem; if (FromWhse == null) { MessageBox.Show("Please select a warehouse from which to transfer"); return; } var ToWhse = (TLADM_WhseStore)cmboTowareHouse.SelectedItem; if (ToWhse == null) { MessageBox.Show("Please select a warehousewhich to transfer too"); return; } if (FromWhse.WhStore_Id == ToWhse.WhStore_Id) { MessageBox.Show("Please select a different warehouse to transfer too"); return; } if (!TransferMode) { TransferMode = !TransferMode; btnSubmit.Text = "Transfer"; QueryParms.FromWhse = FromWhse.WhStore_Id; //This function needs to be modified for Bought in Fabric purposes //=========================================================================== var Existing = repo.FromWareHouse(QueryParms); if (Existing.Count() == 0) { MessageBox.Show("No Records found for selection made", FromWhse.WhStore_Description); return; } using (var context = new TTI2Entities()) { foreach (var Record in Existing) { var index = dataGridView1.Rows.Add(); dataGridView1.Rows[index].Cells[0].Value = Record.TLSOH_Pk; dataGridView1.Rows[index].Cells[1].Value = false; dataGridView1.Rows[index].Cells[2].Value = Record.TLSOH_BoxNumber; dataGridView1.Rows[index].Cells[3].Value = context.TLADM_Styles.Find(Record.TLSOH_Style_FK).Sty_Description; dataGridView1.Rows[index].Cells[4].Value = context.TLADM_Colours.Find(Record.TLSOH_Colour_FK).Col_Display; dataGridView1.Rows[index].Cells[5].Value = context.TLADM_Sizes.Find(Record.TLSOH_Size_FK).SI_Description; dataGridView1.Rows[index].Cells[6].Value = Record.TLSOH_BoxedQty; } } } else { var CountSelected = (from Rows in dataGridView1.Rows.Cast <DataGridViewRow>() where (bool)Rows.Cells[1].Value == true select Rows).Count(); if (CountSelected == 0) { MessageBox.Show("Please tick at least one box to be transferred"); return; } TransferMode = !TransferMode; btnSubmit.Text = "Submit"; using (var context = new TTI2Entities()) { //Need to create a Header Record in the file //======================================================= TLCSV_WhseTransfer WhseTransfer = new TLCSV_WhseTransfer(); var Dept = context.TLADM_Departments.Where(x => x.Dep_ShortCode == "CSV").FirstOrDefault(); if (Dept != null) { var LNU = context.TLADM_LastNumberUsed.Where(x => x.LUN_Department_FK == Dept.Dep_Id).FirstOrDefault(); if (LNU != null) { WhseTransfer.TLCSVWHT_Date = DateTime.Now; WhseTransfer.TLCSVWHT_PickList = true; WhseTransfer.TLCSVWHT_FromWhse_Fk = FromWhse.WhStore_Id; WhseTransfer.TLCSVWHT_ToWhse_Fk = ToWhse.WhStore_Id; WhseTransfer.TLCSVWHT_PickListDate = DateTime.Now; WhseTransfer.TLCSVWHT_PickListNo = LNU.col6; LNU.col6 += 1; context.TLCSV_WhseTransfer.Add(WhseTransfer); try { context.SaveChanges(); } catch (Exception ex) { MessageBox.Show(ex.Message); return; } foreach (DataGridViewRow Row in dataGridView1.Rows) { if ((bool)Row.Cells[1].Value == false) { continue; } TLCSV_WhseTransferDetail WhDetail = new TLCSV_WhseTransferDetail(); WhDetail.TLCSVWHTD_WhseTranfer_FK = WhseTransfer.TLCSVWHT_Pk; WhDetail.TLCSVWHTD_TLSOH_Fk = (int)Row.Cells[0].Value; WhDetail.TLCSVWHTD_PickList = true; context.TLCSV_WhseTransferDetail.Add(WhDetail); } try { context.SaveChanges(); MessageBox.Show("Records successfully updated to database"); FormLoaded = false; frmCutViewRep vRep = new frmCutViewRep(16, WhseTransfer.TLCSVWHT_Pk); int h = Screen.PrimaryScreen.WorkingArea.Height; int w = Screen.PrimaryScreen.WorkingArea.Width; vRep.ClientSize = new Size(w, h); vRep.ShowDialog(this); this.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message); } } } } } } }