private void SaveCommit()
        {
            using (SSLsEntities db = new SSLsEntities())
            {
                PriceSchedule ps           = new PriceSchedule();
                int           currentYear  = DateTime.Now.Year;
                int           currentMonth = DateTime.Now.Month;
                var           pro          = db.PriceSchedule.Where(w => w.CreateDate.Year == currentYear && w.CreateDate.Month == currentMonth).Count() + 1;
                string        proCodeGen   = SingletonThisBudgetYear.Instance().ThisYear.CodeYear + DateTime.Now.ToString("MM") + Library.GenerateCodeFormCount(pro, 3);

                ps.Code        = proCodeGen;
                ps.Enable      = true;
                ps.Name        = textBoxProName.Text;
                ps.Description = textBoxRemark.Text;
                ps.CreateDate  = DateTime.Now;
                ps.CreateBy    = SingletonAuthen.Instance().Id;
                ps.UpdateDate  = DateTime.Now;
                ps.UpdateBy    = SingletonAuthen.Instance().Id;
                ps.FKCampaign  = MyConstant.CampaignType.FullyAmountAndDiscount;
                // dd/MM/yyyy
                string[] date = dateTimePickerStart.Text.Split('/');
                ps.StartDate = Library.ConvertDateTime(date[0], date[1], date[2]);
                //ps.StartDate = DateTime.Parse(dateTimePickerStart.Text);
                date       = dateTimePickerEnd.Text.Split('/');
                ps.EndDate = Library.ConvertDateTime(date[0], date[1], date[2]);
                //ps.EndDate = DateTime.Parse(dateTimePickerEnd.Text);
                ps.Limited   = 0;
                ps.Notice    = textBoxProNotice.Text;
                ps.FullPrice = decimal.Parse(textBoxProAmount.Text);
                ps.FullQty   = 0;
                ps.Discount  = decimal.Parse(textBoxProDiscount.Text);
                ps.IsStop    = false;
                List <SellingPrice> details = new List <SellingPrice>();
                for (int i = 0; i < dataGridView1.Rows.Count; i++)
                {
                    details.Add(new SellingPrice()
                    {
                        CreateBy        = SingletonAuthen.Instance().Id,
                        CreateDate      = DateTime.Now,
                        Description     = dataGridView1.Rows[i].Cells[colRemark].Value.ToString(),
                        Enable          = true,
                        FKProduct       = int.Parse(dataGridView1.Rows[i].Cells[colId].Value.ToString()),
                        GetCurrentPrice = decimal.Parse(dataGridView1.Rows[i].Cells[colCurrentPrice].Value.ToString()),
                        Name            = textBoxProName.Text,
                        SpecialPrice    = 0,
                        UpdateDate      = DateTime.Now,
                        UpdateBy        = SingletonAuthen.Instance().Id
                    });
                    if (i >= dataGridView1.Rows.Count - 2)
                    {
                        break;
                    }
                }
                ps.SellingPrice = details;
                db.PriceSchedule.Add(ps);
                db.SaveChanges();
            }
            // reset all
            ResetForm();
        }
 /// <summary>
 /// ตกลง ต่อเวลา
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void button2_Click(object sender, EventArgs e)
 {
     using (SSLsEntities db = new SSLsEntities())
     {
         priceSchedule                 = db.PriceSchedule.SingleOrDefault(w => w.Id == priceSchedule.Id);
         priceSchedule.StartDate       = dateTimePickerStart.Value;
         priceSchedule.EndDate         = dateTimePickerEnd.Value;
         priceSchedule.UpdateDate      = DateTime.Now;
         priceSchedule.UpdateBy        = Singleton.SingletonAuthen.Instance().Id;
         db.Entry(priceSchedule).State = EntityState.Modified;
         db.SaveChanges();
         this.searchEditPromotionForm.Reload();
         this.Dispose();
     }
 }
 public SearchEditLongTimeDialog(SearchEditPromotionForm searchEditPromotionForm, PriceSchedule priceSchedule)
 {
     InitializeComponent();
     this.searchEditPromotionForm = searchEditPromotionForm;
     this.priceSchedule           = priceSchedule;
 }
        private void SaveCommit()
        {
            var thisBudget = SingletonThisBudgetYear.Instance().ThisYear;

            using (SSLsEntities db = new SSLsEntities())
            {
                int    currentYear  = DateTime.Now.Year;
                int    currentMonth = DateTime.Now.Month;
                var    pro          = db.PriceSchedule.Where(w => w.CreateDate.Year == currentYear && w.CreateDate.Month == currentMonth).Count() + 1;
                string code         = thisBudget.CodeYear + DateTime.Now.ToString("MM") + Library.GenerateCodeFormCount(pro, 3);

                PriceSchedule header = new PriceSchedule();
                header.Code        = code;
                header.Enable      = true;
                header.Name        = textBoxProName.Text;
                header.Description = textBoxRemark.Text;
                header.CreateDate  = DateTime.Now;
                header.CreateBy    = SingletonAuthen.Instance().Id;
                header.UpdateBy    = SingletonAuthen.Instance().Id;
                header.UpdateDate  = DateTime.Now;
                header.FKCampaign  = MyConstant.CampaignType.FullyQtyAndGift;
                header.StartDate   = dateTimePickerStart.Value;
                header.EndDate     = dateTimePickerEnd.Value;
                header.Limited     = 0;
                header.Notice      = textBoxProNotice.Text;
                header.FullPrice   = 0;
                header.FullQty     = 0;
                header.Discount    = 0;
                header.IsStop      = false;
                header.StopReason  = null;

                /// ต้อง Row เท่ากัน
                if (dataGridView1.Rows.Count == dataGridView2.Rows.Count)
                {
                    SellingPrice        selling;
                    SellingPriceDetails details;
                    for (int i = 0; i < dataGridView1.Rows.Count; i++)
                    {
                        selling                 = new SellingPrice();
                        selling.CreateDate      = DateTime.Now;
                        selling.CreateBy        = SingletonAuthen.Instance().Id;
                        selling.Enable          = true;
                        selling.Name            = header.Name;
                        selling.Description     = null;
                        selling.UpdateDate      = DateTime.Now;
                        selling.UpdateBy        = SingletonAuthen.Instance().Id;
                        selling.FKProduct       = int.Parse(dataGridView1.Rows[i].Cells[col1Id].Value.ToString());
                        selling.GetCurrentPrice = decimal.Parse(dataGridView1.Rows[i].Cells[col1Price].Value.ToString());
                        selling.SpecialPrice    = 0;
                        selling.FullyQty        = decimal.Parse(dataGridView1.Rows[i].Cells[col1Qty].Value.ToString());

                        /// ส่วนของแถม
                        details                 = new SellingPriceDetails();
                        details.Enable          = true;
                        details.Name            = header.Name;
                        details.CreateDate      = DateTime.Now;
                        details.CreateBy        = SingletonAuthen.Instance().Id;
                        details.UpdateDate      = DateTime.Now;
                        details.UpdateBy        = SingletonAuthen.Instance().Id;
                        details.FKProduct       = int.Parse(dataGridView2.Rows[i].Cells[col2Id].Value.ToString());
                        details.GiftQty         = decimal.Parse(dataGridView2.Rows[i].Cells[col2Qty].Value.ToString());
                        details.GetCurrentPrice = decimal.Parse(dataGridView2.Rows[i].Cells[col2Price].Value.ToString());
                        details.SpecialPrice    = 0;

                        selling.SellingPriceDetails.Add(details);
                        header.SellingPrice.Add(selling);
                        if (i >= dataGridView1.Rows.Count - 2)
                        {
                            break;
                        }
                    }
                }
                else
                {
                    MessageBox.Show("พบข้อผิดพลาดกรุณาตรวจสอบดูอีกครั้ง");
                }
                db.PriceSchedule.Add(header);
                db.SaveChanges();
                // reset all
                ResetForm();
            }
        }