Beispiel #1
0
        private void dataGridView2_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            var oDgv = sender as DataGridView;

            if (oDgv.Focused && oDgv.CurrentCell is DataGridViewCheckBoxCell)
            {
                bool isChecked = (bool)oDgv[e.ColumnIndex, e.RowIndex].EditedFormattedValue;
                if (!isChecked)
                {
                    using (var context = new TTI2Entities())
                    {
                        var index = (int)oDgv.CurrentRow.Cells[0].Value;
                        TLCMT_CompletedWork comWork = context.TLCMT_CompletedWork.Find(index);
                        if (comWork != null)
                        {
                            comWork.TLCMTWC_Picked      = false;
                            comWork.TLCMTWC_PickList_FK = null;

                            try
                            {
                                context.SaveChanges();
                            }
                            catch (Exception ex)
                            {
                                MessageBox.Show(ex.Message);
                            }
                        }
                    }

                    var Rindex = oDgv.CurrentRow.Index;
                    dataGridView2.Rows.RemoveAt(Rindex);
                }
            }
        }
        private void button1_Click(object sender, EventArgs e)
        {
            Button oBtn = sender as Button;

            if (oBtn != null && formloaded)
            {
                var selected = (TLCSV_BoxSelected)cmboWareHouse.SelectedItem;
                if (selected == null)
                {
                    MessageBox.Show("Please select a Delivery Note from the drop down box");
                    return;
                }

                var RecCount = dataGridView1.Rows.Cast <DataGridViewRow>().Where(x => (bool)x.Cells[1].Value == true).Count();

                if (RecCount == 0)
                {
                    MessageBox.Show("Please select a least one record to process");
                    return;
                }

                using (var context = new TTI2Entities())
                {
                    TLCSV_Movement move = new TLCSV_Movement();
                    move.TLMV_FromCMT_Fk        = selected.TLCSV_From_FK;
                    move.TLMV_ToWhse_FK         = selected.TLCSV_To_FK;
                    move.TLMV_TransactionNumber = 1;
                    move.TLMV_TransDate         = dtpTransDate.Value;
                    move.TLMV_BoxSelected_FK    = selected.TLCSV_Pk;
                    move.TLMV_NoOfBoxes         = 0;
                    move.TLMV_BoxedQty          = 0;
                    move.TLMV_OriginalNumber    = selected.TLCSV_DNDeails;
                    var moveDetails = context.TLCMT_CompletedWork.Where(x => x.TLCMTWC_DepatchedList_FK == selected.TLCSV_Pk).ToList();
                    if (moveDetails != null)
                    {
                        move.TLMV_NoOfBoxes = moveDetails.Count;
                        move.TLMV_BoxedQty  = moveDetails.Sum(x => x.TLCMTWC_Qty);
                    }

                    context.TLCSV_Movement.Add(move);

                    try
                    {
                        context.SaveChanges();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                        return;
                    }

                    foreach (DataGridViewRow row in dataGridView1.Rows)
                    {
                        bool isChecked = (bool)row.Cells[1].Value;
                        if (isChecked)
                        {
                            TLCSV_StockOnHand OnHand = new TLCSV_StockOnHand();
                            OnHand.TLSOH_WareHouse_FK   = selected.TLCSV_To_FK;
                            OnHand.TLSOH_CMT_FK         = (int)row.Cells[0].Value;
                            OnHand.TLSOH_BoxSelected_FK = selected.TLCSV_Pk;
                            OnHand.TLSOH_Movement_FK    = move.TLMV_Pk;
                            OnHand.TLSOH_DateIntoStock  = dtpTransDate.Value;

                            TLCMT_CompletedWork comWork = context.TLCMT_CompletedWork.Find((int)row.Cells[0].Value);
                            if (comWork != null)
                            {
                                comWork.TLCMTWC_BoxReceiptedWhse = true;

                                var Already = context.TLCSV_StockOnHand.Where(x => x.TLSOH_BoxNumber == comWork.TLCMTWC_BoxNumber).FirstOrDefault();
                                if (Already != null)
                                {
                                    continue;
                                }

                                OnHand.TLSOH_BoxedQty     = comWork.TLCMTWC_Qty;
                                OnHand.TLSOH_Style_FK     = comWork.TLCMTWC_Style_FK;
                                OnHand.TLSOH_Colour_FK    = comWork.TLCMTWC_Colour_FK;
                                OnHand.TLSOH_Size_FK      = comWork.TLCMTWC_Size_FK;
                                OnHand.TLSOH_BoxNumber    = comWork.TLCMTWC_BoxNumber;
                                OnHand.TLSOH_Weight       = comWork.TLCMTWC_Weight;
                                OnHand.TLSOH_PastelNumber = comWork.TLCMTWC_PastelNumber;
                                OnHand.TLSOH_CutSheet_FK  = comWork.TLCMTWC_CutSheet_FK;

                                if (comWork.TLCMTWC_PastelNumber.Length == 0)
                                {
                                    OnHand.TLSOH_PastelNumber  = context.TLADM_Styles.Find(comWork.TLCMTWC_Style_FK).Sty_PastelNo.ToString();
                                    OnHand.TLSOH_PastelNumber += context.TLADM_Colours.Find(comWork.TLCMTWC_Colour_FK).Col_FinishedCode;
                                    OnHand.TLSOH_PastelNumber += "NG";
                                    OnHand.TLSOH_PastelNumber += context.TLADM_Sizes.Find(comWork.TLCMTWC_Size_FK).SI_PastelNo;
                                }

                                OnHand.TLSOH_BoxType = comWork.TLCMTWC_BoxType_FK;
                                OnHand.TLSOH_Grade   = comWork.TLCMTWC_Grade;
                                if (!comWork.TLCMTWC_Grade.Contains("A"))
                                {
                                    var Assoc = context.TLADM_WareHouseAssociation.Where(X => X.TLWA_PrimaryWareHouse == selected.TLCSV_To_FK).FirstOrDefault();
                                    if (Assoc != null)
                                    {
                                        OnHand.TLSOH_WareHouse_FK = (int)Assoc.TLWA_SecondaryWareHouse;
                                    }
                                }
                                else
                                {
                                    OnHand.TLSOH_Is_A = true;
                                }
                            }
                            context.TLCSV_StockOnHand.Add(OnHand);
                        }
                    }

                    var Existing = context.TLCSV_BoxSelected.Where(x => x.TLCSV_DNTransNumber == selected.TLCSV_DNTransNumber).ToList();
                    foreach (var row in Existing)
                    {
                        TLCSV_BoxSelected Box = new TLCSV_BoxSelected();
                        Box = context.TLCSV_BoxSelected.Find(row.TLCSV_Pk);
                        if (Box != null)
                        {
                            Box.TLCSV_Receipted     = true;
                            Box.TLCSV_DateReceipted = dtpTransDate.Value;
                        }
                    }

                    try
                    {
                        context.SaveChanges();
                        MessageBox.Show("Data saved successfully to database");
                        dataGridView1.Rows.Clear();

                        cmboWareHouse.DataSource    = null;
                        cmboWareHouse.DataSource    = context.TLCSV_BoxSelected.Where(x => !x.TLCSV_Receipted).GroupBy(g => new { g.TLCSV_DNTransNumber }).Select(s => s.FirstOrDefault()).ToList();
                        cmboWareHouse.ValueMember   = "TLCSV_Pk";
                        cmboWareHouse.DisplayMember = "TLCSV_DNDeails";
                        cmboWareHouse.SelectedValue = -1;

                        frmCSViewRep vRep = new frmCSViewRep(3, selected.TLCSV_Pk);
                        int          h    = Screen.PrimaryScreen.WorkingArea.Height;
                        int          w    = Screen.PrimaryScreen.WorkingArea.Width;
                        vRep.ClientSize = new Size(w, h);
                        vRep.ShowDialog(this);
                    }
                    catch (Exception ex)
                    {
                        var exceptionMessages = new StringBuilder();
                        do
                        {
                            exceptionMessages.Append(ex.Message);
                            ex = ex.InnerException;
                        }while (ex != null);

                        MessageBox.Show(exceptionMessages.ToString());
                    }
                }
            }
        }
