Esempio n. 1
0
        private void cmbCotton_SelectedIndexChanged(object sender, EventArgs e)
        {
            ComboBox oCmb = sender as ComboBox;

            if (oCmb != null && formloaded)
            {
                var cotton = (TLADM_Cotton)cmbCotton.SelectedItem;
                if (cotton != null)
                {
                    using (var context = new TTI2Entities())
                    {
                        TLADM_Cotton newcotton = context.TLADM_Cotton.Find(cotton.Cotton_Pk);
                        txtCode.Text        = newcotton.Cotton_Code;
                        txtDescription.Text = newcotton.Cotton_Description;
                        txtGrade.Text       = newcotton.Cotton_Grade;
                        txtRol.Text         = Math.Round(newcotton.Cotton_ROL, 2).ToString();
                        txtRoq.Text         = Math.Round(newcotton.Cotton_ROQ, 2).ToString();
                        txtContact.Text     = newcotton.Cotton_Contact;
                        if (newcotton.Cotton_ShowQty)
                        {
                            rbShowQtyYes.Checked = true;
                            txtUnits.Visible     = true;
                        }
                        else
                        {
                            rbShowQtyNo.Checked = true;
                            txtUnits.Visible    = false;
                        }
                        if (newcotton.Cotton_ShowStdCost)
                        {
                            rbShowCostYes.Checked = true;
                            txtStdCost.Visible    = true;
                        }
                        else
                        {
                            rbShowQtyNo.Checked = true;
                            txtStdCost.Visible  = false;
                        }

                        txtStdCost.Text = Math.Round(newcotton.Cotton_StdCost, 2).ToString();
                        txtUnits.Text   = newcotton.Cotton_Units.ToString();

                        rtbNotes.Text = newcotton.Cotton_Notes;

                        cmbOrigin.SelectedValue      = newcotton.Cotton_Origin_FK;
                        cmbStore.SelectedValue       = newcotton.Cotton_Store_FK;
                        cmbUOM.SelectedValue         = newcotton.Cotton_UOM_Fk;
                        cmbStockType.SelectedValue   = newcotton.Cotton_StockType_FK;
                        cmbCottonAgent.SelectedValue = newcotton.Cotton_Agent_FK;

                        FldEntered = core.PopulateArray(FldNames.Length, true);
                    }
                }
            }
        }
Esempio n. 2
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            Button oBtn     = sender as Button;
            bool   lSuccess = true;

            if (oBtn != null && formloaded)
            {
                var Mess = returnMessage(FldEntered);
                if (!string.IsNullOrEmpty(Mess))
                {
                    MessageBox.Show(Mess);
                    return;
                }
                using (var context = new TTI2Entities())
                {
                    TLADM_Cotton ctn = new TLADM_Cotton();
                    if (!addRecord)
                    {
                        var cotton = (TLADM_Cotton)cmbCotton.SelectedItem;
                        if (cotton != null)
                        {
                            ctn = context.TLADM_Cotton.Find(cotton.Cotton_Pk);
                        }
                    }
                    ctn.Cotton_Code        = txtCode.Text;
                    ctn.Cotton_Description = txtDescription.Text;
                    ctn.Cotton_Grade       = txtGrade.Text;
                    ctn.Cotton_ROL         = Convert.ToDecimal(txtRol.Text);
                    ctn.Cotton_ROQ         = Convert.ToDecimal(txtRoq.Text);

                    if (rbShowCostYes.Checked)
                    {
                        ctn.Cotton_ShowStdCost = true;
                    }
                    else
                    {
                        ctn.Cotton_ShowStdCost = false;
                    }
                    if (rbShowQtyYes.Checked)
                    {
                        ctn.Cotton_ShowQty = true;
                    }
                    else
                    {
                        ctn.Cotton_ShowQty = false;
                    }

                    ctn.Cotton_Contact = txtContact.Text;
                    ctn.Cotton_Units   = Convert.ToInt32(txtUnits.Text);
                    ctn.Cotton_StdCost = Math.Round(Convert.ToDecimal(txtStdCost.Text), 2);
                    ctn.Cotton_Notes   = rtbNotes.Text;
                    //----------------------------------------------------------
                    var uom = (TLADM_UOM)cmbUOM.SelectedItem;
                    if (uom != null)
                    {
                        ctn.Cotton_UOM_Fk = uom.UOM_Pk;
                    }
                    else
                    {
                        ctn.Cotton_UOM_Fk = 1;
                    }

                    //---------------------------------------------------------------------
                    var store = (TLADM_WhseStore)cmbStore.SelectedItem;
                    if (store != null)
                    {
                        ctn.Cotton_Store_FK = store.WhStore_Id;
                    }
                    else
                    {
                        ctn.Cotton_Store_FK = 1;
                    }

                    //--------------------------------------------------------------------
                    var stock = (TLADM_StockTypes)cmbStockType.SelectedItem;
                    if (stock != null)
                    {
                        ctn.Cotton_StockType_FK = stock.ST_Id;
                    }
                    else
                    {
                        ctn.Cotton_StockType_FK = 1;
                    }

                    //-----------------------------------------------------------------------
                    var origin = (TLADM_CottonOrigin)cmbOrigin.SelectedItem;
                    if (origin != null)
                    {
                        ctn.Cotton_Origin_FK = origin.CottonOrigin_Pk;
                    }
                    else
                    {
                        ctn.Cotton_Origin_FK = 1;
                    }

                    //-----------------------------------------------------------------------
                    var agents = (TLADM_CottonAgent)cmbCottonAgent.SelectedItem;
                    if (agents != null)
                    {
                        ctn.Cotton_Agent_FK = agents.CottonAgent_Pk;
                    }
                    else
                    {
                        ctn.Cotton_Agent_FK = 1;
                    }

                    if (addRecord)
                    {
                        context.TLADM_Cotton.Add(ctn);
                    }

                    try
                    {
                        context.SaveChanges();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                        lSuccess = false;
                    }
                }
                if (lSuccess)
                {
                    MessageBox.Show("Records saved to database successfully");
                    Setup(false);
                }
            }
        }