private void SaveProductBarcode(EF6.ProductBatch oBatch, Guid productid, string barcode) { using (var ctx = new EF6.RT2020Entities()) { string sql = "ProductId = '" + productid.ToString() + "' AND Barcode = '" + barcode + "'"; var oBarcode = ctx.ProductBarcode.Where(x => x.ProductId == productid).FirstOrDefault(); if (oBarcode == null) { oBarcode = new EF6.ProductBarcode(); oBarcode.ProductBarcodeId = Guid.NewGuid(); oBarcode.ProductId = productid; oBarcode.Barcode = barcode; oBarcode.BarcodeType = "INTER"; oBarcode.PrimaryBarcode = true; oBarcode.DownloadToPOS = (oBatch.RETAILITEM == "F") ? false : true; oBarcode.DownloadToCounter = (oBatch.COUNTER_ITEM == "F") ? false : true; ctx.ProductBarcode.Add(oBarcode); ctx.SaveChanges(); } } }
/** * private int CreateProducts() * { * int iCount = 0; * ListView combinList = Combin(); * if (combinList.Items.Count > 0) * { * foreach (ListViewItem oItem in combinList.Items) * { * CreateProducts(oItem); * iCount++; * } * } * return iCount; * } * * private void CreateProducts(ListViewItem listItem) * { * if (IsValidEntries()) * { * string a1 = listItem.SubItems[1].Text; * string a2 = listItem.SubItems[2].Text; * string a3 = listItem.SubItems[3].Text; * * System.Guid a1Id = (Common.Utility.IsGUID(listItem.SubItems[4].Text)) ? new Guid(listItem.SubItems[4].Text) : System.Guid.Empty; * System.Guid a2Id = (Common.Utility.IsGUID(listItem.SubItems[5].Text)) ? new Guid(listItem.SubItems[5].Text) : System.Guid.Empty; * System.Guid a3Id = (Common.Utility.IsGUID(listItem.SubItems[6].Text)) ? new Guid(listItem.SubItems[6].Text) : System.Guid.Empty; * * string prodCode = txtStkCode.Text.Trim() + a1 + a2 + a3; * if (prodCode.Length <= 22) * { * StringBuilder sql = new StringBuilder(); * sql.Append(" STKCODE = '").Append(txtStkCode.Text.Trim()).Append("' "); * sql.Append(" AND APPENDIX1 = '").Append(a1.Trim()).Append("' "); * sql.Append(" AND APPENDIX2 = '").Append(a2.Trim()).Append("' "); * sql.Append(" AND APPENDIX3 = '").Append(a3.Trim()).Append("' "); * * var oProduct = RT2020.DAL.Product.LoadWhere(sql.ToString()); * if (oProduct == null) * { * oProduct = new RT2020.DAL.Product(); * * oProduct.STKCODE = txtStkCode.Text; * oProduct.APPENDIX1 = a1; * oProduct.APPENDIX2 = a2; * oProduct.APPENDIX3 = a3; * * if (cboItemStatus.Text == "HOLD") * { * oProduct.Status = Convert.ToInt32(EnumHelper.Status.Draft.ToString("d")); * } * else if (cboItemStatus.Text == "POST") * { * oProduct.Status = Convert.ToInt32(EnumHelper.Status.Active.ToString("d")); * } * * oProduct.CLASS1 = general.cboClass1.Text; * oProduct.CLASS2 = general.cboClass2.Text; * oProduct.CLASS3 = general.cboClass3.Text; * oProduct.CLASS4 = general.cboClass4.Text; * oProduct.CLASS5 = general.cboClass5.Text; * oProduct.CLASS6 = general.cboClass6.Text; * * oProduct.ProductName = general.txtProductName.Text; * oProduct.ProductName_Chs = general.txtProductNameChs.Text; * oProduct.ProductName_Cht = general.txtProductNameCht.Text; * oProduct.Remarks = general.txtRemarks.Text; * * oProduct.NormalDiscount = Convert.ToDecimal((general.txtRetailDiscount.Text == string.Empty) ? "0" : general.txtRetailDiscount.Text); * oProduct.UOM = general.txtUnit.Text; * oProduct.NatureId = new Guid(general.cboNature.SelectedValue.ToString()); * * oProduct.FixedPriceItem = false; * * // Download Packets * oProduct.DownloadToPOS = general.chkRetailItem.Checked; * oProduct.DownloadToCounter = general.chkCounterItem.Checked; * * oProduct.CreatedBy = ConfigHelper.CurrentUserId; * oProduct.CreatedOn = DateTime.Now; * oProduct.ModifiedBy = ConfigHelper.CurrentUserId; * oProduct.ModifiedOn = DateTime.Now; * * oProduct.Save(); * * SaveProductBarcode(oProduct.ProductId, prodCode); * * // Appendix / Class * System.Guid c1Id = (general.cboClass1.SelectedValue != null) ? new Guid(general.cboClass1.SelectedValue.ToString()) : System.Guid.Empty; * System.Guid c2Id = (general.cboClass2.SelectedValue != null) ? new Guid(general.cboClass2.SelectedValue.ToString()) : System.Guid.Empty; * System.Guid c3Id = (general.cboClass3.SelectedValue != null) ? new Guid(general.cboClass3.SelectedValue.ToString()) : System.Guid.Empty; * System.Guid c4Id = (general.cboClass4.SelectedValue != null) ? new Guid(general.cboClass4.SelectedValue.ToString()) : System.Guid.Empty; * System.Guid c5Id = (general.cboClass5.SelectedValue != null) ? new Guid(general.cboClass5.SelectedValue.ToString()) : System.Guid.Empty; * System.Guid c6Id = (general.cboClass6.SelectedValue != null) ? new Guid(general.cboClass6.SelectedValue.ToString()) : System.Guid.Empty; * SaveProductCode(oProduct.ProductId, a1Id, a2Id, a3Id, c1Id, c2Id, c3Id, c4Id, c5Id, c6Id); * * // Product Price * SaveProductSupplement(oProduct.ProductId); * SaveProductPrice(oProduct.ProductId); * * // Remarks * SaveProductRemarks(oProduct.ProductId); * * SaveCurrentSummary(oProduct.ProductId); * } * } * } * } * * private void SaveCurrentSummary(Guid productId) * { * string where = "ProductId = '" + productId.ToString() + "'"; * * using (var ctx = new EF6.RT2020Entities()) * { * var oCurrSummary = ctx.ProductCurrentSummary.Where(x => x.ProductId == productId).FirstOrDefault(); * if (oCurrSummary == null) * { * oCurrSummary = new EF6.ProductCurrentSummary(); * oCurrSummary.CurrentSummaryId = Guid.NewGuid(); * oCurrSummary.ProductId = productId; * oCurrSummary.CDQTY = 0; * oCurrSummary.LastPurchasedOn = new DateTime(1900, 1, 1); * oCurrSummary.LastSoldOn = new DateTime(1900, 1, 1); * * ctx.ProductCurrentSummary.Add(oCurrSummary); * ctx.SaveChanges(); * } * } * } * * private void SaveProductBarcode(Guid productid, string barcode) * { * using (var ctx = new EF6.RT2020Entities()) * { * //string sql = "ProductId = '" + productid.ToString() + "' AND Barcode = '" + barcode + "'"; * var oBarcode = ctx.ProductBarcode.Where(x => x.ProductId == productid && x.Barcode == barcode).FirstOrDefault(); * if (oBarcode == null) * { * oBarcode = new EF6.ProductBarcode(); * oBarcode.ProductBarcodeId = Guid.NewGuid(); * oBarcode.ProductId = productid; * oBarcode.Barcode = barcode; * oBarcode.BarcodeType = "INTER"; * oBarcode.PrimaryBarcode = true; * oBarcode.DownloadToPOS = general.chkRetailItem.Checked; * oBarcode.DownloadToCounter = general.chkCounterItem.Checked; * * ctx.ProductBarcode.Add(oBarcode); * ctx.SaveChanges(); * } * } * } * * private void SaveProductCode(Guid productId, Guid a1Id, Guid a2Id, Guid a3Id, Guid c1Id, Guid c2Id, Guid c3Id, Guid c4Id, Guid c5Id, Guid c6Id) * { * using (var ctx = new EF6.RT2020Entities()) * { * //string sql = "ProductId = '" + productId.ToString() + "'"; * var oCode = ctx.ProductCode.Where(x => x.ProductId == productId).FirstOrDefault(); * if (oCode == null) * { * oCode = new EF6.ProductCode(); * oCode.CodeId = Guid.NewGuid(); * oCode.ProductId = productId; * oCode.Appendix1Id = a1Id; * oCode.Appendix2Id = a2Id; * oCode.Appendix3Id = a3Id; * * ctx.ProductCode.Add(oCode); * } * oCode.Class1Id = c1Id; * oCode.Class2Id = c2Id; * oCode.Class3Id = c3Id; * oCode.Class4Id = c4Id; * oCode.Class5Id = c5Id; * oCode.Class6Id = c6Id; * * ctx.SaveChanges(); * } * } * * private void SaveProductSupplement(Guid productId) * { * using (var ctx = new EF6.RT2020Entities()) * { * string sql = "ProductId = '" + productId.ToString() + "'"; * var oProdSupp = ctx.ProductSupplement.Where(x => x.ProductId == productId).FirstOrDefault(); * if (oProdSupp == null) * { * oProdSupp = new EF6.ProductSupplement(); * oProdSupp.SupplementId = Guid.NewGuid(); * oProdSupp.ProductId = productId; * * ctx.ProductSupplement.Add(oProdSupp); * } * oProdSupp.VendorCurrencyCode = general.cboVendorCurrency.Text; * oProdSupp.VendorPrice = Convert.ToDecimal((general.txtVendorPrice.Text == string.Empty) ? "0" : general.txtVendorPrice.Text); * oProdSupp.ProductName_Memo = general.txtMemo.Text; * oProdSupp.ProductName_Pole = general.txtPole.Text; * * //oProdSupp.VipDiscount_FixedItem = Convert.ToDecimal((txtDiscount1_FixPriceItem.Text == string.Empty) ? "0" : txtDiscount1_FixPriceItem.Text); * //oProdSupp.VipDiscount_DiscountItem = Convert.ToDecimal((txtDiscount2_DiscountItem.Text == string.Empty) ? "0" : txtDiscount2_DiscountItem.Text); * //oProdSupp.VipDiscount_NoDiscountItem = Convert.ToDecimal((txtDiscount3_NoDiscountItem.Text == string.Empty) ? "0" : txtDiscount3_NoDiscountItem.Text); * //oProdSupp.StaffDiscount = Convert.ToDecimal((txtStaffDiscount.Text == string.Empty) ? "0" : txtStaffDiscount.Text); * * ctx.SaveChanges(); * } * } * * private void SaveProductPrice(Guid productId) * { * SaveProductPrice(productId, EnumHelper.ProductPriceType.BASPRC.ToString(), general.txtCurrentRetailCurrency.Text, general.txtCurrentRetailPrice.Text); * SaveProductPrice(productId, EnumHelper.ProductPriceType.ORIPRC.ToString(), general.txtOriginalRetailCurrency.Text, general.txtOriginalRetailPrice.Text); * SaveProductPrice(productId, EnumHelper.ProductPriceType.VPRC.ToString(), general.cboVendorCurrency.Text, general.txtVendorPrice.Text); * SaveProductPrice(productId, EnumHelper.ProductPriceType.WHLPRC.ToString(), general.txtWholesalesCurrency.Text, general.txtWholesalesPrice.Text); * } * * private void SaveProductPrice(Guid productId, string priceType, string currencyCode, string price) * { * using (var ctx = new EF6.RT2020Entities()) * { * var priceTypeId = ModelEx.ProductPriceTypeEx.GetIdByPriceType(priceType); * //string sql = "ProductId = '" + productId.ToString() + "' AND PriceTypeId = '" + GetPriceType(priceType).ToString() + "'"; * * var oPrice = ctx.ProductPrice.Where(x => x.ProductId == productId && x.PriceTypeId == priceTypeId).FirstOrDefault(); * if (oPrice == null) * { * oPrice = new EF6.ProductPrice(); * oPrice.ProductPriceId = Guid.NewGuid(); * oPrice.ProductId = productId; * * ctx.ProductPrice.Add(oPrice); * } * oPrice.PriceTypeId = priceTypeId; * oPrice.CurrencyCode = currencyCode; * oPrice.Price = Convert.ToDecimal((price == string.Empty) ? "0" : price); * * ctx.SaveChanges(); * } * } * * private void SaveProductRemarks(Guid productId) * { * using (var ctx = new EF6.RT2020Entities()) * { * //string sql = "ProductId = '" + productId.ToString() + "'"; * var oRemarks = ctx.ProductRemarks.Where(x => x.ProductId == productId).FirstOrDefault(); * if (oRemarks == null) * { * oRemarks = new EF6.ProductRemarks(); * oRemarks.ProductRemarksId = Guid.NewGuid(); * oRemarks.ProductId = productId; * * ctx.ProductRemarks.Add(oRemarks); * } * oRemarks.BinX = general.txtBin_X.Text; * oRemarks.BinY = general.txtBin_Y.Text; * oRemarks.BinZ = general.txtBin_Z.Text; * * oRemarks.DownloadToShop = general.chkRetailItem.Checked; * oRemarks.OffDisplayItem = general.chkOffDisplayItem.Checked; * oRemarks.DownloadToCounter = general.chkCounterItem.Checked; * * oRemarks.REMARK1 = general.txtRemarks1.Text; * oRemarks.REMARK2 = general.txtRemarks2.Text; * oRemarks.REMARK3 = general.txtRemarks3.Text; * oRemarks.REMARK4 = general.txtRemarks4.Text; * oRemarks.REMARK5 = general.txtRemarks5.Text; * oRemarks.REMARK6 = general.txtRemarks6.Text; * * ctx.SaveChanges(); * } * } */ #endregion #region Save Product Batch private void SaveProductBatch() { using (var ctx = new EF6.RT2020Entities()) { var oBatch = ctx.ProductBatch.Find(this.ProductBatchId); if (oBatch == null) { oBatch = new EF6.ProductBatch(); oBatch.BatchId = Guid.NewGuid(); ctx.ProductBatch.Add(oBatch); } oBatch.STKCODE = txtStkCode.Text; oBatch.APP1_COMBIN = cboAppendix1.Text; oBatch.APP2_COMBIN = cboAppendix2.Text; oBatch.APP3_COMBIN = cboAppendix3.Text; oBatch.CLASS1 = general.cboClass1.Text; oBatch.CLASS2 = general.cboClass2.Text; oBatch.CLASS3 = general.cboClass3.Text; oBatch.CLASS4 = general.cboClass4.Text; oBatch.CLASS5 = general.cboClass5.Text; oBatch.CLASS6 = general.cboClass6.Text; oBatch.Description = general.txtProductName.Text; oBatch.MAINUNIT = general.txtUnit.Text; oBatch.ALTITEM = string.Empty; oBatch.REMARKS = general.txtRemarks.Text; oBatch.MARKUP = 0; oBatch.BASPRC = (general.txtCurrentRetailPrice.Text.Length == 0) ? 0 : Convert.ToDecimal(general.txtCurrentRetailPrice.Text); oBatch.WHLPRC = (general.txtWholesalesPrice.Text.Length == 0) ? 0 : Convert.ToDecimal(general.txtWholesalesPrice.Text); oBatch.VCURR = general.cboVendorCurrency.Text; oBatch.VPRC = (general.txtVendorPrice.Text.Length == 0) ? 0 : Convert.ToDecimal(general.txtVendorPrice.Text); oBatch.NRDISC = 0; oBatch.REORDLVL = (order.txtReorderLevel.Text.Length == 0) ? 0 : Convert.ToDecimal(order.txtReorderLevel.Text); oBatch.REORDQTY = (order.txtReorderQuantity.Text.Length == 0) ? 0 : Convert.ToDecimal(order.txtReorderQuantity.Text); oBatch.SERIALFLAG = false; oBatch.NATURE = general.cboNature.Text; oBatch.REMARK1 = general.txtRemarks1.Text; oBatch.REMARK2 = general.txtRemarks2.Text; oBatch.REMARK3 = general.txtRemarks3.Text; oBatch.REMARK4 = general.txtRemarks4.Text; oBatch.REMARK5 = general.txtRemarks5.Text; oBatch.REMARK6 = general.txtRemarks6.Text; oBatch.PHOTO = misc.txtPicFileName.Text; oBatch.STK_MEMO = general.txtMemo.Text; oBatch.STATUS = cboItemStatus.Text; oBatch.DATEPOST = new DateTime(1900, 1, 1); oBatch.DATECREATE = DateTime.Now; oBatch.DATELCHG = DateTime.Now; oBatch.USERLCHG = StaffEx.GetStaffNumberById(ConfigHelper.CurrentUserId); oBatch.RETAILITEM = general.chkRetailItem.Checked.ToString(); oBatch.BINX = general.txtBin_X.Text; oBatch.BINY = general.txtBin_Y.Text; oBatch.BINZ = general.txtBin_Z.Text; oBatch.DESC_MEMO = general.txtMemo.Text; oBatch.DESC_POLE = general.txtPole.Text; oBatch.OFF_DISPLAY_ITEM = general.chkOffDisplayItem.Checked.ToString(); oBatch.COUNTER_ITEM = general.chkCounterItem.Checked.ToString(); oBatch.ORIPRC = (general.txtOriginalRetailPrice.Text.Length == 0) ? 0 : Convert.ToDecimal(general.txtOriginalRetailPrice.Text); ctx.SaveChanges(); this.ProductBatchId = oBatch.BatchId; } }