Esempio n. 1
0
        private void InitialDataPopup()
        {
            var cmdCat = new CategoryService();
            var list = cmdCat.GetALL();
            foreach (var item in list)
            {
                ddlCategory.Items.Add(new ListItem(item.CATEGORY_NAME, item.CATEGORY_ID.ToString()));
            }
            var cmdPro = new ProductService();
            var listddlPakUDesc = cmdPro.GetUDescPacking();
            foreach (var item in listddlPakUDesc)
            {
                ddlPakUDesc.Items.Add(new ListItem(item, item));
            }

            var listddlPakPDesc = cmdPro.GetPDescPacking();
            foreach (var item in listddlPakPDesc)
            {
                ddlPakPDesc.Items.Add(new ListItem(item, item));
            }

            var cmd = new ZoneService();
            var listZone = cmd.GetALL();
            DataSouceList = new List<PRODUCT_PRICELIST>();
            foreach (var item in listZone)
            {
                PRODUCT_PRICELIST pd = new PRODUCT_PRICELIST();
                pd.ZONE_ID = item.ZONE_ID;
                pd.ZONE = new ZONE();
                pd.ZONE.ZONE_CODE = item.ZONE_CODE;
                pd.ZONE.ZONE_NAME = item.ZONE_NAME;
                DataSouceList.Add(pd);
            }

            if (ViewState["proId"] != null)
            {
                _product = cmdPro.Select(Convert.ToInt32(ViewState["proId"].ToString()));
                popTxtProductCode.Text = _product.PRODUCT_CODE;
                poptxtProductName.Text = _product.PRODUCT_NAME;
                txtPacking.Text = _product.PRODUCT_PACKING_QTY.ToString();
                //txtPackingDesc.Text = _product.PRODUCT_PACKING_DESC;
                txtWeight.Text = _product.PRODUCT_WEIGHT.ToString();
                txtUnit.Text = _product.PRODUCT_WEIGHT_DEFINE;
                ddlCategory.SelectedValue = _product.CATEGORY_ID.ToString();
                ddlkind.SelectedValue = _product.PRODUCT_TYPE_CODE.ToString();
                //txtSize.Text = _product.PRODUCT_SIZE;
                ddlPakUDesc.SelectedValue = _product.PRODUCT_PACKING_PER_UDESC;
                ddlPakPDesc.SelectedValue = _product.PRODUCT_PACKING_PER_PDESC;
                var cmdPD = new ProductPriceListService();
                var listPD = cmdPD.Select(Convert.ToInt32(ViewState["proId"].ToString()));
                foreach (var itemPD in listPD)
                {
                    foreach (var itemDST in DataSouceList)
                    {
                        if (itemDST.ZONE_ID == itemPD.ZONE_ID)
                        {
                            itemDST.PRODUCT_PRICE = itemPD.PRODUCT_PRICE;
                            itemDST.PRODUCT_ID = itemPD.PRODUCT_ID;
                            break;
                        }
                    }
                }

                List<PRODUCT_PROMOTION> listPromotionItem = new List<PRODUCT_PROMOTION>();
                var cmdPromotion = new ProductPromotionService();
                DataSoucePromotion = cmdPromotion.GetALLIncludeZone(Convert.ToInt32(ViewState["proId"].ToString()));
                listPromotionItem.AddRange(DataSoucePromotion);

                listPromotionItem.AddRange(listPromotion);

                gridPromotion.DataSource = listPromotionItem;
                gridPromotion.DataBind();

                flag.Text = "Edit";
            }
            gridProductDetail.DataSource = DataSouceList;
            gridProductDetail.DataBind();
        }