Beispiel #3
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            Button oBtn = sender as Button;

            if (oBtn != null && formloaded)
            {
                int TotBGradeFaults = dataGridView3.Rows.Cast <DataGridViewRow>()
                                      .Sum(x => Convert.ToInt32(x.Cells[2].Value.ToString()));

                if (TotBGradeFaults != Convert.ToInt32(txtTotBGrade.Text))
                {
                    MessageBox.Show("Please enter the total number of B Grade faults");
                    return;
                }

                var BoxType = (TLADM_BoxTypes)cmboBoxType.SelectedItem;
                if (BoxType == null)
                {
                    MessageBox.Show("Please select a box type from the facilities");
                    return;
                }
                var PanelIssue = (int)cmboCMTIssue.SelectedValue;
                if (PanelIssue == 0)
                {
                    MessageBox.Show("Please select a panel issue document");
                    return;
                }

                int LineIssue = (int)cmboCMTLine.SelectedValue;
                if (LineIssue == 0)
                {
                    MessageBox.Show("Please select a production line");
                    return;
                }



                using (var context = new TTI2Entities())
                {
                    var LI = context.TLCMT_LineIssue.Find(LineIssue);
                    if (LI != null)
                    {
                        LI.TLCMTLI_WorkCompletedDate = dtpTransDate.Value;
                    }

                    foreach (DataGridViewRow row in dataGridView2.Rows)
                    {
                        TLCMT_CompletedWork comWork = new TLCMT_CompletedWork();

                        if (row.ErrorText.Length != 0)
                        {
                            continue;
                        }

                        if (row.Cells[0].Value == null)
                        {
                            continue;
                        }

                        if ((int)row.Cells[4].Value == 0)
                        {
                            continue;
                        }

                        comWork.TLCMTWC_LineIssue_FK = LineIssue;
                        if (LI != null)
                        {
                            comWork.TLCMTWC_CMTFacility_FK = LI.TLCMTLI_CmtFacility_FK;
                            LI.TLCMTLI_WorkCompleted       = true;
                        }

                        comWork.TLCMTWC_PanelIssue_FK   = PanelIssue;
                        comWork.TLCMTWC_TransactionDate = dtpTransDate.Value;
                        comWork.TLCMTWC_BoxNumber       = row.Cells[0].Value.ToString();
                        comWork.TLCMTWC_PastelNumber    = row.Cells[3].Value.ToString();

                        var Pk = (int)row.Cells[6].Value;
                        if (Pk != 0)
                        {
                            var CSRD = context.TLCUT_CutSheetReceiptDetail.Find(Pk);
                            if (CSRD != null)
                            {
                                if (CSRD.TLCUTSHRD_BoxType_FK != null)
                                {
                                    comWork.TLCMTWC_BoxType_FK = (int)CSRD.TLCUTSHRD_BoxType_FK;
                                }
                            }
                        }
                        else
                        {
                            if (CS != null)
                            {
                                var CSRD = context.TLCUT_CutSheetReceiptDetail.Where(x => x.TLCUTSHRD_CutSheet_FK == CS.TLCutSH_Pk).FirstOrDefault();
                                if (CSRD != null)
                                {
                                    if (CSRD.TLCUTSHRD_BoxType_FK != null)
                                    {
                                        comWork.TLCMTWC_BoxType_FK = (int)CSRD.TLCUTSHRD_BoxType_FK;
                                    }
                                }
                            }
                        }

                        comWork.TLCMTWC_Grade = row.Cells[1].Value.ToString();
                        comWork.TLCMTWC_Qty   = (int)row.Cells[4].Value;

                        if (row.Cells[2].Value == null)
                        {
                            MessageBox.Show("Please select a size from the combo box in the grid");
                            return;
                        }

                        comWork.TLCMTWC_Size_FK = (int)row.Cells[2].Value;


                        if (row.Cells[5].Value != null)
                        {
                            comWork.TLCMTWC_Weight = (decimal)row.Cells[5].Value;
                        }
                        else
                        {
                            comWork.TLCMTWC_Weight = 0;
                        }

                        if (CS != null)
                        {
                            comWork.TLCMTWC_CutSheet_FK = CS.TLCutSH_Pk;
                            comWork.TLCMTWC_Colour_FK   = CS.TLCutSH_Colour_FK;
                            comWork.TLCMTWC_Style_FK    = CS.TLCutSH_Styles_FK;
                        }

                        //BoxType Stored
                        comWork.TLCMTWC_BoxType_FK = BoxType.TLADMBT_Pk;

                        context.TLCMT_CompletedWork.Add(comWork);
                    }

                    foreach (DataGridViewRow rw in dataGridView3.Rows)
                    {
                        if ((int)rw.Cells[2].Value == 0)
                        {
                            continue;
                        }

                        TLCMT_ProductionFaults pf = new TLCMT_ProductionFaults();

                        pf.TLCMTPF_Fault_FK      = (int)rw.Cells[0].Value;
                        pf.TLCMTPF_PanelIssue_FK = PanelIssue;
                        if (LI != null)
                        {
                            pf.TLCMTPF_LineIssue_FK = LI.TLCMTLI_LineNo_FK;
                        }
                        pf.TLCMTPF_Qty = (int)rw.Cells[2].Value;

                        context.TLCMT_ProductionFaults.Add(pf);
                    }

                    //===============================================================
                    // Need to save statistics
                    //==================================================================
                    TLCMT_Statistics stats = new TLCMT_Statistics();
                    bool             Add   = true;

                    stats = context.TLCMT_Statistics.Where(x => x.CMTS_PanelIssue_FK == PanelIssue).FirstOrDefault();
                    if (stats == null)
                    {
                        stats = new TLCMT_Statistics();
                    }
                    else
                    {
                        Add = !Add;
                    }

                    stats.CMTS_PanelIssue_FK    = PanelIssue;
                    stats.CMTS_Total_A_Grades   = Convert.ToInt32(txtTotAGrade.Text);
                    stats.CMTS_Total_B_Grades   = Convert.ToInt32(txtTotBGrade.Text);
                    stats.CMTS_TotalPanelIssued = Convert.ToInt32(txtTPIssued.Text);
                    stats.CMTS_Panels           = Convert.ToInt32(txtTPPanels.Text);

                    stats.CMTS_Transdate        = dtpTransDate.Value;
                    stats.CMTS_Total_Difference = Convert.ToInt32(txtDifference.Text);

                    if (Add)
                    {
                        context.TLCMT_Statistics.Add(stats);
                    }

                    //=====================================================================

                    try
                    {
                        context.SaveChanges();


                        MessageBox.Show("Records successfully saved to database");


                        formloaded = false;
                        cmboCMTIssue.SelectedValue = -1;
                        cmboCMTLine.SelectedValue  = -1;
                        formloaded = true;

                        frmCompleted_Load(this, null);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message.ToString());
                    }
                }
            }
        }
