Exemple #1
0
 /// <summary>
 /// ทำการตัด stock ที่ QtyAllow
 /// </summary>
 private void ConfirmISSOrder()
 {
     using (SSLsEntities db = new SSLsEntities())
     {
         var data = db.SaleOrderWarehouse.SingleOrDefault(w => w.Code == code);
         data.FKSaleOrderWarehouseStatus = MyConstant.SaleOrderWarehouseStatus.WarehouseISS;
         data.UpdateDate      = DateTime.Now;
         data.UpdateBy        = Singleton.SingletonAuthen.Instance().Id;
         db.Entry(data).State = EntityState.Modified;
         for (int i = 0; i < dataGridView1.Rows.Count; i++)
         {
             int id  = int.Parse(dataGridView1.Rows[i].Cells[colId].Value.ToString());
             var dtl = data.SaleOrderWarehouseDtl.SingleOrDefault(w => w.Id == id);
             dtl.QtyAllow        = decimal.Parse(dataGridView1.Rows[i].Cells[colQtyAllow].Value.ToString());
             dtl.UpdateDate      = DateTime.Now;
             dtl.UpdateBy        = Singleton.SingletonAuthen.Instance().Id;
             db.Entry(dtl).State = EntityState.Modified;
         }
         db.SaveChanges();
         data = db.SaleOrderWarehouse.SingleOrDefault(w => w.Code == code);
         Library.MakeValueForUpdateStockWms(data.SaleOrderWarehouseDtl.Where(w => w.Enable == true).ToList());
         this.saleOrderWarehouseTakeForm.LoadGrid();
         this.Dispose();
     }
 }
        /// <summary>
        /// บันทึกการแก้ไข โดยไล่ Disable ตัวเดิมทิ้งให้หมด แล้ว add ใหม่
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button6_Click(object sender, EventArgs e)
        {
            DialogResult dr = MessageBox.Show("คุณต้องการบันทึกข้อมูล ใช่หรือไม่ ?", "คำเตือนจากระบบ", MessageBoxButtons.YesNo);

            switch (dr)
            {
            case DialogResult.Yes:
                using (SSLsEntities db = new SSLsEntities())
                {
                    var order = db.SaleOrderWarehouse.SingleOrDefault(w => w.Code == code);
                    foreach (var item in order.SaleOrderWarehouseDtl.Where(w => w.Enable == true).ToList())
                    {
                        item.UpdateDate      = DateTime.Now;
                        item.UpdateBy        = SingletonAuthen.Instance().Id;
                        item.Enable          = false;
                        db.Entry(item).State = EntityState.Modified;
                    }
                    List <SaleOrderWarehouseDtl> details = new List <SaleOrderWarehouseDtl>();
                    SaleOrderWarehouseDtl        detail;
                    decimal discountList = 0;
                    for (int i = 0; i < dataGridView1.Rows.Count; i++)
                    {
                        detail = new SaleOrderWarehouseDtl();
                        detail.FKSaleOrderWarehouse = order.Id;
                        detail.Enable       = true;
                        detail.Description  = dataGridView1.Rows[i].Cells[colRemark].Value.ToString();
                        detail.CreateDate   = DateTime.Now;
                        detail.CreateBy     = SingletonAuthen.Instance().Id;
                        detail.UpdateDate   = DateTime.Now;
                        detail.UpdateBy     = SingletonAuthen.Instance().Id;
                        detail.FKProductDtl = int.Parse(dataGridView1.Rows[i].Cells[colId].Value.ToString());
                        detail.Qty          = decimal.Parse(dataGridView1.Rows[i].Cells[colQty].Value.ToString());          // จำนวนหน่วย
                        detail.PricePerUnit = decimal.Parse(dataGridView1.Rows[i].Cells[colPricePerUnit].Value.ToString()); // จำนวนหน่วย
                        detail.BathDiscount = decimal.Parse(dataGridView1.Rows[i].Cells[colDiscount].Value.ToString());     // จำนวนเงินส่วนลด
                        detail.TotalPrice   = decimal.Parse(dataGridView1.Rows[i].Cells[colTotalPrice].Value.ToString());   // จำนวนเงิน หลังหักส่วนลด
                        details.Add(detail);
                        discountList += decimal.Parse(dataGridView1.Rows[i].Cells[colDiscount].Value.ToString());
                        if (i >= dataGridView1.Rows.Count - 2)
                        {
                            break;
                        }
                    }
                    db.SaleOrderWarehouseDtl.AddRange(details);
                    order.TotalDiscountInList = discountList;     // วนใน ลิส
                    order.TotalBalance        = decimal.Parse(textBoxTotalBalance.Text);
                    order.UpdateDate          = DateTime.Now;
                    order.UpdateBy            = SingletonAuthen.Instance().Id;
                    db.Entry(order).State     = EntityState.Modified;
                    db.SaveChanges();
                    saleOrderWarehouseListForm.LoadGrid();
                    this.Dispose();
                }
                break;

            case DialogResult.No:
                break;
            }
        }
        private void button2_Click(object sender, EventArgs e)
        {
            if (_EmployeeId == 0)
            {
                MessageBox.Show("กรุณาเลือกผู้หยิบ");
                return;
            }
            try
            {
                DialogResult dr = MessageBox.Show("คุณต้องการบันทึกข้อมูล ใช่หรือไม่ ?",
                                                  "คำเตือนจากระบบ", MessageBoxButtons.YesNo);
                switch (dr)
                {
                case DialogResult.Yes:
                    using (SSLsEntities db = new SSLsEntities())
                    {
                        var data = db.ISS2Front.SingleOrDefault(w => w.Code == code);
                        for (int i = 0; i < dataGridView1.Rows.Count; i++)
                        {
                            int     id     = int.Parse(dataGridView1.Rows[i].Cells[0].Value.ToString());
                            decimal allow  = decimal.Parse(dataGridView1.Rows[i].Cells[colAllowQty].Value.ToString());
                            var     detail = data.ISS2FrontDetails.SingleOrDefault(w => w.Id == id);
                            detail.QtyAllow        = allow;
                            detail.UpdateDate      = DateTime.Now;
                            detail.UpdateBy        = Singleton.SingletonAuthen.Instance().Id;
                            db.Entry(detail).State = EntityState.Modified;
                        }
                        data.FKISS2FrontStatus = MyConstant.ISS2FrontStatus.ConfirmOrder;
                        data.FKEmployee        = _EmployeeId;
                        data.Takedate          = DateTime.Now;
                        data.TakeBy            = Singleton.SingletonAuthen.Instance().Id;
                        data.Remark            = textBoxRemark.Text;
                        db.Entry(data).State   = EntityState.Modified;

                        db.SaveChanges();
                        /// ตัด stock wms แล้ว
                        Library.MakeValueForUpdateStockWms(data.ISS2FrontDetails.ToList());
                        /// เพิ่ม stock
                        /// + store Front
                        Library.MakeValueForUpdateStockPos(data.ISS2FrontDetails.ToList());
                        this.iSS2FrontManageForm.LoadGrid();
                        this.Dispose();
                    }
                    break;

                case DialogResult.No:
                    break;
                }
            }
            catch (Exception)
            {
                MessageBox.Show("พบสิ่งผิดพลาด");
            }
        }
        /// <summary>
        /// ลบสินค้า ที่ selling price
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button2_Click(object sender, EventArgs e)
        {
            DialogResult dr = MessageBox.Show("คุณต้องการบันทึกข้อมูล ใช่หรือไม่ ?",
                                              "คำเตือนจากระบบ", MessageBoxButtons.YesNo);

            switch (dr)
            {
            case DialogResult.Yes:
                int rowCurrent = dataGridView1.CurrentRow.Index;
                int idSelling  = int.Parse(dataGridView1.Rows[rowCurrent].Cells[0].Value.ToString());
                using (SSLsEntities db = new SSLsEntities())
                {
                    var data = db.SellingPrice.SingleOrDefault(w => w.Id == idSelling);
                    data.Enable          = false;
                    data.UpdateDate      = DateTime.Now;
                    data.UpdateBy        = Singleton.SingletonAuthen.Instance().Id;
                    db.Entry(data).State = EntityState.Modified;

                    db.SaveChanges();
                    Reload();
                }
                break;

            case DialogResult.No:
                break;
            }
        }
        /// <summary>
        ///  ยกเลิก ต้องเอาลง CNCancel ด้วย
        /// </summary>
        private void SaveCommit()
        {
            using (SSLsEntities db = new SSLsEntities())
            {
                var data = db.CNHeader.SingleOrDefault(w => w.No == textBoxCNNo.Text.Trim());
                data.UpdateDate = DateTime.Now;
                data.UpdateBy   = Singleton.SingletonAuthen.Instance().Id;
                data.Enable     = false;

                CNCancel cancel = new CNCancel();
                cancel.FKCN        = textBoxCNNo.Text.Trim();
                cancel.Enable      = true;
                cancel.Description = textBoxDescription.Text.Trim();
                cancel.CreateDate  = DateTime.Now;
                cancel.CreateBy    = Singleton.SingletonAuthen.Instance().Id;
                cancel.UpdateDate  = DateTime.Now;
                cancel.UpdateBy    = Singleton.SingletonAuthen.Instance().Id;
                db.CNCancel.Add(cancel);
                // update -stock pos
                Library.MakeValueForUpdateStockPos(data.CNDetails.Where(w => w.Enable == true).ToList(), "ยกเลิกทำคืน");
                foreach (var item in data.CNDetails.Where(w => w.Enable == true).ToList())
                {
                    item.Enable     = false;
                    item.UpdateDate = DateTime.Now;
                    item.UpdateBy   = Singleton.SingletonAuthen.Instance().Id;
                }
                db.Entry(data).State = EntityState.Modified;
                db.SaveChanges();

                this.Dispose();
            }
        }