Esempio n. 2
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            var obj = new PRODUCT();
            obj.PRODUCT_CODE = popTxtProductCode.Text;
            obj.PRODUCT_NAME = poptxtProductName.Text;
            obj.PRODUCT_PACKING_QTY = Convert.ToInt32(txtPacking.Text);

            if (ddlPakUDesc.SelectedValue != "กรุณาเลือก")
                obj.PRODUCT_PACKING_PER_UDESC = ddlPakUDesc.SelectedValue;

            if (ddlPakPDesc.SelectedValue != "กรุณาเลือก")
                obj.PRODUCT_PACKING_PER_PDESC = ddlPakPDesc.SelectedValue;

            obj.PRODUCT_PACKING_DESC = "(" + obj.PRODUCT_PACKING_QTY + " " + obj.PRODUCT_PACKING_PER_UDESC + "/" + obj.PRODUCT_PACKING_PER_PDESC + ")";
            obj.PRODUCT_WEIGHT = Convert.ToDecimal(txtWeight.Text);
            obj.PRODUCT_WEIGHT_DEFINE = txtUnit.Text;
            obj.CATEGORY_ID = Convert.ToInt32(ddlCategory.SelectedValue);
            obj.PRODUCT_TYPE_CODE = Convert.ToInt32(ddlkind.SelectedValue);

            var cmd = new ProductService(obj);

            if (flag.Text.Equals("Add"))
            {
                obj.Action = ActionEnum.Create;
                obj.CREATE_DATE = DateTime.Now;
                obj.CREATE_EMPLOYEE_ID = 0;
                obj.UPDATE_DATE = DateTime.Now;
                obj.UPDATE_EMPLOYEE_ID = 0;
                obj.SYE_DEL = true;
                cmd.Add();
            }
            else
            {
                obj.Action = ActionEnum.Update;
                obj.PRODUCT_ID = Convert.ToInt32(ViewState["proId"].ToString());
                obj.UPDATE_DATE = DateTime.Now;
                obj.UPDATE_EMPLOYEE_ID = 0;
                obj.SYE_DEL = true;
                cmd.Edit();
            }

            if (FileUpload1.HasFile)
            {
                Stream fs = FileUpload1.PostedFile.InputStream;
                if (!System.IO.Directory.Exists(HttpContext.Current.Server.MapPath("~") + "ImageProduct"))
                    System.IO.Directory.CreateDirectory(HttpContext.Current.Server.MapPath("~") + "ImageProduct");
                obj.PRODUCT_IMAGE_PATH = "~/ImageProduct/" + obj.PRODUCT_ID + "." + FileUpload1.FileName.Split('.').ToArray()[1];
                FileUpload1.PostedFile.SaveAs(HttpContext.Current.Server.MapPath("~") + "ImageProduct\\" + obj.PRODUCT_ID + "." + FileUpload1.FileName.Split('.').ToArray()[1]);
            }
            cmd = new ProductService(obj);
            cmd.Edit();

            var listDetail = new List<PRODUCT_PRICELIST>();
            int i = 0;
            foreach (var item in DataSouceList)
            {
                var objDetail = new PRODUCT_PRICELIST();
                objDetail.ZONE_ID = item.ZONE_ID;
                objDetail.PRODUCT_PRICE = Convert.ToDecimal(((TextBox)(gridProductDetail.Rows[i++].Cells[2].FindControl("txtPrice"))).Text);
                objDetail.SYE_DEL = true;
                objDetail.UPDATE_DATE = DateTime.Now;
                objDetail.UPDATE_EMPLOYEE_ID = 0;
                if (item.PRODUCT_ID == 0)
                {
                    objDetail.Action = ActionEnum.Create;
                    objDetail.PRODUCT_ID = obj.PRODUCT_ID;
                    objDetail.CREATE_DATE = DateTime.Now;
                    objDetail.CREATE_EMPLOYEE_ID = 0;
                }
                else
                {
                    objDetail.Action = ActionEnum.Update;
                    objDetail.PRODUCT_ID = item.PRODUCT_ID;
                }
                listDetail.Add(objDetail);
            }

            if (listPromotion.Count > 0)
            {
                foreach (PRODUCT_PROMOTION item in listPromotion)
                {
                    item.PRODUCT_ID = obj.PRODUCT_ID;
                }
                var cmdPromotion = new ProductPromotionService(listPromotion);
                cmdPromotion.AddList();
            }

            var cmdDetail = new ProductPriceListService(listDetail);
            cmdDetail.AddUpdateList();
            ViewState["proId"] = null;
            Response.Redirect("SearchProduct.aspx");
        }