Esempio n. 1
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            Button oBtn = sender as Button;

            bool lAdd;
            bool lNoProblems = false;

            if (oBtn != null)
            {
                using (var context = new TTI2Entities())
                {
                    foreach (DataGridViewRow row in dataGridView1.Rows)
                    {
                        if (row.Cells[0].Value != null)
                        {
                            lAdd = true;
                            TLADM_ProductRating pr = new TLADM_ProductRating();

                            if (row.Cells[8].Value != null)
                            {
                                var index = (int)row.Cells[8].Value;
                                pr   = context.TLADM_ProductRating.Find(index);
                                lAdd = false;
                            }

                            pr.PR_Style_FK = (int)row.Cells[0].Value;
                            pr.PR_Quality  = row.Cells[1].Value.ToString();
                            pr.Pr_Wieght   = Convert.ToInt32(row.Cells[2].Value.ToString());
                            pr.Pr_Width    = Convert.ToInt32(row.Cells[3].Value.ToString());
                            pr.Pr_Size_FK  = Convert.ToInt32(row.Cells[4].Value.ToString());
                            pr.PR_Rating   = Convert.ToDecimal(row.Cells[5].Value.ToString());
                            pr.PR_Yield    = Convert.ToDecimal(row.Cells[6].Value.ToString());
                            pr.PR_PCS_Kg   = Convert.ToDecimal(row.Cells[7].Value.ToString());


                            if (lAdd)
                            {
                                context.TLADM_ProductRating.Add(pr);
                            }

                            try
                            {
                                context.SaveChanges();
                            }
                            catch (Exception ex)
                            {
                                MessageBox.Show(ex.Message);
                                lNoProblems = true;
                            }
                        }
                    }
                }
                if (!lNoProblems)
                {
                    dataGridView1.Rows.Clear();
                    MessageBox.Show("All records stored to the database");
                }
            }
        }
Esempio n. 2
0
        private void btnSaveTrims_Click(object sender, EventArgs e)
        {
            Button oBtn             = sender as Button;
            bool   updateSuccessful = true;

            if (formloaded && oBtn != null)
            {
                using (var context = new TTI2Entities())
                {
                    foreach (DataRow DRow in ProductRating.Rows)
                    {
                        TLADM_ProductRating pr = new TLADM_ProductRating();

                        if (!DRow.Field <bool>(10))
                        {
                            pr = context.TLADM_ProductRating.Find(DRow.Field <int>(0));
                        }

                        if (rbBody.Checked)
                        {
                            pr.Pr_BodyorRibbing = 1;
                            pr.Pr_Size_FK       = DRow.Field <int>(11);
                        }
                        else
                        {
                            pr.Pr_BodyorRibbing = 0;
                            pr.Pr_Trim_FK       = DRow.Field <int>(11);
                        }

                        var Cust = (TLADM_CustomerFile)cmbLabels.SelectedItem;
                        if (Cust != null)
                        {
                            pr.Pr_Customer_FK = Cust.Cust_Pk;
                        }

                        var Style = (TLADM_Styles)cmbStyles.SelectedItem;
                        if (Style != null)
                        {
                            pr.Pr_Style_FK = Style.Sty_Id;
                        }

                        pr.Pr_PowerN       = DRow.Field <int>(9);
                        pr.Pr_Discontinued = DRow.Field <bool>(2);
                        pr.Pr_MultiMarker  = DRow.Field <bool>(8);
                        pr.Pr_Ratio        = DRow.Field <decimal>(4);
                        if (!DRow.Field <bool>(8))
                        {
                            pr.Pr_Ratio = 1;
                        }
                        pr.Pr_Marker_Length  = DRow.Field <decimal>(5);
                        pr.Pr_numeric_Rating = DRow.Field <decimal>(6);

                        pr.Pr_Display = DRow.Field <String>(1);
                        if (!String.IsNullOrWhiteSpace(DRow.Field <string>(3)))
                        {
                            pr.Pr_Display += " / " + DRow.Field <string>(3);
                        }

                        if (DRow.Field <bool>(10))
                        {
                            context.TLADM_ProductRating.Add(pr);
                        }
                    }

                    try
                    {
                        context.SaveChanges();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                        updateSuccessful = false;
                    }
                    finally
                    {
                        if (updateSuccessful)
                        {
                            ProductRating.Rows.Clear();
                            MessageBox.Show("Records successfully updated");
                        }
                    }
                }
            }
        }
