예제 #1
0
 private void cboProposed_SelectedIndexChanged(object sender, EventArgs e)
 {
     try
     {
         string        proposedID = (string)cboProposed.SelectedValue;
         List <string> lst        = db.Headquarter_SelectProduct(proposedID).ToList();
         double        totalMoney = 0;
         for (int i = 0; i < lst.Count; i++)
         {
             var    entityError = lst[i];
             double getMoney    = db.Prices.Single(x => x.ProductID == entityError).Price1;
             totalMoney += getMoney;
         }
         txtTotalAmount.Text = totalMoney.ToString();
     }
     catch { }
 }
예제 #2
0
        private void cboHeadquarterID_SelectedIndexChanged(object sender, EventArgs e)
        {
            lstProducts.Rows.Clear();

            string headquarterID = (string)cboHeadquarterID.SelectedValue;

            var enableButton = db.HeadquaterReceiptDetails.FirstOrDefault(x => x.HeadquaterID == headquarterID);

            if (enableButton == null)
            {
                btnUpdate.Enabled = false;
                btnCreate.Enabled = true;
            }
            else
            {
                btnUpdate.Enabled = true;
                btnCreate.Enabled = false;
            }
            LoadDetail(headquarterID);

            var tam = db.HeadquaterReceiptDetails.FirstOrDefault(x => x.HeadquaterID == headquarterID);

            if (tam == null)
            {
                string        proposedID = db.HeadquaterReceipts.Single(x => x.HeadquaterID == headquarterID).ProposeID;
                List <string> lst        = db.Headquarter_SelectProduct(proposedID).ToList();

                for (int i = 0; i < lst.Count; i++)
                {
                    var entityError = lst[i];
                    int quantity    = db.ProposeReceiptDetails.Single(x => x.ProposeID == proposedID && x.ProductID == entityError).Quantity;
                    //double price = db.Prices.Single(x => x.ProductID == entityError).Price1;
                    lstProducts.Rows.Add(entityError, quantity);
                    var status = db.HeadquaterReceiptDetails.FirstOrDefault(x => x.HeadquaterID == headquarterID && x.ProductID == entityError);
                    if (status == null)
                    {
                        foreach (DataGridViewRow row in lstProducts.Rows)
                        {
                            row.Cells[3].Value = false;
                            row.Cells[4].Value = false;
                            row.Cells[5].Value = false;
                        }
                    }
                    else
                    {
                        if (status.Status == "Full")
                        {
                            lstProducts.Rows[i].Cells[3].Value = true;
                            lstProducts.Rows[i].Cells[4].Value = false;
                            lstProducts.Rows[i].Cells[5].Value = false;
                        }
                        else if (status.Status == "Not enough")
                        {
                            lstProducts.Rows[i].Cells[3].Value = false;
                            lstProducts.Rows[i].Cells[4].Value = true;
                            lstProducts.Rows[i].Cells[5].Value = false;
                        }
                        else if (status.Status == "Damage")
                        {
                            lstProducts.Rows[i].Cells[3].Value = false;
                            lstProducts.Rows[i].Cells[4].Value = false;
                            lstProducts.Rows[i].Cells[5].Value = true;
                        }
                    }
                }
            }
            else
            {
                CMART0Entities db1        = new CMART0Entities();
                string         proposedID = db1.HeadquaterReceipts.Single(x => x.HeadquaterID == headquarterID).ProposeID;
                List <string>  lst        = db1.Headquarter_SelectProduct(proposedID).ToList();

                for (int i = 0; i < lst.Count; i++)
                {
                    var    entityError = lst[i];
                    int    quantity    = db1.HeadquaterReceiptDetails.Single(x => x.HeadquaterID == headquarterID && x.ProductID == entityError).Quantity;
                    double price       = db1.HeadquaterReceiptDetails.Single(x => x.HeadquaterID == headquarterID && x.ProductID == entityError).Price;
                    lstProducts.Rows.Add(entityError, quantity, price);
                    var status = db1.HeadquaterReceiptDetails.FirstOrDefault(x => x.HeadquaterID == headquarterID && x.ProductID == entityError);
                    if (status == null)
                    {
                        foreach (DataGridViewRow row in lstProducts.Rows)
                        {
                            row.Cells[3].Value = false;
                            row.Cells[4].Value = false;
                            row.Cells[5].Value = false;
                        }
                    }
                    else
                    {
                        if (status.Status == "Full")
                        {
                            lstProducts.Rows[i].Cells[3].Value = true;
                            lstProducts.Rows[i].Cells[4].Value = false;
                            lstProducts.Rows[i].Cells[5].Value = false;
                        }
                        else if (status.Status == "Not enough")
                        {
                            lstProducts.Rows[i].Cells[3].Value = false;
                            lstProducts.Rows[i].Cells[4].Value = true;
                            lstProducts.Rows[i].Cells[5].Value = false;
                        }
                        else if (status.Status == "Damage")
                        {
                            lstProducts.Rows[i].Cells[3].Value = false;
                            lstProducts.Rows[i].Cells[4].Value = false;
                            lstProducts.Rows[i].Cells[5].Value = true;
                        }
                    }
                }
            }
        }