Ejemplo n.º 1
0
        private void cmb_SelectedIndexChanged(object sender, EventArgs e)
        {
            int      nbr;
            ComboBox oCmb = sender as ComboBox;

            if (oCmb != null && formloaded)
            {
                var result = (from u in MandatoryFields
                              where u[0] == oCmb.Name
                              select u).FirstOrDefault();

                if (result != null)
                {
                    nbr = Convert.ToInt32(result[2].ToString());
                    MandSelected[nbr] = true;
                }

                if (oCmb.TabIndex == 0)
                {
                    AddRecord = false;

                    TLADM_NonStockItems nsi = new TLADM_NonStockItems();
                    var test = (TLADM_NonStockItems)oCmb.SelectedItem;
                    using (var context = new TTI2Entities())
                    {
                        nsi = context.TLADM_NonStockItems.Find(test.NSI_Pk);
                        if (nsi != null)
                        {
                            txtCode.Text                = nsi.NSI_Code;
                            txtDescription.Text         = nsi.NSI_Description;
                            txtBoxUnitCost.Text         = Math.Round(nsi.NSI_UnitCost, 2).ToString();
                            cmbUOM.SelectedValue        = nsi.NSI_UOM_FK;
                            cmbStockTypes.SelectedValue = nsi.NSI_StockType_FK;
                            cmbCategories.SelectedValue = nsi.NSI_Category_FK;
                            btnDept.Text                = nsi.NSI_Department_PWN.ToString();
                            txtBoxUnitCost.Visible      = true;

                            if (nsi.NSI_ShowUnitCost)
                            {
                                rbYes.Checked = true;
                            }
                            else
                            {
                                rbNo.Checked = true;
                            }

                            MandSelected = core.PopulateArray(MandatoryFields.Length, true);
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            Button oBtn = sender as Button;

            if (oBtn != null && formloaded)
            {
                TLADM_NonStockItems nsi = new TLADM_NonStockItems();

                string errorM = core.returnMessage(MandSelected, true, MandatoryFields);
                if (errorM != string.Empty)
                {
                    MessageBox.Show("The following Errors were encountered " + Environment.NewLine + errorM);
                    return;
                }

                var uom        = (TLADM_UOM)cmbUOM.SelectedItem;
                var nscat      = (TLADM_NonStockCat)cmbCategories.SelectedItem;
                var stocktypes = (TLADM_StockTypes)cmbStockTypes.SelectedItem;

                using (var context = new TTI2Entities())
                {
                    if (AddRecord)
                    {
                        nsi.NSI_Code           = txtCode.Text;
                        nsi.NSI_Description    = txtDescription.Text;
                        nsi.NSI_Category_FK    = nscat.NSC_Pk;
                        nsi.NSI_StockType_FK   = stocktypes.ST_Id;
                        nsi.NSI_UOM_FK         = uom.UOM_Pk;
                        nsi.NSI_Department_PWN = Convert.ToInt32(btnDept.Text);
                        nsi.NSI_UnitCost       = Convert.ToDecimal(txtBoxUnitCost.Text);
                        if (core.IsValueDidgit(btnDept.Text))
                        {
                            nsi.NSI_Department_PWN = Convert.ToInt32(btnDept.Text);
                        }
                        if (rbYes.Checked)
                        {
                            nsi.NSI_ShowUnitCost = true;
                        }

                        context.TLADM_NonStockItems.Add(nsi);
                    }
                    else
                    {
                        var test = (TLADM_NonStockItems)cmbNSI.SelectedItem;
                        nsi                  = context.TLADM_NonStockItems.Find(test.NSI_Pk);
                        nsi.NSI_Code         = txtCode.Text;
                        nsi.NSI_Description  = txtDescription.Text;
                        nsi.NSI_Category_FK  = nscat.NSC_Pk;
                        nsi.NSI_StockType_FK = stocktypes.ST_Id;
                        nsi.NSI_UOM_FK       = uom.UOM_Pk;
                        if (core.IsValueDidgit(btnDept.Text))
                        {
                            nsi.NSI_Department_PWN = Convert.ToInt32(btnDept.Text);
                        }
                        nsi.NSI_UnitCost = Convert.ToDecimal(txtBoxUnitCost.Text);
                        if (rbYes.Checked)
                        {
                            nsi.NSI_ShowUnitCost = true;
                        }
                    }

                    try
                    {
                        context.SaveChanges();
                        MessageBox.Show("records successfully updated to database");
                        cmbCategories.SelectedIndex = 0;
                        cmbNSI.SelectedIndex        = 0;
                        cmbStockTypes.SelectedIndex = 0;
                        cmbUOM.SelectedIndex        = 0;
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                        return;
                    }
                }
                Setup(false);
            }
        }