Esempio n. 3
0
        private void datagridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            Util       core = new Util();
            var        oDgv = sender as DataGridView;
            int        pn   = 0;
            List <int> xx   = null;

            if (oDgv.Focused && oDgv.CurrentCell is DataGridViewButtonCell)
            {
                if (e.ColumnIndex == 1)
                {
                    if (rbBody.Checked)
                    {
                        var Id = 1005;

                        var RowPos = oDgv.CurrentRow.Index;
                        pn = int.Parse(oDgv.CurrentRow.Cells[9].Value.ToString());
                        frmTLADMGardProp aprop = new frmTLADMGardProp(Id, pn, Listsizes);
                        aprop.ShowDialog();
                        var sizes = aprop.TotalPN;
                        if (sizes != 0)
                        {
                            StringBuilder desciption = new StringBuilder();
                            int           a          = Convert.ToInt32(sizes);
                            using (var context = new TTI2Entities())
                            {
                                xx = core.ExtrapNumber(a, context.TLADM_Sizes.Count());
                            }
                            xx.Sort();

                            oDgv.CurrentRow.Cells[8].Value = false;
                            if (xx.Count > 1)
                            {
                                oDgv.CurrentRow.Cells[8].Value = true;
                            }

                            foreach (var rw in xx)
                            {
                                bool First = true;
                                foreach (var dd in Listsizes)
                                {
                                    if (dd.SI_PowerN == rw)
                                    {
                                        if (First)
                                        {
                                            First = !First;
                                            oDgv.CurrentRow.Cells[11].Value = dd.SI_id;
                                        }
                                        if (desciption.Length == 0)
                                        {
                                            desciption.Append(dd.SI_Description);
                                        }
                                        else
                                        {
                                            desciption.Append(", " + dd.SI_Description);
                                        }
                                    }
                                }
                            }

                            oDgv.CurrentRow.Cells[10].Value = false;
                            if ((int)oDgv.CurrentRow.Cells[0].Value == 0)
                            {
                                oDgv.CurrentRow.Cells[10].Value = true;
                            }

                            oDgv.CurrentRow.Cells[1].Value = desciption;
                            oDgv.CurrentRow.Cells[7].Value = "Ratio";
                            oDgv.CurrentRow.Cells[9].Value = sizes;
                        }
                    }
                    else if (rbTrims.Checked)
                    {
                        var StyleSelected = (TLADM_Styles)cmbStyles.SelectedItem;
                        if (StyleSelected != null)
                        {
                            var   Id       = 1007;
                            int[] TrimKeys = new int[2];
                            // First Element is the style
                            //======================================
                            TrimKeys[0] = StyleSelected.Sty_Id;
                            // Second element is the Primary Key of the Trim
                            //===============================================
                            TrimKeys[1] = (int)oDgv.Rows[e.RowIndex].Cells[11].Value;

                            var RowPos = oDgv.CurrentRow.Index;
                            pn = int.Parse(oDgv.CurrentRow.Cells[9].Value.ToString());
                            frmTLADMGardProp aprop = new frmTLADMGardProp(Id, TrimKeys, true);
                            aprop.ShowDialog();
                            var sizes = aprop._TrimKeys;
                            oDgv.CurrentRow.Cells[8].Value = false;

                            oDgv.CurrentRow.Cells[10].Value = false;
                            if ((int)oDgv.CurrentRow.Cells[0].Value == 0)
                            {
                                oDgv.CurrentRow.Cells[10].Value = true;
                            }

                            oDgv.CurrentRow.Cells[11].Value = sizes[1];
                            using (var context = new TTI2Entities())
                            {
                                oDgv.CurrentRow.Cells[1].Value = context.TLADM_Trims.Find(sizes[1]).TR_Description;
                            }

                            oDgv.CurrentRow.Cells[7].Value = "Ratio";
                            oDgv.CurrentRow.Cells[9].Value = 0;
                        }
                    }
                }
                else
                {
                    // Only available to body details
                    //-----------------------------------------------
                    if (!rbBody.Checked)
                    {
                        using (DialogCenteringService centeringService = new DialogCenteringService(this)) // center message box
                        {
                            MessageBox.Show("Please select the body check box prior to selecting this option");
                        }
                        return;
                    }

                    //Only available to multi sized markers
                    //-----------------------------------------------
                    var CurrentRow = oDgv.CurrentRow;

                    if (!(bool)CurrentRow.Cells[8].Value)
                    {
                        using (DialogCenteringService centeringService = new DialogCenteringService(this))  // center message box
                        {
                            MessageBox.Show("This option is only available to multi sized Markers");
                            return;
                        }
                    }
                    else
                    {
                        var PNumber    = (int)CurrentRow.Cells[9].Value;
                        int PrimaryKey = (int)CurrentRow.Cells[0].Value;

                        if (PrimaryKey == 0)
                        {
                            using (var context = new TTI2Entities())
                            {
                                TLADM_ProductRating ProductRating = new TLADM_ProductRating();
                                context.TLADM_ProductRating.Add(ProductRating);

                                try
                                {
                                    context.SaveChanges();
                                    PrimaryKey = ProductRating.Pr_Id;
                                    CurrentRow.Cells[0].Value  = PrimaryKey;
                                    CurrentRow.Cells[10].Value = false;
                                }
                                catch (Exception ex)
                                {
                                    MessageBox.Show(ex.InnerException.Message.ToString());
                                    return;
                                }
                            }
                        }


                        frmTLADMProductRatingDetail prodDetail = new frmTLADMProductRatingDetail(PNumber, PrimaryKey);
                        prodDetail.ShowDialog(this);
                        if (prodDetail.ProductRatio != 0)
                        {
                            oDgv.Rows[e.RowIndex].Cells[4].Value = (decimal)prodDetail.ProductRatio;
                            if (oDgv.Rows[e.RowIndex].Cells[5].Value != null)
                            {
                                var ML = (decimal)oDgv.Rows[e.RowIndex].Cells[5].Value;
                                try
                                {
                                    oDgv.Rows[e.RowIndex].Cells[6].Value = Math.Round(ML / prodDetail.ProductRatio, 4);
                                }
                                catch (Exception ex)
                                {
                                    MessageBox.Show(ex.Message);
                                    return;
                                }
                            }
                        }
                    }
                }
            }
        }