Beispiel #4
0
        private void btnSubmit_Click(object sender, EventArgs e)
        {
            Button            oBtn = sender as Button;
            Repository        repo = new Repository();
            TLCSV_BoxSelected boxSelected;

            if (oBtn != null && Submit)
            {
                var Depts = (TLADM_Departments)cmboFrom.SelectedItem;
                if (Depts == null)
                {
                    MessageBox.Show("Please select a CMT from from the drop down box");
                    return;
                }

                QueryParms.Depts.Add(repo.LoadDepart(Depts.Dep_Id));

                var BoxesAvailable = repo.Query(QueryParms);

                if (BoxesAvailable.Count() == 0)
                {
                    MessageBox.Show("There are no Boxes available");
                    return;
                }

                DGVResults.Rows.Clear();

                using (var context = new TTI2Entities())
                {
                    foreach (var Box in BoxesAvailable)
                    {
                        var index = DGVResults.Rows.Add();
                        DGVResults.Rows[index].Cells[0].Value = Box.TLCMTWC_Pk;
                        DGVResults.Rows[index].Cells[1].Value = false;
                        DGVResults.Rows[index].Cells[2].Value = Box.TLCMTWC_BoxNumber;
                        DGVResults.Rows[index].Cells[3].Value = Box.TLCMTWC_Qty;
                        DGVResults.Rows[index].Cells[4].Value = Box.TLCMTWC_Weight;
                        var Styles = context.TLADM_Styles.Find(Box.TLCMTWC_Style_FK);
                        if (Styles != null)
                        {
                            DGVResults.Rows[index].Cells[5].Value = context.TLADM_CustomerFile.Find(Styles.Sty_Label_FK).Cust_Description;
                            DGVResults.Rows[index].Cells[6].Value = Styles.Sty_Description;
                        }
                        DGVResults.Rows[index].Cells[7].Value = context.TLADM_Colours.Find(Box.TLCMTWC_Colour_FK).Col_Display;
                        DGVResults.Rows[index].Cells[8].Value = context.TLADM_Sizes.Find(Box.TLCMTWC_Size_FK).SI_Description;
                    }
                }


                DGVResults.Visible = true;

                label4.Visible = false;
                label5.Visible = false;
                label6.Visible = false;

                Submit         = !Submit;
                btnSubmit.Text = "Process";
                groupBox1.Text = "Results";
            }
            else
            {
                //-------------------------------------------------------------------
                // 1st Has a to destination been selected
                // If No return
                //------------------------------------------------------------------------
                var Dept = (TLADM_Departments)cmboFrom.SelectedItem;
                if (Dept == null)
                {
                    MessageBox.Show("Error encountered" + Environment.NewLine + "Process aborted");
                    return;
                }

                var Whse = (TLADM_WhseStore)cmboTo.SelectedItem;
                if (Whse == null)
                {
                    MessageBox.Show("Please select a TO Destination from the drop down box provided");
                    return;
                }

                var RecCount = DGVResults.Rows.Cast <DataGridViewRow>().Where(x => (bool)x.Cells[1].Value == true).Count();

                if (RecCount == 0)
                {
                    MessageBox.Show("Please select a least one record to process");
                    return;
                }

                using (var context = new TTI2Entities())
                {
                    //------------------------------------------------
                    // 1st Things first create a header record
                    //-------------------------------------------------------------------------

                    var LNU = context.TLADM_LastNumberUsed.Where(x => x.LUN_Department_FK == Dept.Dep_Id).FirstOrDefault();

                    boxSelected = new TLCSV_BoxSelected();

                    boxSelected.TLCSV_TransDate = dateTimePicker1.Value;
                    boxSelected.TLCSV_From_FK   = Dept.Dep_Id;
                    boxSelected.TLCSV_To_FK     = Whse.WhStore_Id;
                    if (LNU != null)
                    {
                        boxSelected.TLCSV_TransNumber = LNU.col6;
                        LNU.col6 += 1;
                    }

                    boxSelected.TLCSV_PLDetails = "CP" + boxSelected.TLCSV_TransNumber.ToString().PadLeft(5, '0');
                    try
                    {
                        context.TLCSV_BoxSelected.Add(boxSelected);
                        context.SaveChanges();
                    }
                    catch (Exception ex)
                    {
                        var exceptionMessages = new StringBuilder();
                        do
                        {
                            exceptionMessages.Append(ex.Message);
                            ex = ex.InnerException;
                        }while (ex != null);
                        MessageBox.Show(exceptionMessages.ToString());
                        return;
                    }

                    foreach (DataGridViewRow row in DGVResults.Rows)
                    {
                        if ((bool)row.Cells[1].Value == false)
                        {
                            continue;
                        }

                        TLCMT_CompletedWork comWork = new TLCMT_CompletedWork();
                        var index = (int)row.Cells[0].Value;
                        comWork = context.TLCMT_CompletedWork.Find(index);
                        if (comWork != null)
                        {
                            comWork.TLCMTWC_PickList_FK = boxSelected.TLCSV_Pk;
                            comWork.TLCMTWC_Picked      = true;
                            comWork.TLCMTWC_ToWhse_FK   = Whse.WhStore_Id;
                        }
                    }

                    try
                    {
                        context.SaveChanges();
                        using (DialogCenteringService centeringService = new DialogCenteringService(this)) // center message box
                        {
                            MessageBox.Show("Data successfully saved to the database");
                        }
                    }
                    catch (Exception ex)
                    {
                        var exceptionMessages = new StringBuilder();
                        do
                        {
                            exceptionMessages.Append(ex.Message);
                            ex = ex.InnerException;
                        }while (ex != null);
                        MessageBox.Show(exceptionMessages.ToString());
                        return;
                    }
                    //----------------------------------------------------------------------
                    frmCSViewRep vRep = new frmCSViewRep(1, boxSelected.TLCSV_Pk);
                    int          h    = Screen.PrimaryScreen.WorkingArea.Height;
                    int          w    = Screen.PrimaryScreen.WorkingArea.Width;
                    vRep.ClientSize = new Size(w, h);
                    vRep.ShowDialog(this);
                    //-----------------------------------------------------------------------

                    try
                    {
                        DialogResult res = MessageBox.Show(" Do you wish to send a confirmation email ", "Confirmation email", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                        if (res == DialogResult.Yes)
                        {
                            //-------------------------------------------------------------------
                            // We need to build up a data table of
                            // boxes( stock ) transfered
                            //-------------------------------------------------------------------
                            DataTable dt = new DataTable();
                            dt.Columns.Add("BoxNumber", typeof(String));
                            dt.Columns["BoxNumber"].DefaultValue = string.Empty;
                            dt.Columns.Add("Style", typeof(String));
                            dt.Columns["Style"].DefaultValue = string.Empty;
                            dt.Columns.Add("Colour", typeof(String));
                            dt.Columns["Colour"].DefaultValue = string.Empty;
                            dt.Columns.Add("Size", typeof(String));
                            dt.Columns["Size"].DefaultValue = string.Empty;
                            dt.Columns.Add("Grade", typeof(String));
                            dt.Columns["Grade"].DefaultValue = string.Empty;
                            dt.Columns.Add("Qty", typeof(int));
                            dt.Columns["Qty"].DefaultValue = 0;
                            dt.Columns.Add("Weight", typeof(decimal));
                            dt.Columns["Weight"].DefaultValue = 0.0M;

                            var BoxesTransfered = context.TLCMT_CompletedWork.Where(x => x.TLCMTWC_PickList_FK == boxSelected.TLCSV_Pk).ToList();
                            foreach (var Box in BoxesTransfered)
                            {
                                DataRow dr = dt.NewRow();
                                dr[0] = Box.TLCMTWC_BoxNumber;
                                dr[1] = context.TLADM_Styles.Find(Box.TLCMTWC_Style_FK).Sty_Description;
                                dr[2] = context.TLADM_Colours.Find(Box.TLCMTWC_Colour_FK).Col_Description;
                                dr[3] = context.TLADM_Sizes.Find(Box.TLCMTWC_Size_FK).SI_Description;
                                dr[4] = Box.TLCMTWC_Grade;
                                dr[5] = Box.TLCMTWC_Qty;
                                dr[6] = Box.TLCMTWC_Weight;
                                dt.Rows.Add(dr);
                            }

                            StringBuilder       EMailAdd     = new StringBuilder();
                            frmSeleEMailAddress EMailAddress = new frmSeleEMailAddress();
                            EMailAddress.ShowDialog(this);
                            var Email = EMailAddress.EMailSelected;
                            if (Email.ToString().Length > 0)
                            {
                                try
                                {
                                    string ToWhse = context.TLADM_WhseStore.Find(boxSelected.TLCSV_To_FK).WhStore_Description;

                                    core.SendEmailtoContacts(Email.ToString(), dt, 2, dateTimePicker1.Value, ToWhse, boxSelected.TLCSV_PLDetails);
                                    MessageBox.Show("Email successfully despatched");
                                }
                                catch (Exception ex)
                                {
                                    var exceptionMessages = new StringBuilder();
                                    do
                                    {
                                        exceptionMessages.Append(ex.Message);
                                        ex = ex.InnerException;
                                    }while (ex != null);
                                    MessageBox.Show(exceptionMessages.ToString());
                                }
                            }
                            else
                            {
                                MessageBox.Show("No Email address's selected or Email address's do not exist");
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        var exceptionMessages = new StringBuilder();
                        do
                        {
                            exceptionMessages.Append(ex.Message);
                            ex = ex.InnerException;
                        }while (ex != null);
                        MessageBox.Show(exceptionMessages.ToString());
                    }
                }



                DGVResults.Visible = false;

                groupBox1.Text = "Selection";

                label4.Visible = true;
                label5.Visible = true;
                label6.Visible = true;

                Submit         = !Submit;
                btnSubmit.Text = "Submit";

                cmboStyles.Items.Clear();
                cmboColours.Items.Clear();
                cmboSizes.Items.Clear();

                frmWareHouseTransfers_Load(this, null);
            }
        }
Beispiel #5
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            Button oBtn        = sender as Button;
            int    TransNumber = 0;
            int    MasterPk    = 0;

            if (oBtn != null && formloaded)
            {
                using (var context = new TTI2Entities())
                {
                    var Dept = (TLADM_Departments)cmboDepartment.SelectedItem;
                    if (Dept == null)
                    {
                        MessageBox.Show("Please select a from destination");
                        return;
                    }

                    var RecCount = dataGridView2.Rows.Cast <DataGridViewRow>().Where(x => (bool)x.Cells[1].Value == true).Count();

                    if (RecCount == 0)
                    {
                        MessageBox.Show("Please select a least one record to process");
                        return;
                    }


                    var LNU = context.TLADM_LastNumberUsed.Where(x => x.LUN_Department_FK == Dept.Dep_Id).FirstOrDefault();
                    if (LNU != null)
                    {
                        TransNumber = LNU.col8;
                    }

                    var Whse = (TLADM_WhseStore)cmboWareHouse.SelectedItem;
                    if (Whse != null)
                    {
                    }

                    bool First = true;
                    foreach (DataGridViewRow row in dataGridView1.Rows)
                    {
                        bool isChecked = (bool)row.Cells[1].Value;
                        if (!isChecked)
                        {
                            continue;
                        }

                        if (First)
                        {
                            MasterPk = (int)row.Cells[0].Value;
                            First    = !First;
                        }

                        if (!chkSelectHistory.Checked)
                        {
                            TLCSV_BoxSelected Box = new TLCSV_BoxSelected();

                            var index = (int)row.Cells[0].Value;
                            Box = context.TLCSV_BoxSelected.Find(index);
                            if (Box != null)
                            {
                                Box.TLCSV_Despatched     = true;
                                Box.TLCSV_DespatchedDate = DateTime.Now;
                                Box.TLCSV_DNDeails       = "CDN" + TransNumber.ToString().PadLeft(5, '0');
                                Box.TLCSV_DNTransNumber  = TransNumber;
                            }
                        }
                    }

                    foreach (DataGridViewRow rows in dataGridView2.Rows)
                    {
                        bool isChecked = (bool)rows.Cells[1].Value;

                        if (!isChecked)
                        {
                            continue;
                        }

                        if (!chkSelectHistory.Checked)
                        {
                            var index = (int)rows.Cells[0].Value;
                            TLCMT_CompletedWork comWork = context.TLCMT_CompletedWork.Find(index);
                            if (comWork != null)
                            {
                                if (!isChecked)
                                {
                                    comWork.TLCMTWC_Picked      = false;
                                    comWork.TLCMTWC_PickList_FK = null;
                                }
                                else
                                {
                                    comWork.TLCMTWC_Despatched       = true;
                                    comWork.TLCMTWC_DepatchedList_FK = MasterPk;
                                }
                            }
                        }
                    }


                    try
                    {
                        if (!chkSelectHistory.Checked)
                        {
                            LNU.col8 += 1;
                            context.SaveChanges();
                            foreach (DataGridViewRow row in dataGridView1.Rows)
                            {
                                var index = (int)row.Cells[0].Value;
                                var cnt   = context.TLCMT_CompletedWork.Where(x => x.TLCMTWC_PickList_FK == index && x.TLCMTWC_Picked).Count();
                                if (cnt == 0)
                                {
                                    TLCSV_BoxSelected Box = new TLCSV_BoxSelected();
                                    Box = context.TLCSV_BoxSelected.Find(index);
                                    if (Box != null)
                                    {
                                        context.TLCSV_BoxSelected.Remove(Box);
                                    }
                                }
                            }

                            context.SaveChanges();
                            MessageBox.Show("Data saved successfully to database");
                        }
                        dataGridView1.Rows.Clear();
                        dataGridView2.Rows.Clear();


                        frmCSViewRep vRep = new frmCSViewRep(2, MasterPk);
                        int          h    = Screen.PrimaryScreen.WorkingArea.Height;
                        int          w    = Screen.PrimaryScreen.WorkingArea.Width;
                        vRep.ClientSize = new Size(w, h);
                        vRep.ShowDialog(this);

                        if (chkSelectHistory.Checked)
                        {
                            chkSelectHistory.Checked = false;
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                }
            }
        }