Exemple #6
0
        /// <summary>
        /// พิมพ์
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button4_Click(object sender, EventArgs e)
        {
            try
            {
                string code = textBoxDocNo.Text.Trim();
                using (SSLsEntities db = new SSLsEntities())
                {
                    var getDocOlder = db.StoreFrontValueDoc.SingleOrDefault(w => w.DocNo == code && w.Enable == true);
                    if (getDocOlder != null)
                    {
                        getDocOlder.PrintNumber     = getDocOlder.PrintNumber + 1;
                        db.Entry(getDocOlder).State = EntityState.Modified;
                        db.SaveChanges();
                    }
                    else
                    {
                        MessageBox.Show("ไม่ถูกต้อง");
                    }
                }

                frmMainReport mr = new frmMainReport(this, code);
                mr.Show();
            }
            catch (Exception)
            {
                MessageBox.Show("ไม่ถูกต้อง");
            }
        }
Exemple #7
0
        /// <summary>
        /// ปฏิเสธออเดอร์ หรือ Reject จะต้องเป็น ออเดอร์ ที่ถูกยืนยันมาแล้ว เท่านั้น
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button3_Click(object sender, EventArgs e)
        {
            using (SSLsEntities db = new SSLsEntities())
            {
                string code = dataGridView1.Rows[dataGridView1.CurrentRow.Index].Cells[2].Value.ToString();
                var    data = db.SaleOrderWarehouse.SingleOrDefault(w => w.Code == code);
                if (data.FKSaleOrderWarehouseStatus == MyConstant.SaleOrderWarehouseStatus.ConfirmOrder)
                {
                    if (textBoxRemark.Text.Trim() == "")
                    {
                        MessageBox.Show("กรุณากรอกหมายเหตุ");
                        return;
                    }
                    DialogResult dr = MessageBox.Show("คุณต้องการบันทึกข้อมูล ใช่หรือไม่ ?", "คำเตือนจากระบบ", MessageBoxButtons.YesNo);
                    switch (dr)
                    {
                    case DialogResult.Yes:
                        data.FKSaleOrderWarehouseStatus = MyConstant.SaleOrderWarehouseStatus.WarehouseRejectOrder;
                        data.UpdateDate      = DateTime.Now;
                        data.UpdateBy        = Singleton.SingletonAuthen.Instance().Id;
                        db.Entry(data).State = EntityState.Modified;
                        db.SaveChanges();
                        LoadGrid();
                        break;

                    case DialogResult.No:
                        break;
                    }
                }
                else
                {
                    MessageBox.Show("ไม่สามารถปฏิเสธออเดอร์นี้ได้");
                }
            }
        }
        /// <summary>
        /// ปิดสถานะ จะปิดได้ ต้อง enable == true และต้องมีการรับเข้า > 0%
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button5_Click(object sender, EventArgs e)
        {
            SSLsEntities    db = new SSLsEntities();
            WH_TRATEntities wh = new WH_TRATEntities();

            try
            {
                int currentRow = dataGridView1.CurrentRow.Index;
                int currentId  = int.Parse(dataGridView1.Rows[currentRow].Cells[0].Value.ToString());
                var data       = db.POHeader.SingleOrDefault(w => w.Id == currentId);
                if (data.Enable == false)
                {
                    MessageBox.Show("PO นี้ยกเลิกไปแล้ว");
                }
                else if (data.FKPOStatus == MyConstant.POStatus.RCVComplete || data.FKPOStatus == MyConstant.POStatus.RCVNotComplete_ButEnd)
                {
                    MessageBox.Show("PO นี้ ปิดสถานะแล้ว");
                }
                else if (data.FKPOStatus == MyConstant.POStatus.NotRCV)
                {
                    MessageBox.Show("PO นี้ ไม่เคยรับเข้ามาก่อน ไม่สามารถปิดได้");
                }
                else
                {
                    //
                    DialogResult dr = MessageBox.Show("คุณต้องการบันทึกข้อมูล ใช่หรือไม่ ?",
                                                      "คำเตือนจากระบบ", MessageBoxButtons.YesNo);
                    switch (dr)
                    {
                    case DialogResult.Yes:
                        data.UpdateDate      = DateTime.Now;
                        data.UpdateBy        = Singleton.SingletonAuthen.Instance().Id;
                        data.FKPOStatus      = MyConstant.POStatus.RCVNotComplete_ButEnd;
                        db.Entry(data).State = EntityState.Modified;

                        var poOrder = wh.PS_PO_ORDER.FirstOrDefault(w => w.ENABLE == true && w.PO_NO == data.PONo);
                        poOrder.CONFIRMRCV      = DateTime.Now;
                        wh.Entry(poOrder).State = EntityState.Modified;

                        wh.SaveChanges();
                        db.SaveChanges();
                        Search();
                        break;

                    case DialogResult.No:
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("พบข้อผิดพลาด ในการเลือกรายการ");
            }
            finally
            {
                db.Dispose();
                wh.Dispose();
            }
        }
 /// <summary>
 /// ตรวจสอบ Promotion หยุดทำงาน
 /// </summary>
 private void CheckPromorionstop()
 {
     using (SSLsEntities db = new SSLsEntities())
     {
         var      dateQuery  = db.Database.SqlQuery <DateTime>("SELECT getdate()");
         DateTime serverDate = dateQuery.AsEnumerable().First();
         var      dateCheck  = db.PriceScheduleCheck.FirstOrDefault(w => DbFunctions.TruncateTime(w.DateCheck) == DbFunctions.TruncateTime(serverDate));
         if (dateCheck.IsCheck == false)
         {
             // ถ้าวันนี้ ยังไม่เชค ก็เชค
             dateCheck.IsCheck         = true;
             dateCheck.CheckDate       = serverDate;
             dateCheck.CheckBy         = SingletonAuthen.Instance().Id;
             db.Entry(dateCheck).State = EntityState.Modified;
             var priceSchedule = db.PriceSchedule.Where(w => w.Enable == true && w.IsStop == false);
             foreach (var item in priceSchedule)
             {
                 if (serverDate > item.EndDate)
                 {
                     // ถ้าวันนี้ มากกว่า วันสิ้นสุด
                     // โปรโมชั่น ควร Stop ลง
                     item.IsStop          = true;
                     item.StopReason      = "Stop By Code";
                     item.UpdateDate      = DateTime.Now;
                     item.UpdateBy        = SingletonAuthen.Instance().Id;
                     db.Entry(item).State = EntityState.Modified;
                 }
             }
             db.SaveChanges();
         }
         else
         {
             // ถ้าวันนี้ เชคแล้ว ปล่อยผ่าน
         }
         //int days = 1000;
         //for (int i = 0; i < days; i++)
         //{
         //    PriceScheduleCheck f = new PriceScheduleCheck();
         //    f.DateCheck = DateTime.Now.AddDays(i + 1);
         //    f.IsCheck = false;
         //    db.PriceScheduleCheck.Add(f);
         //}
         //db.SaveChanges();
     }
 }
Exemple #10
0
        private void CheckCount1()
        {
            string docno = textBoxDocNo.Text.Trim();

            using (SSLsEntities db = new SSLsEntities())
            {
                var getDocOlder = db.StoreFrontValueDoc.SingleOrDefault(w => w.DocNo == docno && w.Enable == true);
                if (getDocOlder.ConfirmCheck1Date != null)
                {
                    return;
                }
                if (getDocOlder != null)
                {
                    _GetDocNo = getDocOlder;
                    if (_GetDocNo.ConfirmCheck1Date == null) // ยังไม่ยืนยัน 1
                    {
                        getDocOlder.ConfirmCheck1Date = DateTime.Now;
                        getDocOlder.ConfirmCheck1By   = Singleton.SingletonAuthen.Instance().Id;
                        foreach (var item in getDocOlder.StoreFrontValueSet.Where(w => w.Enable == true).ToList())
                        {
                            item.QtyUnit2        = item.QtyUnit1;
                            item.Total           = item.CostOnlyPerUnit * item.QtyUnit2;
                            db.Entry(item).State = EntityState.Modified;
                        }
                        db.Entry(getDocOlder).State = EntityState.Modified;
                        db.SaveChanges();
                        MessageBox.Show("ยืนยันตรวจนับ 1 เรียบร้อย");
                        BinddingUI();
                    }

                    //else if (_GetDocNo.ConfirmCheck1Date != null && _GetDocNo.ConfirmCheck2Date == null)
                    //{
                    //    dataGridView1.Columns[colQty1].ReadOnly = true;
                    //    dataGridView1.Columns[colQty2].ReadOnly = false;
                    //    dataGridView1.Columns[colCode].ReadOnly = true;
                    //}
                    //else
                    //{
                    //    dataGridView1.Columns[colCode].ReadOnly = true;
                    //}
                }
            }
        }
Exemple #11
0
        private void CheckCount2()
        {
            string docno = textBoxDocNo.Text.Trim();

            using (SSLsEntities db = new SSLsEntities())
            {
                var getDocOlder = db.StoreFrontValueDoc.SingleOrDefault(w => w.DocNo == docno && w.Enable == true);
                if (getDocOlder != null)
                {
                    _GetDocNo = getDocOlder;
                    if (_GetDocNo.ConfirmCheck1Date != null && _GetDocNo.ConfirmCheck2Date == null) // ยังไม่ยืนยัน 1
                    {
                        getDocOlder.ConfirmCheck2Date = DateTime.Now;
                        getDocOlder.ConfirmCheck2By   = Singleton.SingletonAuthen.Instance().Id;
                        for (int i = 0; i < dataGridView1.Rows.Count; i++)
                        {
                            if (dataGridView1.Rows[i].Cells[colCode].Value != null)
                            {
                                int     number = int.Parse(dataGridView1.Rows[i].Cells[colNumber].Value.ToString());
                                decimal qty1   = decimal.Parse(dataGridView1.Rows[i].Cells[colQty1].Value.ToString());
                                decimal qty2   = decimal.Parse(dataGridView1.Rows[i].Cells[colQty2].Value.ToString());
                                decimal total  = decimal.Parse(dataGridView1.Rows[i].Cells[colTotal].Value.ToString());
                                if (qty1 != qty2)
                                {
                                    // แปลว่ามีการนับ 2
                                    var edit = getDocOlder.StoreFrontValueSet.FirstOrDefault(w => w.Enable == true && w.Number == number);
                                    edit.QtyUnit2        = qty2;
                                    edit.Total           = total;
                                    db.Entry(edit).State = EntityState.Modified;
                                }
                            }
                        }
                        getDocOlder.TotalQtyUnit    = decimal.Parse(textBoxUnit.Text);
                        getDocOlder.TotalCostOnly   = decimal.Parse(textBoxValue.Text);
                        db.Entry(getDocOlder).State = EntityState.Modified;
                        db.SaveChanges();
                        MessageBox.Show("ยืนยันตรวจนับ 2 เรียบร้อย");
                        BinddingUI();
                    }
                }
            }
        }
        /// <summary>
        /// po ที่จะ ไม่อนุมัติ หรือเตะทิ้ง จะต้องยังไม่อนูมัติ
        /// </summary>
        private void NotApproveSave()
        {
            List <int> idsPO = new List <int>();

            for (int i = 0; i < dataGridView1.Rows.Count; i++)
            {
                var    po    = dataGridView1.Rows[i].Cells[3].Value.ToString();
                string check = "";
                if (dataGridView1.Rows[i].Cells[9].Value == null)
                {
                    check = "FALSE";
                }
                else
                {
                    check = dataGridView1.Rows[i].Cells[9].Value.ToString();
                }

                var id = dataGridView1.Rows[i].Cells[0].Value.ToString();
                Console.WriteLine(id + " " + po + " --------- " + check);
                if (check.ToUpper() == "TRUE")
                {
                    idsPO.Add(int.Parse(id));
                }
            }
            Console.WriteLine(idsPO.Count());
            if (idsPO.Count() < 1)
            {
                MessageBox.Show("ไม่มีพบเลือกรายการ");
                return;
            }
            else if (idsPO.Count() > 0 && textBoxNotApproveRemark.Text == "")
            {
                MessageBox.Show("กรุณากรอกเหตุผล");
                return;
            }
            using (SSLsEntities db = new SSLsEntities())
            {
                var pos = db.POHeader.Where(w => idsPO.Contains(w.Id)).ToList();
                foreach (var item in pos)
                {
                    if (item.ApproveDate != null || item.NotApproveDate != null)
                    {
                        MessageBox.Show("พบ PO อนุมัติแล้ว " + item.PONo);
                        return;
                    }
                    item.NotApproveDate   = DateTime.Now;
                    item.NotApproveBy     = Singleton.SingletonAuthen.Instance().Id;
                    item.NotApproveRemark = textBoxNotApproveRemark.Text;
                    db.Entry(item).State  = EntityState.Modified;
                }
                db.SaveChanges();
            }
            Search();
        }
        /// <summary>
        /// ยืนยันบันทึก
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button4_Click(object sender, EventArgs e)
        {
            DialogResult dr = MessageBox.Show("คุณต้องการบันทึกข้อมูล ใช่หรือไม่ ?",
                                              "คำเตือนจากระบบ", MessageBoxButtons.YesNo);

            switch (dr)
            {
            case DialogResult.Yes:
                //Console.WriteLine(textBoxTotalCost.Text);
                if (_SaveChangeType == 0)
                {
                    SaveCommit();
                }
                else if (_SaveChangeType == 1)
                {
                    // check ว่าใครหายไป
                    ReturnToStock();
                    // check การเพิ่ม ลด วัตถุดิบ ต้องไล่คืน ให้หมดก่อน
                    CheckAddNew();
                    // check ว่า เพิ่มเติมหรือไม่
                    int newQty = int.Parse(textBoxQty.Text) - _QTY;
                    if (newQty > 0)
                    {
                        // กระทำกับกับ _QTY
                        QtyEdit(MyConstant.PosTransaction.AddProcessingGoods, Math.Abs(newQty), MyConstant.PosTransaction.ProcessingGoods);
                    }
                    else if (newQty < 0)
                    {
                        QtyEdit(MyConstant.PosTransaction.MinusProcessingGoods, Math.Abs(newQty), MyConstant.PosTransaction.CancelProcessingGoods);
                    }
                }
                using (SSLsEntities db = new SSLsEntities())
                {
                    var data = db.ProductDetails.SingleOrDefault(w => w.Id == _FKProDtl);

                    decimal totalcost = decimal.Parse(textBoxTotalCost.Text);
                    if (data.CostAndVat != totalcost)
                    {
                        // update now
                        data.CostAndVat      = totalcost;
                        data.CostVat         = Library.CalVatFromValue(data.CostAndVat);
                        data.CostOnly        = data.CostAndVat - data.CostVat;
                        db.Entry(data).State = EntityState.Modified;
                        db.SaveChanges();
                    }
                }
                this.Dispose();
                break;

            case DialogResult.No:
                break;
            }
        }
Exemple #14
0
        /// <summary>
        ///
        /// </summary>
        private void SaveCommit()
        {
            using (SSLsEntities db = new SSLsEntities())
            {
                if (_id == 0)
                {
                    // add new
                    Debtor d = new Debtor();
                    d.Code        = textBoxCode.Text.Trim();
                    d.Name        = textBoxName.Text.Trim();
                    d.Address     = textBoxAddress.Text.Trim();
                    d.Tel         = textBoxTel.Text.Trim();
                    d.Email       = textBoxEmail.Text.Trim();
                    d.TaxNo       = textBoxTax.Text.Trim();
                    d.LineId      = textBoxLine.Text.Trim();
                    d.Fax         = "-";
                    d.Description = null;
                    d.CreateDate  = DateTime.Now;
                    d.CreateBy    = Singleton.SingletonAuthen.Instance().Id;
                    d.UpdateDate  = DateTime.Now;
                    d.UpdateBy    = Singleton.SingletonAuthen.Instance().Id;
                    d.Enable      = true;
                    db.Debtor.Add(d);
                    db.SaveChanges();

                    Debtor data = db.Debtor.OrderByDescending(w => w.CreateDate).FirstOrDefault(w => w.CreateBy == d.CreateBy);
                    Singleton.SingletonDebtor.Instance().Debtors.Add(data);
                }
                else
                {
                    // Update
                    var d      = db.Debtor.SingleOrDefault(w => w.Id == _id);
                    var oldDeb = Singleton.SingletonDebtor.Instance().Debtors.SingleOrDefault(w => w.Id == _id);
                    Singleton.SingletonDebtor.Instance().Debtors.Remove(oldDeb);

                    d.Code            = textBoxCode.Text.Trim();
                    d.Name            = textBoxName.Text.Trim();
                    d.Address         = textBoxAddress.Text.Trim();
                    d.Tel             = textBoxTel.Text.Trim();
                    d.Email           = textBoxEmail.Text.Trim();
                    d.TaxNo           = textBoxTax.Text.Trim();
                    d.LineId          = textBoxLine.Text.Trim();
                    d.UpdateDate      = DateTime.Now;
                    d.UpdateBy        = Singleton.SingletonAuthen.Instance().Id;
                    db.Entry(d).State = EntityState.Modified;

                    Debtor data = db.Debtor.OrderByDescending(w => w.UpdateDate).FirstOrDefault(w => w.UpdateBy == d.UpdateBy);
                    Singleton.SingletonDebtor.Instance().Debtors.Add(data);
                    db.SaveChanges();
                }
                Reload(textBoxSearchKey.Text.Trim());
            }
        }
Exemple #15
0
 /// <summary>
 /// บันทึก
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void button2_Click(object sender, EventArgs e)
 {
     using (SSLsEntities db = new SSLsEntities())
     {
         try
         {
             if (_checkAdd)
             {
                 // is add new
                 Users user = new Users();
                 user.Id          = textBoxUser.Text;
                 user.Password    = "******";
                 user.Name        = textBoxFullName.Text;
                 user.Description = textBoxDesc.Text;
                 user.FKRole      = int.Parse(textBoxRoleId.Text);
                 user.FKBranch    = MyConstant.MyBranch._02;
                 user.CreateDate  = DateTime.Now;
                 user.CreateBy    = Singleton.SingletonAuthen.Instance().Id;
                 user.UpdateDate  = DateTime.Now;
                 user.UpdateBy    = Singleton.SingletonAuthen.Instance().Id;
                 user.Enable      = true;
                 db.Users.Add(user);
                 _checkAdd = false;
             }
             else
             {
                 var data = db.Users.SingleOrDefault(w => w.Id == textBoxUser.Text);
                 data.Name        = textBoxFullName.Text;
                 data.FKRole      = int.Parse(textBoxRoleId.Text);
                 data.Description = textBoxDesc.Text;
                 data.UpdateDate  = DateTime.Now;
                 data.UpdateBy    = Singleton.SingletonAuthen.Instance().Id;
                 if (radioButtonNon.Checked == true)
                 {
                     // ถ้าระงับใช้งาน
                     data.Enable = false;
                 }
                 else
                 {
                     data.Enable = true;
                 }
                 db.Entry(data).State = EntityState.Modified;
             }
             db.SaveChanges();
             Reload();
         }
         catch (Exception)
         {
             MessageBox.Show("กรุณาตรวจสอบ User ซ้ำ");
         }
     }
 }
 private void SaveConfirm()
 {
     using (SSLsEntities db = new SSLsEntities())
     {
         string code = dataGridView1.Rows[dataGridView1.CurrentRow.Index].Cells[0].Value.ToString();
         var    data = db.CNWarehouse.SingleOrDefault(w => w.Enable == true && w.Code == code);
         data.ConfirmCNDate   = DateTime.Now;
         data.ConfirmCNBy     = SingletonAuthen.Instance().Id;
         db.Entry(data).State = EntityState.Modified;
         db.SaveChanges();
         SearchData();
     }
 }
        /// <summary>
        /// ยกเลิก PO ทีละ 1 PO
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button4_Click(object sender, EventArgs e)
        {
            SSLsEntities db = new SSLsEntities();

            try
            {
                int currentRow = dataGridView1.CurrentRow.Index;
                int currentId  = int.Parse(dataGridView1.Rows[currentRow].Cells[0].Value.ToString());
                var data       = db.POHeader.SingleOrDefault(w => w.Id == currentId);
                if (data.Enable == false)
                {
                    MessageBox.Show("PO นี้ยกเลิกไปแล้ว");
                }
                else if (data.FKPOStatus == MyConstant.POStatus.RCVComplete || data.FKPOStatus == MyConstant.POStatus.RCVNotComplete_ButEnd)
                {
                    MessageBox.Show("PO นี้ ปิดสถานะแล้ว");
                }
                else if (data.FKPOStatus == MyConstant.POStatus.RCVNotEnd)
                {
                    MessageBox.Show("PO นี้ อยู่ในระหว่างรับเข้า");
                }
                else
                {
                    //
                    DialogResult dr = MessageBox.Show("คุณต้องการบันทึกข้อมูล ใช่หรือไม่ ?",
                                                      "คำเตือนจากระบบ", MessageBoxButtons.YesNo);
                    switch (dr)
                    {
                    case DialogResult.Yes:
                        data.UpdateDate      = DateTime.Now;
                        data.UpdateBy        = Singleton.SingletonAuthen.Instance().Id;
                        data.Enable          = false;
                        db.Entry(data).State = EntityState.Modified;
                        db.SaveChanges();
                        Search();
                        break;

                    case DialogResult.No:
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("พบข้อผิดพลาด ในการเลือกรายการ");
            }
            finally
            {
                db.Dispose();
            }
        }
        private void button2_Click(object sender, EventArgs e)
        {
            using (SSLsEntities db = new SSLsEntities())
            {
                if (_Id == 0)
                {
                    // add new
                    Supplier obj = new Supplier();
                    obj.Code        = textBoxCode.Text;
                    obj.Name        = textBoxName.Text;
                    obj.Address     = textBoxAddress.Text;
                    obj.Tel         = textBoxTel.Text;
                    obj.Description = textBoxDesc.Text;
                    obj.CreateDate  = DateTime.Now;
                    obj.CreateBy    = Singleton.SingletonAuthen.Instance().Id;
                    obj.Enable      = true;
                    obj.UpdateBy    = Singleton.SingletonAuthen.Instance().Id;
                    obj.UpdateDate  = DateTime.Now;
                    db.Supplier.Add(obj);
                }
                else
                {
                    // edit
                    var obj = db.Supplier.SingleOrDefault(w => w.Id == _Id);
                    obj.UpdateDate  = DateTime.Now;
                    obj.UpdateBy    = Singleton.SingletonAuthen.Instance().Id;
                    obj.Code        = textBoxCode.Text;
                    obj.Name        = textBoxName.Text;
                    obj.Address     = textBoxAddress.Text;
                    obj.Tel         = textBoxTel.Text;
                    obj.Description = textBoxDesc.Text;
                    if (radioButton1.Checked)
                    {
                        obj.Enable = true;
                    }
                    else
                    {
                        obj.Enable = false;
                    }
                    db.Entry(obj).State = EntityState.Modified;
                }
                db.SaveChanges();
                Singleton.SingletonPriority1.SetInstance();
                //Singleton.SingletonPriority1.Instance();

                dataGrid();
                //this.Dispose();
                //_Id = 0;
            }
        }
Exemple #19
0
 public frmMainReport(RCVPOEditForm rCVPOEditForm, string code)
 {
     InitializeComponent();
     this.rCVPOEditForm = rCVPOEditForm;
     this.code          = code;
     using (SSLsEntities db = new SSLsEntities())
     {
         var data = db.PORcv.SingleOrDefault(w => w.Enable == true && w.Code == code);
         data.PrintNumber     = data.PrintNumber + 1;
         db.Entry(data).State = EntityState.Modified;
         db.SaveChanges();
     }
     this.TypeReport = MyConstant.TypeReport.RCVPO;
 }
Exemple #20
0
 private void SaveSubmit()
 {
     // save pass
     using (SSLsEntities db = new SSLsEntities())
     {
         string id   = Singleton.SingletonAuthen.Instance().Id;
         var    user = db.Users.SingleOrDefault(w => w.Id == id);
         user.Password        = textBoxNewPass.Text.Trim();
         user.Description     = "แก้ไขรหัสผ่าน " + Library.ConvertDateToThaiDate(DateTime.Now, true);
         db.Entry(user).State = EntityState.Modified;
         db.SaveChanges();
     }
     Environment.Exit(0);
 }
        /// <summary>
        /// ลบสมาชิก ออกจากระบบ Disable ทั้ง HD Details
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        ///
        private void button3_Click(object sender, EventArgs e)
        {
            DialogResult dr = MessageBox.Show("คุณต้องการบันทึกข้อมูล ใช่หรือไม่ ?",
                                              "คำเตือนจากระบบ", MessageBoxButtons.YesNo);

            switch (dr)
            {
            case DialogResult.Yes:
                int index  = dataGridView1.CurrentRow.Index;
                int id     = int.Parse(dataGridView1.Rows[index].Cells[col1Id].Value.ToString());
                var member = Singleton.SingletonMember.Instance().Members.SingleOrDefault(w => w.Id == id);
                Singleton.SingletonMember.Instance().Members.Remove(member);
                using (SSLsEntities db = new SSLsEntities())
                {
                    var data = db.Member.SingleOrDefault(w => w.Id == id);
                    data.UpdateDate      = DateTime.Now;
                    data.UpdateBy        = SingletonAuthen.Instance().Id;
                    data.Enable          = false;
                    db.Entry(data).State = EntityState.Modified;

                    foreach (var item in data.MemberShare.Where(w => w.Enable == true))
                    {
                        item.UpdateDate      = DateTime.Now;
                        item.UpdateBy        = SingletonAuthen.Instance().Id;
                        item.Enable          = false;
                        db.Entry(item).State = EntityState.Modified;
                    }
                    db.SaveChanges();
                }
                reload();
                break;

            case DialogResult.No:
                break;
            }
        }
 private void Recount()
 {
     using (SSLsEntities db = new SSLsEntities())
     {
         string barcodescan       = textBoxScanner.Text.Trim();
         var    getProductDetails = Singleton.SingletonProduct.Instance().ProductDetails.FirstOrDefault(w => w.Enable == true && w.Code == barcodescan);
         var    checkFKPro        = db.CheckStockDetails.FirstOrDefault(w => w.Enable == true && w.FKProductDetails == getProductDetails.Id);
         checkFKPro.Enable          = false;
         checkFKPro.UpdateDate      = DateTime.Now;
         checkFKPro.UpdateBy        = _UserId;
         db.Entry(checkFKPro).State = EntityState.Modified;
         db.SaveChanges();
     }
     ResetNew();
 }
 /// <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();
     }
 }
        /// <summary>
        /// ยืนยันบันทึก disable ชุดเดิมทิ้งทั้งหมด
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button3_Click(object sender, EventArgs e)
        {
            List <int> ids = new List <int>();

            for (int i = 0; i < dataGridView2.Rows.Count; i++)
            {
                //Console.WriteLine();
                int id = int.Parse(dataGridView2.Rows[i].Cells[0].Value.ToString());
                ids.Add(id);
            }
            DialogResult dr = MessageBox.Show("คุณต้องการบันทึกข้อมูล ใช่หรือไม่ ?",
                                              "คำเตือนจากระบบ", MessageBoxButtons.YesNo);

            switch (dr)
            {
            case DialogResult.Yes:
                using (SSLsEntities db = new SSLsEntities())
                {
                    var menuAc = db.MenuAccess.Where(w => w.Enable == true && w.FKRole == _idRole);
                    foreach (var item in menuAc)
                    {
                        item.Enable          = false;
                        item.UpdateDate      = DateTime.Now;
                        item.UpdateBy        = Singleton.SingletonAuthen.Instance().Id;
                        db.Entry(item).State = EntityState.Modified;
                    }
                    // add new ids
                    foreach (var item in ids)
                    {
                        MenuAccess ac = new MenuAccess();
                        ac.CreateBy   = Singleton.SingletonAuthen.Instance().Id;
                        ac.CreateDate = DateTime.Now;
                        ac.FKRole     = _idRole;
                        ac.FKMenu     = item;
                        ac.UpdateDate = DateTime.Now;
                        ac.UpdateBy   = Singleton.SingletonAuthen.Instance().Id;
                        ac.Enable     = true;
                        db.MenuAccess.Add(ac);
                    }
                    db.SaveChanges();
                    ReloaGrid1();
                }
                break;

            case DialogResult.No:
                break;
            }
        }
        private void SaveCommit()
        {
            using (SSLsEntities db = new SSLsEntities())
            {
                string username = Singleton.SingletonAuthen.Instance().Id;
                var    data     = db.Users.SingleOrDefault(w => w.Id == username);

                data.UpdateBy        = Singleton.SingletonAuthen.Instance().Id;
                data.UpdateDate      = DateTime.Now;
                data.Name            = textBoxFullName.Text;
                data.Description     = textBoxDesc.Text;
                db.Entry(data).State = EntityState.Modified;
                db.SaveChanges();
                this.Dispose();
            }
        }
 private void CancelOrder(IEnumerable<string> stackDocNo)
 {
     using (SSLsEntities db = new SSLsEntities())
     {
         foreach (var item in stackDocNo)
         {
             var order = db.SaleOrderWarehouse.SingleOrDefault(w => w.Code == item);
             order.UpdateDate = DateTime.Now;
             order.UpdateBy = Singleton.SingletonAuthen.Instance().Id;
             order.Enable = false;
             order.FKSaleOrderWarehouseStatus = MyConstant.SaleOrderWarehouseStatus.CancelOrder;
             db.Entry(order).State = EntityState.Modified;
         }
         db.SaveChanges();
         LoadGrid();
     }
 }
        /// <summary>
        /// คำนวน Order ใหม่
        /// </summary>
        /// <param name="code"></param>
        private void Recal(string code)
        {
            using (SSLsEntities db = new SSLsEntities())
            {
                var data = db.SaleOrderWarehouse.SingleOrDefault(w => w.Code == code);
                decimal totalHasVat = 0; // ยอดสินค้ามีภาษี
                decimal totalUnVat = 0; // ยอดสินค้ายกเว้นภาษี
                decimal totalDisInList = 0;
                foreach (var item in data.SaleOrderWarehouseDtl.Where(w => w.Enable == true).ToList())
                {
                    if (item.QtyAllow < item.Qty)
                    {
                        // ได้ยอดไม่ตามเป้า
                        item.QtyOriginal = item.Qty;
                        item.Qty = item.QtyAllow;
                        // clear ส่วนลด
                        item.PercentDiscount = 0;
                        item.BathDiscount = 0;
                        item.TotalPrice = item.QtyAllow * item.PricePerUnit;
                        db.Entry(item).State = EntityState.Modified;

                    }
                    if (item.ProductDetails.Products.ProductVatType.Id == MyConstant.ProductVatType.HasVat)
                    {
                        totalHasVat += item.TotalPrice;
                    }
                    else
                    {
                        totalUnVat += item.TotalPrice;
                    }
                    totalDisInList += item.BathDiscount;

                }
                decimal total = totalHasVat + totalUnVat; // ยอดรวมก่อนหักลด
                decimal totalBalance = total - data.TotalDiscount;

                data.TotalVat = totalHasVat * MyConstant.MyVat.Vat / MyConstant.MyVat.VatRemove;
                data.TotaNoVat = totalUnVat;
                data.TotalBeforeVat = totalHasVat - data.TotalVat;
                data.Total = total;
                data.TotalDiscountInList = totalDisInList;
                data.TotalBalance = totalBalance;
                db.SaveChanges();
            }
        }
        /// <summary>
        /// save or edit
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button2_Click(object sender, EventArgs e)
        {
            using (SSLsEntities db = new SSLsEntities())
            {
                if (_Id == 0)
                {
                    // add new
                    ProductUnit obj = new ProductUnit();
                    obj.Code        = textBoxCode.Text;
                    obj.Name        = textBoxName.Text;
                    obj.Description = textBoxDesc.Text;
                    obj.CreateDate  = DateTime.Now;
                    obj.CreateBy    = Singleton.SingletonAuthen.Instance().Id;
                    obj.Enable      = true;
                    obj.UpdateBy    = Singleton.SingletonAuthen.Instance().Id;
                    obj.UpdateDate  = DateTime.Now;
                    db.ProductUnit.Add(obj);
                }
                else
                {
                    // edit
                    var unit = db.ProductUnit.SingleOrDefault(w => w.Id == _Id);
                    unit.UpdateDate  = DateTime.Now;
                    unit.UpdateBy    = Singleton.SingletonAuthen.Instance().Id;
                    unit.Code        = textBoxCode.Text;
                    unit.Name        = textBoxName.Text;
                    unit.Description = textBoxDesc.Text;
                    if (radioButton1.Checked)
                    {
                        unit.Enable = true;
                    }
                    else
                    {
                        unit.Enable = false;
                    }
                    db.Entry(unit).State = EntityState.Modified;
                }
                db.SaveChanges();
                Singleton.SingletonPUnit.SetInstance();

                dataGrid();
                //this.Dispose();
                //_Id = 0;
            }
        }
        /// <summary>
        /// บันทึก Role
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button2_Click(object sender, EventArgs e)
        {
            using (SSLsEntities db = new SSLsEntities())
            {
                if (_idRole == 0)
                {
                    // add new role
                    Role role = new Role();
                    role.Code        = textBoxCode.Text;
                    role.Name        = textBoxName.Text;
                    role.Description = textBoxDesc.Text;
                    role.CreateDate  = DateTime.Now;
                    role.CreateBy    = Singleton.SingletonAuthen.Instance().Id;
                    role.UpdateDate  = DateTime.Now;
                    role.UpdateBy    = Singleton.SingletonAuthen.Instance().Id;
                    role.Enable      = true;
                    db.Role.Add(role);
                }
                else
                {
                    // Update Role Value
                    Role role = new Role();
                    role                 = db.Role.SingleOrDefault(w => w.Id == _idRole);
                    role.Code            = textBoxCode.Text;
                    role.Name            = textBoxName.Text;
                    role.Description     = textBoxDesc.Text;
                    role.UpdateDate      = DateTime.Now;
                    role.UpdateBy        = Singleton.SingletonAuthen.Instance().Id;
                    db.Entry(role).State = EntityState.Modified;
                }
                DialogResult dr = MessageBox.Show("คุณต้องการบันทึกข้อมูล ใช่หรือไม่ ?",
                                                  "คำเตือนจากระบบ", MessageBoxButtons.YesNo);
                switch (dr)
                {
                case DialogResult.Yes:
                    db.SaveChanges();
                    ReloaGrid1();
                    break;

                case DialogResult.No:
                    break;
                }
            }
        }
Exemple #30
0
        private void button4_Click(object sender, EventArgs e)
        {
            using (SSLsEntities db = new SSLsEntities())
            {
                var obj          = db.Vendor.SingleOrDefault(w => w.Id == _Id);
                var vendorSingle = Singleton.SingletonVender.Instance().Vendors.SingleOrDefault(w => w.Id == _Id);
                Singleton.SingletonVender.Instance().Vendors.Remove(vendorSingle);
                obj.UpdateDate  = DateTime.Now;
                obj.UpdateBy    = Singleton.SingletonAuthen.Instance().Id;
                obj.Code        = textBoxCode.Text;
                obj.Name        = textBoxName.Text;
                obj.Address     = textBoxAddress.Text;
                obj.Tel         = textBoxTel.Text;
                obj.Fax         = textBoxFax.Text;
                obj.Description = textBoxDesc.Text;
                if (radioButton1.Checked)
                {
                    obj.Enable = true;
                }
                else
                {
                    obj.Enable = false;
                }
                if (radioButtonCostOnly.Checked == true)
                {
                    obj.FKPOCostType = MyConstant.POCostType.CostOnly;
                }
                else
                {
                    obj.FKPOCostType = MyConstant.POCostType.CostAndVat;
                }
                db.Entry(obj).State = EntityState.Modified;

                db.SaveChanges();

                string user = Singleton.SingletonAuthen.Instance().Id;
                var    v    = db.Vendor.Include("POCostType").OrderByDescending(w => w.UpdateDate).Where(w => w.UpdateBy == user).FirstOrDefault();
                Singleton.SingletonVender.Instance().Vendors.Add(v);

                dataGrid();
                //_Id = 0;
                Reload(textBoxSearchKey.Text.Trim());
            }
        }