/// <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(); } }
private void SaveCommit() { try { WarehouseToWaste wt = new WarehouseToWaste(); wt.Enable = true; wt.Description = textBoxRemark.Text; wt.CreateDate = DateTime.Now; wt.CreateBy = Singleton.SingletonAuthen.Instance().Id; wt.UpdateDate = DateTime.Now; wt.UpdateBy = Singleton.SingletonAuthen.Instance().Id; wt.DocNo = textBoxCode.Text; wt.FKWarehouse = _WarehouseId; if (_WasteReason == 0) { MessageBox.Show("กรุณาเลือกเหตุผล"); return; } wt.FKWasteReason = _WasteReason; List <WarehouseToWasteDetails> details = new List <WarehouseToWasteDetails>(); WarehouseToWasteDetails d; using (WH_TRATEntities whEN = new WH_TRATEntities()) { for (int i = 0; i < dataGridView1.Rows.Count; i++) { var code = dataGridView1.Rows[i].Cells[colCode].Value; if (code == null) { continue; } d = new WarehouseToWasteDetails(); d.Enable = true; d.Description = textBoxRemark.Text; d.CreateDate = DateTime.Now; d.CreateBy = Singleton.SingletonAuthen.Instance().Id; d.UpdateDate = DateTime.Now; d.UpdateBy = Singleton.SingletonAuthen.Instance().Id; d.FKProductDetails = int.Parse(dataGridView1.Rows[i].Cells[colId].Value.ToString()); d.QtyUnit = decimal.Parse(dataGridView1.Rows[i].Cells[colQty].Value.ToString()); d.Packsize = decimal.Parse(dataGridView1.Rows[i].Cells[colPZ].Value.ToString()); d.PricePerUnit = decimal.Parse(dataGridView1.Rows[i].Cells[colCostPerUnit].Value.ToString()); decimal qty = decimal.Parse(dataGridView1.Rows[i].Cells[colQty].Value.ToString()); decimal cost = decimal.Parse(dataGridView1.Rows[i].Cells[colCostPerUnit].Value.ToString()); decimal sum = qty * cost; Console.WriteLine(sum); int locId = int.Parse(dataGridView1.Rows[i].Cells[colLocation + 1].Value.ToString()); WH_LOCSTK locStk = whEN.WH_LOCSTK.FirstOrDefault(w => w.ROWID == locId); d.Location = locStk.LOCATION_NO; details.Add(d); locStk.UPDATE_DATE = DateTime.Now; locStk.QTY = locStk.QTY - ((float)qty * (float)locStk.PACK_SIZE); if (locStk.QTY <= 0) { // ลบ row ทิ้ง whEN.WH_LOCSTK.Remove(locStk); whEN.SaveChanges(); // check WH_LOCSTK เพื่อ set book flag master var locationList = whEN.WH_LOCSTK.Where(w => w.LOCATION_NO == locStk.LOCATION_NO && (w.QTY > 0 || w.BOOK_QTY > 0)).ToList(); if (locationList.Count() > 0) // ถ้าบ้านนี้ ยัง { // not set } else { // set book flag // ต้องไปอัพเดท location mast ให้ book flag = null //var locationMast = whEN.WH_LOCATION_MAST.SingleOrDefault(w => w.LOCATION_NO == locStk.LOCATION_NO); //locationMast.BOOK_FLAG = null; //whEN.Entry(locationMast).State = EntityState.Modified; //whEN.SaveChanges(); whEN.Database.ExecuteSqlCommand("UPDATE dbo.WH_LOCATION_MAST SET BOOK_FLAG = NULL WHERE LOCATION_NO = '" + locStk.LOCATION_NO + "'"); } } else { whEN.Entry(locStk).State = EntityState.Modified; whEN.SaveChanges(); } } } wt.WarehouseToWasteDetails = details; using (SSLsEntities db = new SSLsEntities()) { db.WarehouseToWaste.Add(wt); db.SaveChanges(); //reset form dataGridView1.Rows.Clear(); dataGridView1.Refresh(); int count = db.WarehouseToWaste.Where(w => w.CreateDate.Year == DateTime.Now.Year && w.CreateDate.Month == DateTime.Now.Month).Count() + 1; string code = MyConstant.PrefixForGenerateCode.WHToWaste + Singleton.SingletonThisBudgetYear.Instance().ThisYear.CodeYear + DateTime.Now.ToString("MM") + Library.GenerateCodeFormCount(count, 4); textBoxCode.Text = code; textBoxDate.Text = Library.ConvertDateToThaiDate(DateTime.Now); textBoxTotalBalance.Text = "0.00"; textBoxTotalQty.Text = "0.00"; // Update Stock Wms //Library.MakeValueForUpdateStockWms(details); // + ห้องของเสีย // Initisl waste warehouse ก่อน List <int> fkProDtl = details.Select(w => w.FKProductDetails).Distinct().ToList <int>(); List <int> fkPro = Singleton.SingletonProduct.Instance().ProductDetails.Where(w => fkProDtl.Contains(w.Id)).Select(w => w.FKProduct).Distinct().ToList <int>(); List <WasteWarehouse> wss = new List <WasteWarehouse>(); foreach (var item in fkPro) { var data = db.WasteWarehouse.FirstOrDefault(w => w.FKProduct == item && w.Enable == true); if (data == null) { WasteWarehouse ws = new WasteWarehouse(); ws.FKProduct = item; ws.FKWarehouse = MyConstant.WareHouse.WasteWarehouse; ws.QtyPiece = 0; ws.QtyUnit = 0; ws.Description = "Auto Detect"; ws.Enable = true; ws.CreateDate = DateTime.Now; ws.CreateBy = Singleton.SingletonAuthen.Instance().Id; ws.UpdateDate = DateTime.Now; ws.UpdateBy = Singleton.SingletonAuthen.Instance().Id; wss.Add(ws); } } db.WasteWarehouse.AddRange(wss); db.SaveChanges(); Library.AddWasteWarehouse(details, wt.DocNo); /// ต้องไปตัด stock ระบบจารกอต โดยใช้ บาร์โค้ด dataGridView1.Rows.Add(1); textBoxRemark.Text = ""; textBoxRemark.Select(); } } catch (Exception ex) { MessageBox.Show("พบข้อผิดพลาด " + ex.ToString()); } }
private void button2_Click(object sender, EventArgs e) { using (SSLsEntities db = new SSLsEntities()) { if (_Id == 0) { // add new Vendor obj = new Vendor(); obj.Code = textBoxCode.Text; obj.Name = textBoxName.Text; obj.Address = textBoxAddress.Text; obj.Tel = textBoxTel.Text; obj.Fax = textBoxFax.Text; obj.TaxNo = textBoxTax.Text.Trim(); 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; if (radioButtonCostOnly.Checked == true) { obj.FKPOCostType = MyConstant.POCostType.CostOnly; } else { obj.FKPOCostType = MyConstant.POCostType.CostAndVat; } db.Vendor.Add(obj); var vendorsOnSingleton = Singleton.SingletonVender.Instance().Vendors; if (vendorsOnSingleton.FirstOrDefault(w => w.Code == obj.Code) != null) // ถ้า code นี้ เคยมีแล้ว { MessageBox.Show("รหัสซ้ำบนระบบใหม่ (pos.Vendor) " + vendorsOnSingleton.FirstOrDefault(w => w.Code == obj.Code).Name); return; } // add to wh customer and brand using (WH_TRATEntities wh = new WH_TRATEntities()) { var getCust = wh.WH_CUSTOMER_MAST.FirstOrDefault(w => (w.CUSTOMER_NO + "") == obj.Code); if (getCust != null) // แปลว่าซ้ำยุ่ในระบบเก่า { MessageBox.Show("รหัสซ้ำบนระบบเก่า (dbo.WH_CUSTOMER_MAST) " + getCust.CUSTOMER_NAME); return; } // check in brand var getBrand = wh.WH_BRAND_MAST.FirstOrDefault(w => (w.BRAND_NO + "") == obj.Code); if (getBrand != null) // ซ้ำ ยี่ห้อในระบบเก่า { MessageBox.Show("รหัสซ้ำบนระบบเก่า (dbo.WH_BRAND_MAST) " + getBrand.BRAND_NAME); return; } // pass customer and brand to add 2 table WH_CUSTOMER_MAST customer = new WH_CUSTOMER_MAST(); customer.CUSTOMER_NO = int.Parse(obj.Code); customer.CUSTOMER_NAME = obj.Name; customer.CUSTOMER_BRANCH = "-"; customer.CUSTOMER_TAXID = obj.TaxNo; customer.CUSTOMER_ADDRESS = obj.Address; customer.CUSTOMER_PROVINCE = ""; customer.CUSTOMER_POSTNO = null; customer.CUSTOMER_PHONE = obj.Tel; customer.CUSTOMER_FAX = obj.Fax; customer.CUSTOMER_EMAIL = ""; customer.CREATE_DATE = DateTime.Now; customer.UPDATE_DATE = null; customer.USER_ID = obj.CreateBy; wh.WH_CUSTOMER_MAST.Add(customer); // brand WH_BRAND_MAST brand = new WH_BRAND_MAST(); brand.BRAND_NO = int.Parse(obj.Code); brand.BRAND_NAME = obj.Name; brand.CREATE_DATE = DateTime.Now; brand.UPDATE_DATE = null; brand.USER_ID = obj.CreateBy; wh.WH_BRAND_MAST.Add(brand); wh.SaveChanges(); } db.SaveChanges(); } else { // edit 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(); //this.Dispose(); //_Id = 0; } }
private void button2_Click(object sender, EventArgs e) { using (SSLsEntities db = new SSLsEntities()) { if (_Id == 0) { // add new ProductBrands obj = new ProductBrands(); 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.ProductBrands.Add(obj); //add to wh using (WH_TRATEntities wh = new WH_TRATEntities()) { var getBrand = wh.WH_BRAND_MAST.FirstOrDefault(w => (w.BRAND_NO + "") == obj.Code); if (getBrand == null) { // add now WH_BRAND_MAST brand = new WH_BRAND_MAST(); brand.BRAND_NAME = obj.Name; brand.BRAND_NO = int.Parse(obj.Code); brand.CREATE_DATE = DateTime.Now; brand.USER_ID = obj.UpdateBy; wh.WH_BRAND_MAST.Add(brand); wh.SaveChanges(); } else { // not add } } } else { // edit var obj = db.ProductBrands.SingleOrDefault(w => w.Id == _Id); obj.UpdateDate = DateTime.Now; obj.UpdateBy = Singleton.SingletonAuthen.Instance().Id; //obj.Code = textBoxCode.Text; obj.Name = textBoxName.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; } }