Esempio n. 1
0
 public List<ProductItem> Query(ProductItem query)
 {
     try
     {
         query.Replace4MySQL();
         StringBuilder strSql = new StringBuilder("select i.item_id,barcode,i.product_id,spec_id_1,spec_id_2,s1.spec_name as Spec_Name_1,s2.spec_name as Spec_Name_2,");
         //strSql.Append("i.item_cost,i.item_money,i.event_product_start,i.event_product_end,i.event_item_cost,i.event_item_money,");
         strSql.Append("i.item_cost,i.item_money,i.event_product_start,i.event_product_end,i.event_item_cost,i.event_item_money,");
         //add by zhuoqin0830w 2015/02/05 增加備註  // add by zhuoqin0830w 2014/03/20 增加運達天數
         strSql.Append("item_stock,item_alarm,item_status,item_code,erp_id,remark,arrive_days from product_item i left join product_spec s1 on i.spec_id_1 = s1.spec_id left join product_spec s2 on i.spec_id_2 = s2.spec_id  where 1=1");//edit by xiangwang0413w 2014/06/18 (增加ERP廠商編號erp_id)
         if (query.Item_Id != 0)
         {
             strSql.AppendFormat(" and i.item_id={0}", query.Item_Id);
         }
         if (query.Product_Id != 0)
         {
             strSql.AppendFormat(" and i.product_id={0}", query.Product_Id);
         }
         if (query.Spec_Id_1 != 0)
         {
             strSql.Append(" and spec_id_1=" + query.Spec_Id_1 + "");
         }
         if (query.Spec_Id_2 != 0)
         {
             strSql.Append(" and spec_id_2=" + query.Spec_Id_2 + "");
         }
         return _dbAccess.getDataTableForObj<ProductItem>(strSql.ToString());
     }
     catch (Exception ex)
     {
         throw new Exception("ProductItemDao.Query-->" + ex.Message, ex);
     }
 }
 //public DataTable GetType(string item_id)
 //{
 //    StringBuilder sql = new StringBuilder();
 //    sql.AppendLine(@"SELECT pi.item_id,ps.spec_name as  spec_name1,pss.spec_name as  spec_name2,p.product_mode,p.prepaid ");
 //    sql.AppendLine(@"from product_item pi LEFT JOIN product_spec ps ON ps.spec_id=pi.spec_id_1 LEFT JOIN product_spec pss ON  pss.spec_id=pi.spec_id_2");
 //    sql.AppendFormat(@"LEFT JOIN product p on  pi.product_id=p.product_id where pi.item_id='{0}'",item_id);
 //    try 
 //    {
 //        return _access.getDataTable(sql.ToString());
 //    }
 //     catch (Exception ex)
 //    {
 //        throw new Exception("ProductStockImportDao.GetType-->" + ex.Message + sql.ToString(), ex);
 //    }
 //}
 public int UpdateStock(ProductItem pi)
 {
     string sql = string.Empty;
     if (pi.Item_Id != 0)
     {
         sql = string.Format("update product_item set item_alarm='{0}',remark='{1}' ", pi.Item_Alarm,pi.Remark);
         //判斷是否更新庫存值
         if (pi.Item_Stock!=999999999)
         {
             sql += string.Format(",item_stock='{0}' ", pi.Item_Stock);
         }
         sql += string.Format(" where item_id='{0}'", pi.Item_Id);
         try
         {
             return _access.execCommand(sql);
         }
         catch (Exception ex)
         {
             throw new Exception("ProductStockImportDao.UpdateStock-->" + ex.Message + sql, ex);
         }
     }
     else
     {
         return 0;
     }
 }
Esempio n. 3
0
 //查詢吉甲地價格細項採用item_price裡面的價格 add by xiangwang0413w 2014/08/12
 public List<ProductItem> QueryPrice(ProductItem query)
 {
     try
     {
         query.Replace4MySQL();
         StringBuilder strSql = new StringBuilder("select  i.item_id,barcode,i.product_id,spec_id_1,spec_id_2,s1.spec_name as Spec_Name_1,s2.spec_name as Spec_Name_2,");
         //細項價格採用item_price裡面的價格
         strSql.Append(" ip.item_money,ip.item_cost,ip.event_money as event_item_money,ip.event_cost as event_item_cost,i.event_product_start,i.event_product_end,");
         strSql.Append("item_stock,item_alarm,item_status,item_code,erp_id from product_item i left join product_spec s1 on i.spec_id_1 = s1.spec_id left join product_spec s2 on i.spec_id_2 = s2.spec_id left join item_price ip on i.item_id=ip.item_id ");
         strSql.Append(" inner join price_master pm on ip.price_master_id=pm.price_master_id and pm.site_id=1 and pm.user_level=1 and user_id=0 where 1=1");
         if (query.Product_Id != 0)
         {
             strSql.AppendFormat(" and i.product_id={0}", query.Product_Id);
         }
         //添加 根據Item_id 查詢數據 的條件  add by zhuoqin0830w  2015/07/10
         if (query.Item_Id != 0)
         {
             strSql.AppendFormat(" and i.item_id={0}", query.Item_Id);
         }
         return _dbAccess.getDataTableForObj<ProductItem>(strSql.ToString());
     }
     catch (Exception ex)
     {
         throw new Exception("ProductItemDao.Query-->" + ex.Message, ex);
     }
 }
Esempio n. 4
0
        public DataOperation(List<Model.MigrationDataSet> mds, MainForm form)
        {
            this.mds = mds;
            this.connectionString = System.Configuration.ConfigurationSettings.AppSettings["MySqlConnectionString"];
            prod = new Product();
            pItem = new ProductItem();
            pM = new PriceMaster();
            iPrice = new ItemPrice();
            categorySet = new ProductCategorySet();
            pMap = new ProductMigrationMap();
            _prodMgr = new ProductMgr(this.connectionString);
            _priceMgr = new PriceMasterMgr(this.connectionString);
            _prodItemMgr = new ProductItemMgr(this.connectionString);
            _itemPriceMgr = new ItemPriceMgr(this.connectionString);
            _vendorBrandMgr = new VendorBrandMgr(this.connectionString);
            _vendorMgr = new VendorMgr(this.connectionString);
            _pMap = new ProductMigrationMgr(this.connectionString);
            _productCategorySetMgr = new ProductCategorySetMgr(this.connectionString);
            _productNoticeSetMgr = new ProductNoticeSetMgr(this.connectionString);
            _productTagSetMgr = new ProductTagSetMgr(this.connectionString);
            _productPictureMgr = new ProductPictureMgr(this.connectionString);
            _proStatusHistoryMgr = new ProductStatusHistoryMgr(connectionString);
            _proSpecMgr = new ProductSpecMgr(connectionString);
            _siteMgr = new SiteMgr(connectionString);
            this.form = form;

        }
 public int UpdateStock(ProductItem pi)
 {
     try
     {
         return _iPStockDao.UpdateStock(pi);
     }
     catch (Exception ex)
     {
         throw new Exception("ProductStockImportMgr.UpdateStock-->" + ex.Message, ex);
     }
 }
Esempio n. 6
0
        public HttpResponseBase StockSave()
        {
            ProductItemTemp piTemp = new ProductItemTemp();
            _productItemMgr = new ProductItemMgr(connectionString);
            ProductItem pItem = new ProductItem();
            string[] Value = Request.Params["ig_sh_InsertValue"].Split(',');

            string json = "{success:true}";

            _productItemTempMgr = new ProductItemTempMgr(connectionString);
            int writeId = (Session["caller"] as Caller).user_id;
            _tableHistoryMgr = new TableHistoryMgr(connectionString);

            List<ProductItemTemp> piTempList = new List<ProductItemTemp>();
            List<ProductItem> pItemList = new List<ProductItem>();

            //edit by wwei0216w 2015/6/11 修改原因:之前代碼在判斷時會做出誤判,因為spilt用(,)進行分割,導致字符串中本來是用(,)時,也被分割
            if (!string.IsNullOrEmpty(Request.Form["InsertValue"]))
            {
                List<ProductItem> list = JsonConvert.DeserializeObject<List<ProductItem>>(Request.Form["InsertValue"].ToString());
                foreach (var p_item in list)
                {
                    piTemp = new ProductItemTemp();
                    pItem = new ProductItem();
                    piTemp.Writer_Id = writeId;
                    if (!string.IsNullOrEmpty(p_item.Item_Id.ToString())) { piTemp.Item_Id = p_item.Item_Id; pItem.Item_Id = p_item.Item_Id; };
                    if (Request.Params["product_id"] != "")
                    {
                        pItem.Product_Id = uint.Parse(Request.Params["product_id"]);
                        pItem = _productItemMgr.Query(pItem)[0];
                    }
                    if (!string.IsNullOrEmpty(p_item.Spec_Id_1.ToString())) { piTemp.Spec_Id_1 = p_item.Spec_Id_1; pItem.Spec_Id_1 = p_item.Spec_Id_1; };
                    if (!string.IsNullOrEmpty(p_item.Spec_Id_2.ToString())) { piTemp.Spec_Id_2 = p_item.Spec_Id_2; pItem.Spec_Id_2 = p_item.Spec_Id_2; };
                    if (!string.IsNullOrEmpty(p_item.Item_Stock.ToString())) { piTemp.Item_Stock = p_item.Item_Stock; pItem.Item_Stock = p_item.Item_Stock; };
                    if (!string.IsNullOrEmpty(p_item.Item_Alarm.ToString())) { piTemp.Item_Alarm = p_item.Item_Alarm; pItem.Item_Alarm = p_item.Item_Alarm; };
                    if (!string.IsNullOrEmpty(p_item.Barcode.ToString())) { piTemp.Barcode = p_item.Barcode; pItem.Barcode = p_item.Barcode; };
                    if (!string.IsNullOrEmpty(p_item.Item_Code.ToString())) { piTemp.Item_Code = p_item.Item_Code; pItem.Item_Code = p_item.Item_Code; }
                    if (!string.IsNullOrEmpty(p_item.Erp_Id.ToString())) { piTemp.Erp_Id = p_item.Erp_Id; pItem.Erp_Id = p_item.Erp_Id; }
                    // add by zhuoqin0830w 2014/02/05 增加備註
                    if (!string.IsNullOrEmpty(p_item.Remark.ToString())) { piTemp.Remark = p_item.Remark; pItem.Remark = p_item.Remark; }
                    // add by zhuoqin0830w 2014/03/20 增加運達天數
                    if (!string.IsNullOrEmpty(p_item.Arrive_Days.ToString())) { piTemp.Arrive_Days = p_item.Arrive_Days; pItem.Arrive_Days = p_item.Arrive_Days; }
                    piTempList.Add(piTemp);
                    pItemList.Add(pItem);
                }

                //string[] Values = Request.Form["InsertValue"].ToString().Split(';');
                //for (int i = 0; i < Values.Length - 1; i++)
                //{
                //    piTemp = new ProductItemTemp();
                //    pItem = new ProductItem();
                //    piTemp.Writer_Id = writeId;
                //    string[] perValue = Values[i].Split(',');
                //    //查詢product_item數據
                //    if (!string.IsNullOrEmpty(perValue[5])) { piTemp.Item_Id = uint.Parse(perValue[5]); pItem.Item_Id = uint.Parse(perValue[5]); };
                //    if (Request.Params["product_id"] != "")
                //    {
                //        pItem.Product_Id = uint.Parse(Request.Params["product_id"]);
                //        pItem = _productItemMgr.Query(pItem)[0];
                //    }
                //    if (!string.IsNullOrEmpty(perValue[0])) { piTemp.Spec_Id_1 = uint.Parse(perValue[0]); pItem.Spec_Id_1 = uint.Parse(perValue[0]); };
                //    if (!string.IsNullOrEmpty(perValue[1])) { piTemp.Spec_Id_2 = uint.Parse(perValue[1]); pItem.Spec_Id_2 = uint.Parse(perValue[1]); };
                //    if (!string.IsNullOrEmpty(perValue[2])) { piTemp.Item_Stock = int.Parse(perValue[2]); pItem.Item_Stock = int.Parse(perValue[2]); };
                //    if (!string.IsNullOrEmpty(perValue[3])) { piTemp.Item_Alarm = uint.Parse(perValue[3]); pItem.Item_Alarm = uint.Parse(perValue[3]); };
                //    if (!string.IsNullOrEmpty(perValue[4])) { piTemp.Barcode = perValue[4]; pItem.Barcode = perValue[4]; };
                //    if (!string.IsNullOrEmpty(perValue[6])) { piTemp.Item_Code = perValue[6]; pItem.Item_Code = perValue[6]; }
                //    if (!string.IsNullOrEmpty(perValue[7])) { piTemp.Erp_Id = perValue[7]; pItem.Erp_Id = perValue[7]; }
                //    // add by zhuoqin0830w 2014/02/05 增加備註
                //    if (!string.IsNullOrEmpty(perValue[8])) { piTemp.Remark = perValue[8]; pItem.Remark = perValue[8]; }
                //    // add by zhuoqin0830w 2014/03/20 增加運達天數
                //    if (!string.IsNullOrEmpty(perValue[9])) { piTemp.Arrive_Days = int.Parse(perValue[9]); pItem.Arrive_Days = int.Parse(perValue[9]); }
                //    piTempList.Add(piTemp);
                //    pItemList.Add(pItem);
                //}
            }
            //判斷單一商品是新增還是修改
            if (!string.IsNullOrEmpty(Request.Params["product_id"]))
            {//修改單一商品時執行
                Product p = new Product();
                _functionMgr = new FunctionMgr(connectionString);
                string function = Request.Params["function"] ?? "";
                Function fun = _functionMgr.QueryFunction(function, "/Product/ProductSave");
                int functionid = fun == null ? 0 : fun.RowId;
                HistoryBatch batch = new HistoryBatch { functionid = functionid };
                batch.batchno = Request.Params["batch"] ?? "";
                batch.kuser = (Session["caller"] as Caller).user_email;
                //更新product
                _productMgr = new ProductMgr(connectionString);
                Product Query = new Product();
                //查詢product表。
                Query.Product_Id = uint.Parse(Request.Params["product_id"]);
                p = _productMgr.Query(Query)[0];
                p.Shortage = int.Parse(Value[1]);
                p.Ignore_Stock = int.Parse(Value[0]);
                p.outofstock_days_stopselling=int.Parse(Value[2]);
                json = "{success:true,msg:'" + Resources.Product.SAVE_SUCCESS + "'}";
                try
                {
                    foreach (var item in pItemList)
                    {
                        ArrayList arrList = new ArrayList();
                        arrList.Add(_productItemMgr.Update(item));
                        _tableHistoryMgr.SaveHistory<ProductItem>(item, batch, arrList);
                    }
                    ArrayList proList = new ArrayList();
                    proList.Add(_productMgr.Update(p));
                    _tableHistoryMgr.SaveHistory<Product>(p, batch, proList);
                    //若為單一商品,則把product_item.export_flag改為2 edit by xiangwang0413w 2014/06/30
                    //if (p.Combination == 1)
                    //{
                    //    _productItemMgr = new ProductItemMgr(connectionString);
                    //    ProductItem pro_Item = new ProductItem() { Product_Id = p.Product_Id, Export_flag = 2 };
                    //    _productItemMgr.UpdateExportFlag(pro_Item);
                    //}
                }
                catch (Exception ex)
                {
                    Log4NetCustom.LogMessage logMessage = new Log4NetCustom.LogMessage();
                    logMessage.Content = string.Format("TargetSite:{0},Source:{1},Message:{2}", ex.TargetSite.Name, ex.Source, ex.Message);
                    logMessage.MethodName = System.Reflection.MethodBase.GetCurrentMethod().Name;
                    log.Error(logMessage);
                    json = "{success:false,msg:'" + Resources.Product.SAVE_FAIL + "'}";
                }
            }
            else
            {//新增單一商品時
                try
                {
                    //更新product_temp
                    _productTempMgr = new ProductTempMgr(connectionString);
                    ProductTemp pTemp = new ProductTemp();

                    pTemp.Ignore_Stock = int.Parse(Value[0]);
                    pTemp.Shortage = int.Parse(Value[1]);
                    pTemp.outofstock_days_stopselling = int.Parse(Value[2]);
                    pTemp.Writer_Id = writeId;
                    pTemp.Combo_Type = COMBO_TYPE;
                    if (!string.IsNullOrEmpty(Request.Form["OldProductId"]))
                    {
                        pTemp.Product_Id = Request.Form["OldProductId"];
                    }

                    _productTempMgr.ProductTempUpdate(pTemp, "stock");

                    piTempList.ForEach(m => { m.Product_Id = pTemp.Product_Id; });


                    _productItemTempMgr.UpdateStockAlarm(piTempList);
                }
                catch (Exception ex)
                {
                    Log4NetCustom.LogMessage logMessage = new Log4NetCustom.LogMessage();
                    logMessage.Content = string.Format("TargetSite:{0},Source:{1},Message:{2}", ex.TargetSite.Name, ex.Source, ex.Message);
                    logMessage.MethodName = System.Reflection.MethodBase.GetCurrentMethod().Name;
                    log.Error(logMessage);
                    json = "{success:false,msg:'" + Resources.Product.SAVE_FAIL + "'}";
                }
            }

            this.Response.Clear();
            this.Response.Write(json);
            this.Response.End();
            return this.Response;
        }
Esempio n. 7
0
        /// <summary>
        /// 對表中的數據進行更新
        /// </summary>
        /// <returns></returns>
        public HttpResponseBase UpdateStock()
        {
            string json = string.Empty;
            ProductItem pi;
            try
            {
                // json = "{success:true,data:" + JsonConvert.SerializeObject(stores, Formatting.Indented) + "}";
                _pStockMgr = new ProductStockImportMgr(connectionString);
                // _pSpecStatusMgr = new ProductSpecMgr(connectionString);
                int i = 0;
                int j = 0;
                foreach (var item in productStockStores)
                {
                    pi = new ProductItem();
                    if (!string.IsNullOrEmpty(item.item_id))
                    {
                        pi.Item_Id = uint.Parse(item.item_id.Trim());
                    }
                    if (!string.IsNullOrEmpty(item.item_alarm))
                    {
                        pi.Item_Alarm = uint.Parse(item.item_alarm.Trim());
                    }
                    //非寄倉、非買斷商品更新庫存和警告值 +備註
                    if (item.type == 0)
                    {
                        if (!string.IsNullOrEmpty(item.item_stock))
                        {
                            pi.Item_Stock = int.Parse(item.item_stock.Trim());
                        }
                        if (!string.IsNullOrEmpty(item.remark))
                        {
                            pi.Remark = item.remark;
                        }
                        i += _pStockMgr.UpdateStock(pi);
                    }
                    //寄倉、買斷商品只更新警告值,+備註
                    else
                    {
                        pi.Item_Stock = 999999999;
                        if (!string.IsNullOrEmpty(item.remark))
                        {
                            pi.Remark = item.remark;
                        }
                        j += _pStockMgr.UpdateStock(pi);
                    }
                    //if (item.spec_status == "顯示")
                    //{
                    //    item.spec_status = "1";
                    //}
                    //else if (item.spec_status == "隱藏")
                    //{
                    //    item.spec_status = "0";
                    //}
                    //else
                    //{
                    //    item.spec_status = string.Empty;
                    //}
                    //if (item.spec_status2 == "顯示")
                    //{
                    //    item.spec_status2 = "1";
                    //}
                    //else if (item.spec_status2 == "隱藏")
                    //{
                    //    item.spec_status2 = "0";
                    //}
                    //else
                    //{
                    //    item.spec_status2 = string.Empty;
                    //}
                    //_pSpecStatusMgr.Updspecstatus(item);
                }
                json = "{success:true,msg:\"" + "匯入成功!<br/>非寄倉、非買斷商品更新" + i + "條,<br/>寄倉、買斷商品更新" + j + "條。\"}";
            }
            catch (Exception ex)
            {

                Log4NetCustom.LogMessage logMessage = new Log4NetCustom.LogMessage();
                logMessage.Content = string.Format("TargetSite:{0},Source:{1},Message:{2}", ex.TargetSite.Name, ex.Source, ex.Message);
                logMessage.MethodName = System.Reflection.MethodBase.GetCurrentMethod().Name;
                log.Error(logMessage);
                json = "{success:false,msg:\"" + "匯入失敗!" + "\"}";
            }
            this.Response.Clear();
            this.Response.Write(json);
            this.Response.End();
            return this.Response;
        }
Esempio n. 8
0
        public int RFKT(AseldQuery ase, IinvdQuery ivd,int pnum)
        {
            string json = string.Empty;
            int result = 0;
            IialgQuery q = new IialgQuery();
            uint id = 0; DateTime dt = new DateTime(); int sun = 0;
            _proditemMgr = new ProductItemMgr(mySqlConnectionString);
            ProductItem Proitems = new ProductItem();

            try
            {
                {//商品id
                    q.item_id = ase.item_id;
                    Proitems.Item_Id = ase.item_id;
                }
                // (DateTime.TryParse(Request.Params["made_date"].ToString(), out dt))
                {//商品製造日期
                    //q.made_dt = ivd.made_date;
                    q.made_dt = new DateTime(3000,1,1);
                }
                //if (int.TryParse(Request.Params["prod_qty"].ToString(), out sun))
                {//商品原有數量
                    q.qty_o = ivd.prod_qty;
                }
                //if (int.TryParse(Request.Params["pnum"].ToString(), out sun))
                {//商品撿貨數量
                    q.pnum = pnum;
                }
                //if (!string.IsNullOrEmpty(Request.Params["loc_id"].ToString()))
                {//商品撿貨數量
                    q.loc_id = ase.sel_loc;
                }
                //if (!string.IsNullOrEmpty(Request.Params["order_id"]))
                {
                    q.order_id = ase.ord_id.ToString();
                }
                q.create_user = (System.Web.HttpContext.Current.Session["caller"] as Caller).user_id;
                //進行庫調
                _iagDao = new IialgDao(mySqlConnectionString);
                Caller call = new Caller();
                call = (System.Web.HttpContext.Current.Session["caller"] as Caller);
                string path = "/WareHouse/KutiaoAddorReduce";
                //if (q.loc_id == "YY999999") 無主料位時也進行庫調
                if (false)
                {
                    json = "{success:false}";
                }
                else
                {
                    Proitems.Item_Stock = q.pnum - q.qty_o;
                    result = _iagDao.addIialgIstock_AutoMarket(q);
                    if (result == 2)
                    {
                        json = "{success:true,msg:2}";
                    }
                    if (result == 100)
                    {
                        //_proditemMgr.UpdateItemStock(Proitems, path, call);
                        json = "{success:true,msg:100}";
                    }
                }
            }
            catch (Exception ex)
            {
                throw new Exception("MarketTallyMgr-->RFKT-->" + ex.Message, ex);
            }
            return result;
        }
Esempio n. 9
0
        public ProductItem GetStockHistorySql(IpodQuery query, out string Stock)
        {
            StringBuilder sqlStock = new StringBuilder();
            Stock = string.Empty;
            try
            {
                sqlStock.AppendFormat("update product_item pi,ipod set pi.item_stock='{0}' where pi.item_id=ipod.prod_id and ipod.row_id='{1}' ;", query.item_stock, query.row_id);
                //_access.execCommand(sqlStock.ToString());
                Stock = sqlStock.ToString();
                sqlStock.Clear();
                sqlStock.AppendFormat(@"SELECT pi.* FROM ipod i LEFT JOIN product_item pi ON pi.item_id = i.prod_id where i.row_id='{0}';", query.row_id);
                
                ProductItem productitem = new ProductItem();
                productitem = _access.getSinggleObj<ProductItem>(sqlStock.ToString());

                return productitem;
            }
            catch (Exception ex)
            {
                throw new Exception("IpodDao-->GetStockHistorySql-->" + ex.Message + sqlStock.ToString(), ex);
            }
        }
Esempio n. 10
0
 public List<ProductItem> QueryPrice(ProductItem query)
 {
     return _productItemDao.QueryPrice(query);
 }
Esempio n. 11
0
        public int UpdateItemStock(ProductItem query,string path,BLL.gigade.Model.Caller user) 
        {
            Boolean result = false;
            try
            {
                ArrayList aList = new ArrayList();
                ITableHistoryImplMgr _tableHistoryMgr = new TableHistoryMgr(connectionStr);//實例化歷史記錄的類

                Int64 n_Time = BLL.gigade.Common.CommonFunction.GetPHPTime();
                Function myFun = new Function();
                myFun.FunctionCode = path;
                List<Function> funList = _functionMgr.Query(myFun);
                int functionid = funList.Count == 0 ? 0 : funList[0].RowId;
                HistoryBatch batch = new HistoryBatch { functionid = functionid };
                batch.kuser = user.user_email;

                //獲取歷史記錄SQL
                string Check = productItemDao.UpdateItemStock(query);

                //獲取修改庫存SQL  
               
                ProductItem item = new ProductItem();
                item = productItemDao.Query(query).Count > 0 ? productItemDao.Query(query)[0] : item;

                batch.batchno = n_Time + "_" + user.user_id + "_" + item.Product_Id;
                if (item != null)
                {
                    item.Item_Stock =  item.Item_Stock +query.Item_Stock;
                    
                    aList.Add(Check);
                    result = _tableHistoryMgr.SaveHistory<ProductItem>(item, batch, aList);
                }

                ////獲取修改商品Ignore SQL  
                //string Ignore_Stock = string.Empty;
                //Product product = new Product();
                //product = productItemDao.GetTaxByItem(query.Item_Id);
                //if (product != null)
                //{
                //    product.Ignore_Stock = 0;
                //    aList.Clear();
                //    aList.Add(Ignore_Stock);
                //    result = _tableHistoryMgr.SaveHistory<Product>(product, batch, aList);
                //}

                return 1;
            }
            catch (Exception ex)
            {
                throw new Exception("ProductItemMgr-->UpdateItemStock" + ex.Message, ex);
            }
        }
Esempio n. 12
0
 public ProductItemCustom GetProductArriveDay(ProductItem pi,string type)
 {
     try
     {
         return productItemDao.GetProductArriveDay(pi, type);
     }
     catch (Exception ex)
     {
         throw new Exception("ProductItemMgr-->GetProductArriveDay" + ex.Message, ex);
     }
 }
Esempio n. 13
0
 public string UpdateCopySpecId(ProductItem proItem)
 {
     return _productItemDao.UpdateCopySpecId(proItem);
 }
Esempio n. 14
0
 public string Delete(ProductItem delModel)
 {
     return _productItemDao.Delete(delModel);
 }
Esempio n. 15
0
        //查詢單一商品庫存
        public string QueryStock(ProductItem pItem)
        {
            try
            {
                StringBuilder stb = new StringBuilder();
                List<Model.ProductItem> result = _productItemDao.Query(pItem);
                int defaultArriveDays = new ProductMgr(connectionStr).GetDefaultArriveDays(new Product { Product_Id=pItem.Product_Id });

                if (result.Count == 0)
                {
                    return "{success:true,items:[]}";
                }
                else
                {
                    stb.Append("{success:true,items:[");
                    foreach (var item in result)
                    {
                        //ediy by wwei0216w 分開顯示Arrive_Days + defaultArriveDays 所以不需要計算和 2015/10/12
                        //item.Arrive_Days += defaultArriveDays;
                        stb.Append("{");
                        stb.AppendFormat("\"spec_title_1\":\"{0}\",\"spec_title_2\":\"{1}\",\"item_stock\":\"{2}\",\"item_alarm\":\"{3}\",\"barcode\":\"{4}\",\"spec_id_1\":\"{5}\",\"spec_id_2\":\"{6}\",\"item_id\":\"{7}\",\"item_code\":\"{8}\",\"erp_id\":\"{9}\",\"remark\":\"{10}\",\"arrive_days\":\"{11}\",\"default_arrive_days\":\"{12}\"", item.Spec_Name_1, item.Spec_Name_2, item.Item_Stock, item.Item_Alarm, item.Barcode, item.Spec_Id_1, item.Spec_Id_2, item.Item_Id, item.Item_Code, item.Erp_Id, item.Remark, item.Arrive_Days, defaultArriveDays);//edit by xiangwang0413w 2014/06/18 (增加ERP廠商編號erp_id)  // add by zhuoqin0830w 2014/02/05 增加備註  //add by zhuoqin0830w 2014/03/20 增加運達天數
                        stb.Append("}");
                    }
                    stb.Append("]}");
                    return stb.ToString().Replace("}{", "},{");
                }
            }
            catch (Exception ex)
            {
                throw new Exception("ProductItemMgr.QueryStock-->" + ex.Message, ex);
            }
        }
Esempio n. 16
0
 public string Delete(ProductItem delModel)
 {
     return string.Format("delete from product_item where product_id = {0}", delModel.Product_Id);
 }
Esempio n. 17
0
 public string UpdateCopySpecId(ProductItem proItem)
 {
     StringBuilder strSql = new StringBuilder("set sql_safe_updates = 0;update product_item set spec_id_1={0} where product_id = {1}");
     strSql.AppendFormat("  and spec_id_1={0};", proItem.Spec_Id_1);
     strSql.Append(" update product_item set spec_id_2={0} where product_id = {1}");
     strSql.AppendFormat(" and spec_id_2={0}", proItem.Spec_Id_2);
     strSql.Append(";set sql_safe_updates = 1; ");
     return strSql.ToString();
 }
Esempio n. 18
0
        public HttpResponseBase InsertIinvd()
        {
            string jsonStr = String.Empty;
            Int64 aaa = 0;  //無用變數
            uint p = 0;  //無用變數
            try
            {
                Iinvd m = new Iinvd();
                IialgQuery ia = new IialgQuery();
                Iupc iu = new Iupc();
                ProductItem proitem = new ProductItem();
                Caller call = new Caller();
                IstockChangeQuery stock = new IstockChangeQuery();
                call = (System.Web.HttpContext.Current.Session["caller"] as Caller);
                string path = "";
                _iinvd = new IinvdMgr(mySqlConnectionString);
                _iagMgr = new IialgMgr(mySqlConnectionString);
                _IiupcMgr = new IupcMgr(mySqlConnectionString);
                #region 獲取數據往
                if (Int64.TryParse(Request.Params["item_id"].ToString(), out aaa))
                {
                    if (uint.TryParse(Request.Params["item_id"].ToString(), out p))
                    {
                        m.item_id = uint.Parse(Request.Params["item_id"].ToString());
                    }
                    if (Request.Params["item_id"].ToString().Length > 6)
                    {
                        m.item_id = uint.Parse(_iinvd.Getprodubybar(Request.Params["item_id"].ToString()).Rows[0]["item_id"].ToString());
                    }
                }
                else
                {
                    if (Request.Params["item_id"].ToString().Length > 6)
                    {
                        m.item_id = uint.Parse(_iinvd.Getprodubybar(Request.Params["item_id"].ToString()).Rows[0]["item_id"].ToString());
                    }
                }

                m.dc_id = 1;
                m.whse_id = 1;
                m.prod_qty = Int32.Parse(Request.Params["prod_qty"].ToString());//數量
                DateTime today = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd"));
                DateTime dtime;
                if (DateTime.TryParse(Request.Params["startTime"].ToString(), out dtime))
                {//用戶填寫創建時間算出有效日期
                    DateTime start = DateTime.Parse(Request.Params["startTime"].ToString());
                    m.made_date = start;
                    if (uint.TryParse(Request.Params["cde_dt_incr"].ToString(), out p))
                    {
                        m.cde_dt = start.AddDays(Int32.Parse(Request.Params["cde_dt_incr"].ToString()));
                    }
                    else
                    {
                        m.cde_dt = DateTime.Now;
                    }
                }
                else
                {
                    if (DateTime.TryParse(Request.Params["cde_dt"].ToString(), out dtime))
                    {//用戶填寫有效日期算出製造日期
                        m.cde_dt = DateTime.Parse(Request.Params["cde_dt"].ToString());//有效時間 
                        if (uint.TryParse(Request.Params["cde_dt_incr"].ToString(), out p))
                        {
                            m.made_date = m.cde_dt.AddDays(-Int32.Parse(Request.Params["cde_dt_incr"].ToString()));
                        }
                        else
                        {
                            m.made_date = today;
                        }
                    }
                    else
                    {
                        m.cde_dt = today;
                        m.made_date = today;
                    }
                }
                m.cde_dt = DateTime.Parse(m.cde_dt.ToShortDateString());
                m.made_date = DateTime.Parse(m.made_date.ToShortDateString());
                m.plas_loc_id = Request.Params["plas_loc_id"].ToString().ToUpper();//上架料位
                string loc_id = Request.Params["loc_id"].ToString().ToUpper();
                m.change_dtim = DateTime.Now;//編輯時間
                m.receipt_dtim = DateTime.Now;//收貨時間
                m.create_user = (Session["caller"] as Caller).user_id;
                #endregion
                #region 獲取數據添加打iialg
                ia.loc_id = m.plas_loc_id.ToString().ToUpper();
                ia.item_id = m.item_id;
                stock.sc_trans_type = 0;
                if (!string.IsNullOrEmpty(Request.Params["iarc_id"].ToString()))
                {
                    ia.iarc_id = Request.Params["iarc_id"].ToString();
                }
                else
                {
                    ia.iarc_id = "PC";
                    stock.sc_trans_type = 1;//收貨上架
                }
                //if (ia.iarc_id == "DR" || ia.iarc_id == "KR")
                //{
                //    type = 2;//RF理貨
                //}

                ia.create_dtim = DateTime.Now;
                ia.create_user = m.create_user;
                ia.doc_no = "P" + DateTime.Now.ToString("yyyyMMddHHmmss");
                if (!string.IsNullOrEmpty(Request.Params["doc_num"]))
                {
                    ia.doc_no = Request.Params["doc_num"];
                    stock.sc_trans_id = ia.doc_no;//交易單號
                }
                if (!string.IsNullOrEmpty(Request.Params["Po_num"]))
                {
                    ia.po_id = Request.Params["Po_num"];
                    stock.sc_cd_id = ia.po_id;//前置單號
                }
                if (!string.IsNullOrEmpty(Request.Params["remark"]))
                {
                    ia.remarks = Request.Params["remark"];
                    stock.sc_note = ia.remarks;//備註 
                }
                ia.made_dt = m.made_date;
                ia.cde_dt = m.cde_dt;
                #endregion

                #region 獲取店內條碼-=添加條碼

                if (!string.IsNullOrEmpty(Request.Params["vendor_id"].ToString()))
                {
                    iu.upc_id = CommonFunction.GetUpc(m.item_id.ToString(), Request.Params["vendor_id"].ToString(), m.cde_dt.ToString("yyMMdd"));
                }
                iu.item_id = m.item_id;
                iu.upc_type_flg = "2";//店內碼
                iu.create_user = m.create_user;
                string result = _IiupcMgr.IsExist(iu);//是否有重複的條碼
                if (result == "0")
                {
                    if (_IiupcMgr.Insert(iu) < 1)
                    {
                        jsonStr = "{success:true,msg:2}";
                    }
                }
                #endregion

                #region 新增/編輯
                #region 庫存調整的時候,商品庫存也要調整
                _proditemMgr = new ProductItemMgr(mySqlConnectionString);
                int item_stock = m.prod_qty;
                proitem.Item_Stock = item_stock;
                proitem.Item_Id = m.item_id;
                #endregion
                if (_iinvd.IsUpd(m, stock) > 0)
                {//編輯             
                    ia.qty_o = _iinvd.Selnum(m);
                    ia.adj_qty = m.prod_qty;

                    m.prod_qty = ia.qty_o + m.prod_qty;
                    if (m.prod_qty >= 0)
                    {
                        if (_iinvd.Upd(m) > 0)
                        {
                            if (Request.Params["iialg"].ToString() == "Y")
                            {// 
                                if (ia.iarc_id != "PC" && ia.iarc_id != "NE")//------------庫存調整的時候商品庫存也更改,收貨上架的時候不更改,RF理貨的時候也是不更改
                                {
                                    path = "/WareHouse/KutiaoAddorReduce";
                                    _proditemMgr.UpdateItemStock(proitem, path, call);
                                }
                                if (_iagMgr.insertiialg(ia) > 0)
                                {
                                    jsonStr = "{success:true,msg:0}";//更新成功
                                }
                                else
                                {
                                    jsonStr = "{success:false,msg:1}";//更新失敗
                                }
                            }
                            else
                            {
                                jsonStr = "{success:true,msg:0}";//更新成功
                            }
                        }
                        else
                        {
                            jsonStr = "{success:false,msg:1}";//更新失敗
                        }
                    }
                    else
                    {
                        jsonStr = "{success:false,msg:1}";//庫存為負數
                    }
                }
                else
                {//新增
                    m.ista_id = "A";
                    m.create_dtim = DateTime.Now;       //創建時間
                    if (_iinvd.Insert(m) > 0)
                    {
                        _IlocMgr = new IlocMgr(mySqlConnectionString);
                        Iloc loc = new BLL.gigade.Model.Iloc();
                        loc.change_user = int.Parse((System.Web.HttpContext.Current.Session["caller"] as Caller).user_id.ToString());
                        loc.change_dtim = DateTime.Now;
                        loc.loc_id = m.plas_loc_id.ToString().ToUpper();
                        if (loc_id.Trim() != m.plas_loc_id.Trim())//判斷如果是主料位不需要進行多餘的操作
                        {
                            if (_IlocMgr.SetIlocUsed(loc) > 0)
                            {
                                if (Request.Params["iialg"].ToString() == "Y")
                                {
                                    if (ia.iarc_id != "PC" && ia.iarc_id != "NE")//------------庫存調整的時候商品庫存也更改,收貨上架的時候不更改,RF理貨的時候也是不更改
                                    {
                                        path = "/WareHouse/KutiaoAddorReduce";
                                        _proditemMgr.UpdateItemStock(proitem, path, call);
                                    }
                                    ia.qty_o = 0;
                                    ia.adj_qty = m.prod_qty;
                                    if (_iagMgr.insertiialg(ia) > 0)
                                    {
                                        jsonStr = "{success:true,msg:0}";//更新成功
                                    }
                                    else
                                    {
                                        jsonStr = "{success:false,msg:1}";//更新失敗
                                    }
                                }
                                else
                                {
                                    jsonStr = "{success:true,msg:0}";//新增成功
                                }
                            }
                            else
                            {
                                jsonStr = "{success:false,msg:1}";//新增失敗
                            }
                        }
                        else
                        {
                            if (Request.Params["iialg"].ToString() == "Y")
                            {
                                if (ia.iarc_id != "PC" && ia.iarc_id != "NE")//------------庫存調整的時候商品庫存也更改,收貨上架的時候不更改,RF理貨的時候也是不更改
                                {
                                    path = "/WareHouse/KutiaoAddorReduce";
                                    _proditemMgr.UpdateItemStock(proitem, path, call);
                                }
                                ia.qty_o = 0;
                                ia.adj_qty = m.prod_qty;
                                if (_iagMgr.insertiialg(ia) > 0)
                                {
                                    jsonStr = "{success:true,msg:0}";//更新成功
                                }
                                else
                                {
                                    jsonStr = "{success:false,msg:1}";//更新失敗
                                }
                            }
                            else
                            {
                                jsonStr = "{success:true,msg:0}";//新增成功
                            }
                        }
                    }
                    else
                    {
                        jsonStr = "{success:false,msg:1}";
                    }
                }
                #endregion
            }
            catch (Exception ex)
            {
                Log4NetCustom.LogMessage logMessage = new Log4NetCustom.LogMessage();
                logMessage.Content = string.Format("TargetSite:{0},Source:{1},Message:{2}", ex.TargetSite.Name, ex.Source, ex.Message);
                logMessage.MethodName = System.Reflection.MethodBase.GetCurrentMethod().Name;
                log.Error(logMessage);
                jsonStr = "{success:false}";
            }
            this.Response.Clear();
            this.Response.Write(jsonStr.ToString());
            this.Response.End();
            return this.Response;
        }
Esempio n. 19
0
 ///查詢和運達天數相關的信息
 public ProductItemCustom GetProductArriveDay(ProductItem pi, string type)
 {
     StringBuilder sb = new StringBuilder();
     try
     {
         sb.Append(@"SELECT pi.arrive_days,p.deliver_days,item_stock,pi.product_id
                         FROM product_item pi
                             INNER JOIN product p ON p.product_id =  pi.product_id 
                     WHERE 1 = 1 ");
         if (type == "item")
         {
             sb.AppendFormat("AND pi.item_id = {0}", pi.Item_Id);
         }
         else if (type == "product")
         {
             sb.AppendFormat("AND p.product_id = {0}", pi.Product_Id);
         }
         return _dbAccess.getSinggleObj<ProductItemCustom>(sb.ToString());
     }
     catch (Exception ex)
     {
         throw new Exception("ProductItemDao-->GetProductArriveDay" + ex.Message, ex);
     }
 }
Esempio n. 20
0
        // 更新表Iinvd庫存鎖的狀態
        public JsonResult UpdateIinvdActive()
        {
            string jsonStr = string.Empty;
            try
            {
                _iinvd = new IinvdMgr(mySqlConnectionString);
                Iinvd nvd = new Iinvd();
                IialgQuery q = new IialgQuery();
                _iagMgr = new IialgMgr(mySqlConnectionString);

                int id = Convert.ToInt32(Request.Params["id"]);
                string active = Request.Params["active"];
                string lock_id = Request.Params["lock_id"];
                if (!string.IsNullOrEmpty(Request.Params["po_id"].ToString()))
                {
                    q.po_id = Request.Params["po_id"].ToString();
                }
                if (!string.IsNullOrEmpty(Request.Params["remarks"].ToString()))
                {
                    q.remarks = Request.Params["remarks"].ToString();
                }
                if (active == "H")
                {
                    nvd.ista_id = "A";
                    nvd.qity_id = 0;
                }
                else if (active == "A")
                {
                    nvd.qity_id = Convert.ToInt32(lock_id);
                    nvd.ista_id = "H";
                }
                nvd.row_id = id;
                nvd.change_user = int.Parse((System.Web.HttpContext.Current.Session["caller"] as Caller).user_id.ToString());
                nvd.change_dtim = DateTime.Now;
                if (_iinvd.UpdateIinvdLock(nvd, q) > 0)
                {
                    //加鎖成功往iialg插入一條數據;解鎖不需要記錄
                    if (active == "A")
                    {
                        Iinvd store = _iinvd.GetIinvd(nvd).FirstOrDefault();
                        q.loc_id = store.plas_loc_id;
                        q.item_id = store.item_id;
                        q.iarc_id = "KS";
                        q.qty_o = store.prod_qty;
                        q.type = 1;
                        q.adj_qty = -store.prod_qty;
                        q.create_dtim = DateTime.Now;
                        q.create_user = int.Parse((System.Web.HttpContext.Current.Session["caller"] as Caller).user_id.ToString());
                        q.made_dt = store.made_date;
                        q.cde_dt = store.cde_dt;
                        if (_iagMgr.insertiialg(q) > 0)
                        {
                            Caller call = new Caller();
                            call = (System.Web.HttpContext.Current.Session["caller"] as Caller);
                            ProductItem proitem = new ProductItem();
                            _proditemMgr = new ProductItemMgr(mySqlConnectionString);
                            int item_stock = store.prod_qty;
                            proitem.Item_Stock = -item_stock;
                            proitem.Item_Id = store.item_id;
                            string path = "/WareHouse/KutiaoAddorReduce";
                            _proditemMgr.UpdateItemStock(proitem, path, call);
                            return Json(new { success = "true" });
                        }
                        else
                        {

                            return Json(new { success = "false" });
                        }
                    }
                    else
                    {
                        Iinvd store = _iinvd.GetIinvd(nvd).FirstOrDefault();
                        q.loc_id = store.plas_loc_id;
                        q.item_id = store.item_id;
                        q.iarc_id = "KS";
                        q.qty_o = 0;
                        q.type = 1;
                        q.adj_qty = store.prod_qty;
                        q.create_dtim = DateTime.Now;
                        q.create_user = int.Parse((System.Web.HttpContext.Current.Session["caller"] as Caller).user_id.ToString());
                        q.made_dt = store.made_date;
                        q.cde_dt = store.cde_dt;
                        if (_iagMgr.insertiialg(q) > 0)
                        {
                            Caller call = new Caller();
                            call = (System.Web.HttpContext.Current.Session["caller"] as Caller);
                            ProductItem proitem = new ProductItem();
                            _proditemMgr = new ProductItemMgr(mySqlConnectionString);
                            int item_stock = store.prod_qty;
                            proitem.Item_Stock = item_stock;
                            proitem.Item_Id = store.item_id;
                            string path = "/WareHouse/KutiaoAddorReduce";
                            _proditemMgr.UpdateItemStock(proitem, path, call);
                            return Json(new { success = "true" });
                        }
                        else
                        {

                            return Json(new { success = "false" });
                        }
                    }
                }
                else
                {

                    return Json(new { success = "false" });
                }
            }
            catch (Exception ex)
            {
                Log4NetCustom.LogMessage logMessage = new Log4NetCustom.LogMessage();
                logMessage.Content = string.Format("TargetSite:{0},Source:{1},Message:{2}", ex.TargetSite.Name, ex.Source, ex.Message);
                logMessage.MethodName = System.Reflection.MethodBase.GetCurrentMethod().Name;
                log.Error(logMessage);
                return Json(new { success = "false" });
            }
        }
Esempio n. 21
0
        /**
         * chaojie1124j 2015/09/17 庫存調整的時候,把商品的庫存也做相應的調整
         */
        public  string UpdateItemStock(ProductItem query)
        { 
            StringBuilder strSql = new StringBuilder();
            try
            {
               strSql.Append("update product_item set ");
               strSql.AppendFormat("item_stock=item_stock+{0} where item_id={1};", query.Item_Stock, query.Item_Id);
                return strSql.ToString();
            }
            catch (Exception ex)
            {
                throw new Exception("ProductItemDao-->UpdateItemStock" + ex.Message + strSql.ToString(), ex);
            }  

        }
Esempio n. 22
0
 //RF直接庫調
 public HttpResponseBase RFKT()
 {
     string json = string.Empty;
     IialgQuery q = new IialgQuery();
     uint id = 0; DateTime dt = new DateTime(); int sun = 0;
     _proditemMgr = new ProductItemMgr(mySqlConnectionString);
     ProductItem Proitems = new ProductItem();
     try
     {
         if (uint.TryParse(Request.Params["item_id"].ToString(), out id))
         {//商品id
             q.item_id = id;
             Proitems.Item_Id = id;
         }
         if (DateTime.TryParse(Request.Params["made_date"].ToString(), out dt))
         {//商品製造日期
             q.made_dt = dt;
         }
         if (int.TryParse(Request.Params["prod_qty"].ToString(), out sun))
         {//商品原有數量
             q.qty_o = sun;
         }
         if (int.TryParse(Request.Params["pnum"].ToString(), out sun))
         {//商品撿貨數量
             q.pnum = sun;
         }
         if (!string.IsNullOrEmpty(Request.Params["loc_id"].ToString()))
         {//商品撿貨數量
             q.loc_id = Request.Params["loc_id"];
         }
         if (!string.IsNullOrEmpty(Request.Params["order_id"]))
         {
             q.order_id = Request.Params["order_id"];
         }
         q.create_user = (System.Web.HttpContext.Current.Session["caller"] as Caller).user_id;
         //進行庫調
         _iagMgr = new IialgMgr(mySqlConnectionString);
         Caller call = new Caller();
         call = (System.Web.HttpContext.Current.Session["caller"] as Caller);
         string path = "/WareHouse/KutiaoAddorReduce";
         if (q.loc_id == "YY999999")
         {
             json = "{success:false}";
         }
         else
         {
             Proitems.Item_Stock = q.pnum - q.qty_o;
             int result = _iagMgr.addIialgIstock(q);
             if (result == 2)
             {
                 json = "{success:true,msg:2}";
             }
             if (result == 100)
             {
                 _proditemMgr.UpdateItemStock(Proitems, path, call);
                 json = "{success:true,msg:100}";
             }
         }
     }
     catch (Exception ex)
     {
         Log4NetCustom.LogMessage logMessage = new Log4NetCustom.LogMessage();
         logMessage.Content = string.Format("TargetSite:{0},Source:{1},Message:{2}", ex.TargetSite.Name, ex.Source, ex.Message);
         logMessage.MethodName = System.Reflection.MethodBase.GetCurrentMethod().Name;
         log.Error(logMessage);
         json = "{success:false}";
     }
     this.Response.Clear();
     this.Response.Write(json);
     this.Response.End();
     return this.Response;
 }
Esempio n. 23
0
        public HttpResponseBase specTempSave()
        {
            string resultStr = "{success:true}";
            bool result = true;
            try
            {

                Caller _caller = (Session["caller"] as Caller);
                string specType = Request.Params["specType"];
                string spec1Name = Request.Params["spec1Name"];
                string spec1Result = Request.Params["spec1Result"];
                string spec2Name = "";
                string spec2Result;

                _specMgr = new ProductSpecMgr(connectionString);
                _specTempMgr = new ProductSpecTempMgr(connectionString);
                _productTempMgr = new ProductTempMgr(connectionString);
                _productItemMgr = new ProductItemMgr(connectionString);
                _productItemTempMgr = new ProductItemTempMgr(connectionString);
                _serialMgr = new SerialMgr(connectionString);

                if (!string.IsNullOrEmpty(Request.Params["ProductId"]))
                {
                    uint proId = uint.Parse(Request.Params["ProductId"]);

                    _functionMgr = new FunctionMgr(connectionString);
                    string function = Request.Params["function"] ?? "";
                    Function fun = _functionMgr.QueryFunction(function, "/Product/ProductSave");
                    int functionid = fun == null ? 0 : fun.RowId;
                    HistoryBatch batch = new HistoryBatch { functionid = functionid };
                    batch.batchno = Request.Params["batch"] ?? "";
                    batch.kuser = (Session["caller"] as Caller).user_email;

                    #region 正式表修改
                    List<ProductSpec> spec1List = null;
                    List<ProductSpec> spec2List = null;
                    List<ProductSpec> specUpdateList = new List<ProductSpec>();
                    List<ProductSpec> specAddList = new List<ProductSpec>();
                    JavaScriptSerializer jss = new JavaScriptSerializer();
                    spec1List = jss.Deserialize<List<ProductSpec>>(spec1Result);
                    if (spec1List != null)
                    {
                        //規格一處理
                        spec1List.ForEach(m =>
                        {
                            m.product_id = proId;
                            m.spec_type = 1;
                            if (m.spec_id != 0)
                            {
                                specUpdateList.Add(m);
                            }
                            else
                            {
                                specAddList.Add(m);
                            }
                        });
                    }

                    //規格二處理
                    if (specType.Equals("2"))
                    {
                        spec2Name = Request.Params["spec2Name"];
                        spec2Result = Request.Params["spec2Result"];
                        spec2List = jss.Deserialize<List<ProductSpec>>(spec2Result);

                        spec2List.ForEach(m =>
                        {
                            m.product_id = proId;
                            m.spec_type = 2;
                            if (m.spec_id != 0)
                            {
                                specUpdateList.Add(m);
                            }
                            else
                            {
                                specAddList.Add(m);
                            }
                        });
                    }

                    Product proModel = new Product();
                    _productMgr = new ProductMgr(connectionString);
                    _tableHistoryMgr = new TableHistoryMgr(connectionString);
                    proModel = _productMgr.Query(new Product { Product_Id = proId }).FirstOrDefault();
                    proModel.Spec_Title_1 = spec1Name;
                    proModel.Spec_Title_2 = spec2Name;

                    if (specUpdateList.Count() > 0)
                    {
                        for (int i = 0, j = specUpdateList.Count(); i < j; i++)
                        {
                            ArrayList sqls = new ArrayList();
                            sqls.Add(_specMgr.Update(specUpdateList[i]));
                            if (i == 0)
                            {
                                sqls.Add(_productMgr.Update(proModel));
                            }
                            if (!_tableHistoryMgr.SaveHistory<ProductSpec>(specUpdateList[i], batch, sqls))
                            {
                                result = false;
                            }
                        }
                    }

                    if (specAddList.Count() > 0)
                    {

                        List<ProductItem> saveItemList = new List<ProductItem>();
                        List<ProductSpec> spec1ExistList = spec1List.Where(m => m.spec_id != 0).ToList();     //規格一中原本就存在的規格
                        specAddList.ForEach(p => p.spec_id = uint.Parse(_serialMgr.NextSerial(18).ToString()));
                        ProductItem saveTemp;
                        List<PriceMaster> list_price = new List<PriceMaster>();
                        PriceMasterMgr pm = new PriceMasterMgr(connectionString);
                        list_price = pm.GetPriceMasterInfoByID2(proId.ToString());//獲取同一個ID下其他產品的價格信息
                        PriceMaster _p = list_price.FirstOrDefault();//add by wangwei0216w 2014/9/19 獲取同一個ID下其他產品的信息
                        //List<ProductItem> pro_list = new List<ProductItem>();
                        //ProductItemMgr pig = new ProductItemMgr(connectionString);
                        //pro_list = pig.GetProductItemByID(Convert.ToInt32(proId));
                        //ProductItem _product = pro_list.FirstOrDefault();//獲取同一個ID下其他產品的信息
                        foreach (var m in specAddList)
                        {
                            if (specType.Equals("1"))
                            {
                                if (m.spec_type == 1)
                                {
                                    saveTemp = new ProductItem();
                                    if (_p.same_price == 1)             //add by wangwei 0216w 2014/9/19 如果同價 就將價格賦予新增規格
                                    {
                                        //saveTemp.Item_Cost = Convert.ToUInt32(_p.cost);
                                        //saveTemp.Item_Money = Convert.ToUInt32(_p.price);
                                    }
                                    else
                                    {
                                        resultStr = "{success:true,Msg:true}";
                                    }
                                    saveTemp.Spec_Id_1 = m.spec_id;
                                    saveTemp.Product_Id = proId;
                                    // saveTemp.Item_Stock = 10;
                                    saveTemp.Item_Alarm = 1;
                                    saveItemList.Add(saveTemp);
                                }
                                else
                                {
                                    saveTemp = new ProductItem();
                                    if (_p.same_price == 1)             //add by wangwei 0216w 2014/9/19 如果同價 就將價格賦予新增規格
                                    {
                                        //saveTemp.Item_Cost = Convert.ToUInt32(_p.cost);
                                        //saveTemp.Item_Money = Convert.ToUInt32(_p.price);
                                    }
                                    else
                                    {
                                        resultStr = "{success:true,Msg:true}";
                                    }
                                    saveTemp.Spec_Id_2 = m.spec_id;
                                    saveTemp.Product_Id = proId;
                                    //saveTemp.Item_Stock = 10;
                                    saveTemp.Item_Alarm = 1;
                                    saveItemList.Add(saveTemp);
                                }
                            }
                            else
                            {
                                if (m.spec_type == 1)
                                {
                                    foreach (ProductSpec item in spec2List)
                                    {
                                        saveTemp = new ProductItem();
                                        if (_p.same_price == 1)             //add by wangwei 0216w 2014/9/19 如果同價 就將價格賦予新增規格
                                        {
                                            //saveTemp.Item_Cost = Convert.ToUInt32(_p.cost);
                                            //saveTemp.Item_Money = Convert.ToUInt32(_p.price);
                                        }
                                        else
                                        {
                                            resultStr = "{success:true,Msg:true}";
                                        }
                                        saveTemp.Spec_Id_1 = m.spec_id;
                                        saveTemp.Spec_Id_2 = item.spec_id;
                                        //saveTemp.Item_Stock = 10;
                                        saveTemp.Item_Alarm = 1;
                                        saveTemp.Product_Id = proId;
                                        saveItemList.Add(saveTemp);
                                    }
                                }
                                else
                                {
                                    foreach (ProductSpec item2 in spec1ExistList)
                                    {
                                        saveTemp = new ProductItem();
                                        if (_p.same_price == 1)             //add by wangwei 0216w 2014/9/19 如果同價 就將價格賦予新增規格
                                        {
                                            //saveTemp.Item_Cost = Convert.ToUInt32(_p.cost);
                                            //saveTemp.Item_Money = Convert.ToUInt32(_p.price);
                                        }
                                        else
                                        {
                                            resultStr = "{success:true,Msg:true}";
                                        }
                                        saveTemp.Spec_Id_1 = item2.spec_id;
                                        saveTemp.Spec_Id_2 = m.spec_id;
                                        //saveTemp.Item_Stock = 10;
                                        saveTemp.Item_Alarm = 1;
                                        saveTemp.Product_Id = proId;
                                        saveItemList.Add(saveTemp);
                                    }

                                }
                            }
                        }

                        _specMgr.Save(specAddList);
                        _productItemMgr.Save(saveItemList);
                        ProductItem pro;
                        if (proModel.Product_Status != 0) //add by wangwei0216w 2014/9/18 作用:將Export_flag的值設置為1
                        {
                            pro = new ProductItem() { Product_Id = proModel.Product_Id, Export_flag = 1 };
                            _productItemMgr.UpdateExportFlag(pro);
                        }
                        if (result) //如果之前保存規格,插入臨時表登操作有誤,則不執行插入itemprice的操作
                        {
                            List<ProductItem> item_list = _productItemMgr.GetProductNewItem_ID(Convert.ToInt32(proModel.Product_Id));   //得到product_item的新增ID
                            ItemPrice i = new ItemPrice();
                            ItemPriceMgr ipm = new ItemPriceMgr(connectionString);
                            ArrayList liststr = new ArrayList();
                            foreach (PriceMaster p in list_price)
                            {
                                foreach (ProductItem pi in item_list)
                                {
                                    if (p.same_price == 1)
                                    {
                                        i.price_master_id = p.price_master_id;
                                        i.item_id = pi.Item_Id;
                                        i.item_money = Convert.ToUInt32(p.price);
                                        i.item_cost = Convert.ToUInt32(p.cost);
                                        i.event_cost = Convert.ToUInt32(p.event_cost);
                                        i.event_money = Convert.ToUInt32(p.event_price);
                                    }
                                    else
                                    {
                                        i.price_master_id = p.price_master_id;
                                        i.item_id = pi.Item_Id;
                                        i.item_money = 0;
                                        i.item_cost = 0;
                                        i.event_money = 0;
                                        i.event_cost = 0;
                                        resultStr = "{success:true,Msg:true}";
                                    }
                                    liststr.Add(ipm.Save(i));
                                }
                            }
                            ipm.AddItemPricBySpec(liststr, connectionString);
                        }
                    }
                    //若為單一商品,則把product_item.export_flag改為2 edit by xiangwang0413w 2014/06/30
                    //if (proModel.Combination == 1)
                    //{
                    //    _productItemMgr = new ProductItemMgr(connectionString);
                    //    ProductItem pro_Item = new ProductItem() { Product_Id = proModel.Product_Id, Export_flag = 2 };
                    //    _productItemMgr.UpdateExportFlag(pro_Item);
                    //}

                    #endregion
                }
                else
                {
                    #region 臨時表修改
                    _productTempMgr = new ProductTempMgr(connectionString); //add by xiangwang 2014.09.26 可修改庫存預設值為99

                    string product_id = "0";
                    if (!string.IsNullOrEmpty(Request.Form["OldProductId"]))
                    {
                        product_id = Request.Form["OldProductId"];
                    }

                    //add by xiangwang 2014.09.26 可修改庫存預設值為99
                    ProductTemp query = _productTempMgr.GetProTemp(new ProductTemp { Writer_Id = _caller.user_id, Combo_Type = COMBO_TYPE, Product_Id = product_id });


                    if (!specType.Equals("0") && !string.IsNullOrEmpty(specType))
                    {
                        #region 有規格
                        List<ProductSpecTemp> spec1List;
                        List<ProductSpecTemp> spec2List;
                        List<ProductSpecTemp> specAllList = new List<ProductSpecTemp>();

                        JavaScriptSerializer jss = new JavaScriptSerializer();
                        spec1List = jss.Deserialize<List<ProductSpecTemp>>(spec1Result);

                        foreach (ProductSpecTemp item in spec1List)
                        {
                            //   specid = _serialMgr.NextSerial(18);
                            //item.spec_id = uint.Parse(specid.ToString());
                            item.Writer_Id = _caller.user_id;
                            item.product_id = product_id;
                            item.spec_type = 1;
                            item.spec_image = "";
                            specAllList.Add(item);
                        }

                        if (specType.Equals("2"))
                        {
                            spec2Name = Request.Params["spec2Name"];
                            spec2Result = Request.Params["spec2Result"];
                            spec2List = jss.Deserialize<List<ProductSpecTemp>>(spec2Result);

                            foreach (ProductSpecTemp item in spec2List)
                            {
                                // specid = _serialMgr.NextSerial(18);
                                //item.spec_id = uint.Parse(specid.ToString());
                                item.Writer_Id = _caller.user_id;
                                item.product_id = product_id;
                                item.spec_type = 2;
                                item.spec_image = "";
                                specAllList.Add(item);
                            }
                        }

                        List<ProductSpecTemp> tempList = _specTempMgr.Query(new ProductSpecTemp { Writer_Id = _caller.user_id, product_id = product_id });
                        if (tempList == null || tempList.Count() <= 0)
                        {
                            #region 保存

                            specAllList.ForEach(p => p.spec_id = uint.Parse(_serialMgr.NextSerial(18).ToString()));

                            bool saveSpecResult = _specTempMgr.Save(specAllList);

                            if (saveSpecResult)
                            {
                                _productItemTempMgr.Delete(new ProductItemTemp { Writer_Id = _caller.user_id, Product_Id = product_id });
                                #region 保存ProductItemTemp

                                List<ProductSpecTemp> specAllResultList = _specTempMgr.Query(new ProductSpecTemp { Writer_Id = _caller.user_id, product_id = product_id });
                                List<ProductSpecTemp> spec1ResultList = specAllResultList.Where(m => m.spec_type == 1).ToList();
                                List<ProductSpecTemp> spec2ResultList = specAllResultList.Where(m => m.spec_type == 2).ToList();

                                List<ProductItemTemp> saveItemList = new List<ProductItemTemp>();

                                if (specType.Equals("1"))
                                {
                                    foreach (ProductSpecTemp specTemp1 in spec1ResultList)
                                    {
                                        ProductItemTemp itemTemp = new ProductItemTemp();
                                        itemTemp.Writer_Id = _caller.user_id;
                                        itemTemp.Product_Id = product_id;
                                        itemTemp.Spec_Id_1 = specTemp1.spec_id;
                                        //itemTemp.Item_Stock = 10;
                                        itemTemp.Item_Alarm = 1;
                                        saveItemList.Add(itemTemp);

                                    }
                                }
                                else if (specType.Equals("2"))
                                {
                                    foreach (ProductSpecTemp specTemp1 in spec1ResultList)
                                    {
                                        foreach (ProductSpecTemp specTemp2 in spec2ResultList)
                                        {
                                            ProductItemTemp itemTemp = new ProductItemTemp();
                                            itemTemp.Writer_Id = _caller.user_id;
                                            itemTemp.Product_Id = product_id;
                                            itemTemp.Spec_Id_1 = specTemp1.spec_id;
                                            itemTemp.Spec_Id_2 = specTemp2.spec_id;
                                            //itemTemp.Item_Stock = 10;
                                            itemTemp.Item_Alarm = 1;
                                            itemTemp.Item_Code = "";
                                            itemTemp.Barcode = "";
                                            saveItemList.Add(itemTemp);
                                        }
                                    }
                                }

                                //add by xiangwang 2014.09.26 可修改庫存預設值為99
                                //saveItemList.ForEach(m => m.SetDefaultItemStock(query));

                                bool saveItemResult = _productItemTempMgr.Save(saveItemList);

                                if (!saveItemResult)
                                {
                                    result = false;
                                }

                                #endregion

                            }
                            else
                            {
                                result = false;
                            }
                            #endregion
                        }
                        else
                        {
                            #region 更新
                            string strSpecInit = Request.Params["specInit"];
                            string[] specs = strSpecInit.Split(',');

                            List<ProductSpecTemp> addList = specAllList.Where(p => p.spec_id == 0).ToList();
                            if (addList.Count() > 0)
                            {
                                addList.ForEach(p => p.spec_id = uint.Parse(_serialMgr.NextSerial(18).ToString()));

                                List<ProductSpecTemp> specAllResultList = _specTempMgr.Query(new ProductSpecTemp { Writer_Id = _caller.user_id, product_id = product_id });
                                List<ProductSpecTemp> spec1ResultList = specAllResultList.Where(m => m.spec_type == 1).ToList();
                                List<ProductSpecTemp> spec2ResultList = specAllResultList.Where(m => m.spec_type == 2).ToList();
                                List<ProductItemTemp> saveItemList = new List<ProductItemTemp>();
                                foreach (ProductSpecTemp item in addList)
                                {
                                    if (specType.Equals("1"))
                                    {
                                        if (item.spec_type == 1)
                                        {
                                            ProductItemTemp saveTemp = new ProductItemTemp();
                                            saveTemp.Writer_Id = _caller.user_id;
                                            saveTemp.Spec_Id_1 = item.spec_id;
                                            saveTemp.Product_Id = product_id;
                                            //saveTemp.Item_Stock = 10;
                                            saveTemp.Item_Alarm = 1;
                                            saveItemList.Add(saveTemp);
                                        }
                                        else
                                        {
                                            ProductItemTemp saveTemp = new ProductItemTemp();
                                            saveTemp.Writer_Id = _caller.user_id;
                                            saveTemp.Spec_Id_2 = item.spec_id;
                                            saveTemp.Product_Id = product_id;
                                            // saveTemp.Item_Stock = 10;
                                            saveTemp.Item_Alarm = 1;
                                            saveItemList.Add(saveTemp);
                                        }
                                    }
                                    else
                                    {
                                        if (item.spec_type == 1)
                                        {
                                            foreach (ProductSpecTemp item1 in spec2ResultList)
                                            {
                                                ProductItemTemp saveTemp = new ProductItemTemp();
                                                saveTemp.Writer_Id = _caller.user_id;
                                                saveTemp.Spec_Id_1 = item.spec_id;
                                                saveTemp.Spec_Id_2 = item1.spec_id;
                                                //saveTemp.Item_Stock = 10;
                                                saveTemp.Item_Alarm = 1;
                                                saveTemp.Product_Id = product_id;
                                                saveItemList.Add(saveTemp);
                                            }

                                            foreach (ProductSpecTemp item1 in addList.Where(p => p.spec_type == 2).ToList())
                                            {
                                                ProductItemTemp saveTemp = new ProductItemTemp();
                                                saveTemp.Writer_Id = _caller.user_id;
                                                saveTemp.Spec_Id_1 = item.spec_id;
                                                saveTemp.Spec_Id_2 = item1.spec_id;
                                                //saveTemp.Item_Stock = 10;
                                                saveTemp.Item_Alarm = 1;
                                                saveTemp.Product_Id = product_id;
                                                saveItemList.Add(saveTemp);
                                            }
                                        }
                                        else
                                        {
                                            foreach (ProductSpecTemp item2 in spec1ResultList)
                                            {
                                                ProductItemTemp saveTemp = new ProductItemTemp();
                                                saveTemp.Writer_Id = _caller.user_id;
                                                saveTemp.Spec_Id_1 = item2.spec_id;
                                                saveTemp.Spec_Id_2 = item.spec_id;
                                                saveTemp.Product_Id = product_id;
                                                // saveTemp.Item_Stock = 10;
                                                saveTemp.Item_Alarm = 1;
                                                saveItemList.Add(saveTemp);
                                            }

                                        }
                                    }
                                }
                                _specTempMgr.Save(addList);

                                //add by xiangwang 2014.09.26 可修改庫存預設值為99
                                //saveItemList.ForEach(m => m.SetDefaultItemStock(query));

                                _productItemTempMgr.Save(saveItemList);

                            }

                            if (specs.Length > 0)
                            {
                                List<ProductSpecTemp> updateList = new List<ProductSpecTemp>();
                                foreach (string initSpecId in specs)
                                {
                                    ProductSpecTemp nowItem = specAllList.Where(p => p.spec_id == uint.Parse(initSpecId)).FirstOrDefault();
                                    if (nowItem != null)
                                    {
                                        updateList.Add(nowItem);
                                    }
                                    else
                                    {

                                        ProductItemTemp delTemp = new ProductItemTemp { Writer_Id = _caller.user_id, Product_Id = product_id };
                                        uint spectype = _specTempMgr.Query(new ProductSpecTemp { spec_id = uint.Parse(initSpecId), product_id = product_id })[0].spec_type;
                                        if (spectype == 1)
                                        {
                                            delTemp.Spec_Id_1 = uint.Parse(initSpecId);
                                        }
                                        else if (spectype == 2)
                                        {
                                            delTemp.Spec_Id_2 = uint.Parse(initSpecId);
                                        }
                                        if (!_productItemTempMgr.Delete(delTemp))
                                        {
                                            result = false;
                                        }
                                        if (!_specTempMgr.Delete(new ProductSpecTemp { spec_id = uint.Parse(initSpecId), Writer_Id = _caller.user_id, product_id = product_id }))
                                        {
                                            result = false;
                                        }
                                        DeletePicOnServer(false, true, false, uint.Parse(initSpecId), product_id);
                                    }

                                }
                                if (!_specTempMgr.Update(updateList, "spec"))
                                {
                                    result = false;
                                }
                            }

                            #endregion
                        }

                        #region 更新Product

                        ProductTemp proTemp = new ProductTemp();
                        proTemp.Writer_Id = _caller.user_id;
                        proTemp.Product_Spec = uint.Parse(specType);
                        proTemp.Spec_Title_1 = spec1Name;
                        proTemp.Spec_Title_2 = spec2Name;
                        proTemp.Combo_Type = COMBO_TYPE;
                        proTemp.Product_Id = product_id;
                        bool saveProductResult = _productTempMgr.SpecInfoSave(proTemp);
                        if (!saveProductResult)
                        {
                            result = false;
                        }
                        #endregion

                        #endregion
                    }
                    else
                    {
                        #region 無規格
                        List<ProductItemTemp> saveList = new List<ProductItemTemp>();
                        //如果原數據有規格
                        if (query.Product_Spec != 0)
                        {
                            //刪除服務器上對應的圖片
                            DeletePicOnServer(false, true, false, 0, product_id);

                            _productItemTempMgr.Delete(new ProductItemTemp { Writer_Id = _caller.user_id, Product_Id = product_id });

                            _specTempMgr.Delete(new ProductSpecTemp { Writer_Id = _caller.user_id, product_id = product_id });

                            _productTempMgr.SpecInfoSave(new ProductTemp { Product_Spec = 0, Spec_Title_1 = "", Spec_Title_2 = "", Writer_Id = _caller.user_id, Combo_Type = COMBO_TYPE, Product_Id = product_id });

                            saveList = new List<ProductItemTemp>();
                            saveList.Add(new ProductItemTemp { Writer_Id = _caller.user_id, Product_Id = product_id/*, Item_Stock = 10*/, Item_Alarm = 1 });
                        }
                        else
                        {
                            List<ProductItemTemp> itemQuery = _productItemTempMgr.Query(new ProductItemTemp { Writer_Id = _caller.user_id, Product_Id = product_id });
                            if (itemQuery.Count() <= 0)
                            {
                                saveList = new List<ProductItemTemp>();
                                saveList.Add(new ProductItemTemp { Writer_Id = _caller.user_id, Product_Id = product_id, /*Item_Stock = 10,*/ Item_Alarm = 1 });
                                // _productItemTempMgr.Save(saveList);
                            }
                        }

                        //add by xiangwang 2014.09.26 可修改庫存預設值為99
                        //saveList.ForEach(m => m.SetDefaultItemStock(query));
                        _productItemTempMgr.Save(saveList);

                        #endregion
                    }
                    #endregion

                    #region 調度或自出商品,商品庫存預設為99
                    var proditemTemp = new ProductItemTemp { Product_Id = product_id, Writer_Id = _caller.user_id };
                    proditemTemp.SetDefaultItemStock(query);
                    _productItemTempMgr.UpdateItemStock(proditemTemp);
                    #endregion
                }
            }
            catch (Exception ex)
            {
                result = false;
                Log4NetCustom.LogMessage logMessage = new Log4NetCustom.LogMessage();
                logMessage.Content = string.Format("TargetSite:{0},Source:{1},Message:{2}", ex.TargetSite.Name, ex.Source, ex.Message);
                logMessage.MethodName = System.Reflection.MethodBase.GetCurrentMethod().Name;
                log.Error(logMessage);
            }

            if (!result)
            {
                resultStr = "{success:false,Msg:false}";
            }

            this.Response.Clear();
            this.Response.Write(resultStr);
            this.Response.End();
            return this.Response;
        }
Esempio n. 24
0
        public HttpResponseBase KutiaoAddorReduce()
        {
            string jsonStr = String.Empty;
            _iinvd = new IinvdMgr(mySqlConnectionString);
            _iagMgr = new IialgMgr(mySqlConnectionString);
            Iinvd invd = new Iinvd();
            iialg iag = new iialg();
            IstockChange Icg = new IstockChange();
            ProductItem Proitems = new ProductItem();
            int results = 0;
            try
            {
                invd.row_id = Convert.ToInt32(Request.Params["row_id"]);//行號碼
                int resultcount = 0;
                int kucuncount = Convert.ToInt32(Request.Params["benginnumber"]);//庫存數量
                int tiaozhengcount = Convert.ToInt32(Request.Params["changenumber"]);
                int kucuntype = Convert.ToInt32(Request.Params["kutiaotype"]);
                if (!string.IsNullOrEmpty(Request.Params["item_id"]))//商品細項編號
                {
                    Icg.item_id = Convert.ToUInt32(Request.Params["item_id"]);
                    Proitems.Item_Id = Icg.item_id;
                }
                int oldsumcount = _iinvd.GetProqtyByItemid(Convert.ToInt32(Icg.item_id));//總庫存
                string iarc_id = "";
                if (!string.IsNullOrEmpty(Request.Params["iarcid"]))
                {
                    iarc_id = Request.Params["iarcid"];//庫調原因
                }

                #region 庫存調整的時候,商品庫存也要調整
                _proditemMgr = new ProductItemMgr(mySqlConnectionString);
                int item_stock = 0;
                #endregion
                if (kucuntype == 1)//表示選擇了加
                {
                    resultcount = kucuncount + tiaozhengcount;
                    item_stock = tiaozhengcount;
                }
                else//表示選擇了減號
                {
                    resultcount = kucuncount - tiaozhengcount;
                    item_stock = -tiaozhengcount;
                }
                Proitems.Item_Stock = item_stock;
                invd.prod_qty = resultcount;//此時為更改后的庫存
                invd.change_dtim = DateTime.Now;
                invd.change_user = (System.Web.HttpContext.Current.Session["caller"] as Caller).user_id;
                Icg.sc_trans_type = 2;
                Icg.sc_num_old = oldsumcount;
                Icg.sc_time = DateTime.Now;
                Icg.sc_user = (System.Web.HttpContext.Current.Session["caller"] as Caller).user_id;

                if (!string.IsNullOrEmpty(Request.Params["po_id"]))
                {
                    Icg.sc_cd_id = Request.Params["po_id"];//採購單編號
                }
                if (!string.IsNullOrEmpty(Request.Params["doc_no"]))
                {
                    Icg.sc_trans_id = Request.Params["doc_no"];//庫調單號
                }
                if (!string.IsNullOrEmpty(Request.Params["remarks"]))
                {
                    Icg.sc_note = Request.Params["remarks"];//備註
                }
                _istockMgr = new IstockChangeMgr(mySqlConnectionString);

                int j = _iinvd.kucunTiaozheng(invd); //更改iloc表中的狀態並且在iialg表中插入數據
                string path = "/WareHouse/KutiaoAddorReduce";
                Caller call = new Caller();
                call = (System.Web.HttpContext.Current.Session["caller"] as Caller);
                int k = 0;
                if (iarc_id == "NE" || iarc_id == "RF")//庫存調整-不改動前台庫存
                {
                    k = 1;
                }
                else
                {
                    k = _proditemMgr.UpdateItemStock(Proitems, path, call);
                }
                int newsumcount = _iinvd.GetProqtyByItemid(Convert.ToInt32(Icg.item_id));//總庫存

                Icg.sc_num_chg = newsumcount - oldsumcount;
                Icg.sc_num_new = newsumcount;
                Icg.sc_istock_why = 2;
                if (oldsumcount != newsumcount)
                {
                    results = _istockMgr.insert(Icg);
                }
                else
                {
                    results = 1;
                }
                if (j > 0 && results > 0 && k > 0)
                {
                    jsonStr = "{success:true}";
                }
                else
                {
                    jsonStr = "{success:false}";
                }
            }
            catch (Exception ex)
            {
                Log4NetCustom.LogMessage logMessage = new Log4NetCustom.LogMessage();
                logMessage.Content = string.Format("TargetSite:{0},Source:{1},Message:{2}", ex.TargetSite.Name, ex.Source, ex.Message);
                logMessage.MethodName = System.Reflection.MethodBase.GetCurrentMethod().Name;
                log.Error(logMessage);
                jsonStr = "{success:false}";
            }

            this.Response.Clear();
            this.Response.Write(jsonStr);
            this.Response.End();
            return this.Response;
        }
Esempio n. 25
0
 public string QueryStock()
 {
     string json = string.Empty;
     if (string.IsNullOrEmpty(Request.Params["product_id"]))
     {
         //查找臨時表是否有記錄
         _productItemTempMgr = new ProductItemTempMgr(connectionString);
         int writeId = (Session["caller"] as Caller).user_id;
         ProductItemTemp query = new ProductItemTemp { Writer_Id = writeId };
         if (!string.IsNullOrEmpty(Request.Form["OldProductId"]))
         {
             query.Product_Id = Request.Form["OldProductId"];
         }
         json = _productItemTempMgr.QueryStock(query);
     }
     else
     {
         //從正式表讀取數據
         _productItemMgr = new ProductItemMgr(connectionString);
         ProductItem pItem = new ProductItem();
         pItem.Product_Id = uint.Parse(Request.Params["product_id"]);
         _productItemMgr.Query(pItem);
         json = _productItemMgr.QueryStock(pItem);
     }
     return json;
 }
Esempio n. 26
0
        public HttpResponseBase verifyApply()
        {
            List<QueryandVerifyCustom> resultList = new List<QueryandVerifyCustom>();
            string result = "{success:false}";
            bool resl = true;
            try
            {
                string prodcutIdStr = Request.Params["prodcutIdStr"];
                string[] productIds = prodcutIdStr.Split(',');
                string method = Request.Params["method"];
                Caller _caller = (Session["caller"] as Caller);
                _prodMgr = new ProductMgr(connectionString);
                _applyMgr = new ProductStatusApplyMgr(connectionString);
                _statusHistoryMgr = new ProductStatusHistoryMgr(connectionString);
                _tableHistoryMgr = new TableHistoryMgr(connectionString);
                _functionMgr = new FunctionMgr(connectionString);
                string function = Request.Params["function"] ?? "";
                Function fun = _functionMgr.QueryFunction(function, "/ProductList") ?? _functionMgr.QueryFunction(function, "/ProductList/ReplaceVerify");
                int functionid = fun == null ? 0 : fun.RowId;
                HistoryBatch batch = new HistoryBatch { functionid = functionid, kuser = (Session["caller"] as Caller).user_email };
                string batchNo = CommonFunction.GetPHPTime().ToString() + "_" + (Session["caller"] as Caller).user_id + "_";

                string msg = "";
                foreach (string item in productIds.Distinct())
                {
                    ArrayList sqls = new ArrayList();
                    Product update = _prodMgr.Query(new Product { Product_Id = uint.Parse(item) }).FirstOrDefault();
                    //選擇自動上架時間時更改商品上架時間為選定時間
                    if (method.Equals("3"))
                    {
                        update.Product_Start = uint.Parse(BLL.gigade.Common.CommonFunction.GetPHPTime(Request.Params["product_start"]).ToString());
                        method = "1";
                    }
                    //若當前商品狀態不是新建商品或下架,則跳過申請
                    if (update.Product_Status != 0 && update.Product_Status != 6 && update.Product_Status!=7)
                    {
                        break;
                    }
                    //判斷商品是否失格 則 直接取消申請  add by  zhuoqin0830w 20105/07/01
                    if (update.off_grade == 1)
                    {
                        msg += "【" + update.Product_Id + "】商品是失格商品,不可申請審核!</br>";
                        break;
                    }
                    ProductStatusApply apply = new ProductStatusApply();
                    apply.product_id = uint.Parse(item);
                    apply.prev_status = update.Product_Status;
                    apply.online_mode = uint.Parse(method);
                    sqls.Add(_applyMgr.Save(apply));

                    ProductStatusHistory history = new ProductStatusHistory();
                    history.product_id = uint.Parse(item);
                    history.user_id = uint.Parse(_caller.user_id.ToString());
                    history.type = 1;               //操作類型        ???????????????????                      
                    history.product_status = 1;     //操作後狀態
                    //edit by zhuoqin0830w  2015/06/30  添加備註欄位
                    history.remark = Request.Form["Remark"];
                    sqls.Add(_statusHistoryMgr.Save(history));

                    batch.batchno = batchNo + update.Product_Id;
                    update.Product_Status = 1;    //狀態 -> 申請審核
                    sqls.Add(_prodMgr.Update(update, _caller.user_id));
                    if (!_tableHistoryMgr.SaveHistory<Product>(update, batch, sqls))
                    {
                        resl = false;
                    }
                    //若當前商品為單一商品並且商品狀態為新建商品,則將product_item.export_flag改為1
                    if (resl && update.Combination == 1 && apply.prev_status == 0)
                    {
                        _productItemMgr = new ProductItemMgr(connectionString);
                        ProductItem proItem = new ProductItem() { Product_Id = update.Product_Id, Export_flag = 1 };
                        _productItemMgr.UpdateExportFlag(proItem);
                    }
                }
                result = "{success:" + resl.ToString().ToLower() + ",'msg':'" + msg + "'}";
            }
            catch (Exception ex)
            {
                Log4NetCustom.LogMessage logMessage = new Log4NetCustom.LogMessage();
                logMessage.Content = string.Format("TargetSite:{0},Source:{1},Message:{2}", ex.TargetSite.Name, ex.Source, ex.Message);
                logMessage.MethodName = System.Reflection.MethodBase.GetCurrentMethod().Name;
                log.Error(logMessage);
            }
            Response.Clear();
            Response.Write(result);
            Response.End();
            return this.Response;
        }
Esempio n. 27
0
        /// <summary>
        /// 讀取Excel文件
        /// </summary>
        /// <param name="filePath"></param>
        /// <param name="channel_id"></param>
        /// <param name="fExtension"></param>
        /// <param name="isHeaderError"></param>
        /// <param name="errorPm"></param>
        /// <returns></returns>
        public List<ProductItemMapCustom> ReadFile(string filePath, int channel_id, string fExtension, ref bool isHeaderError, List<ProductItemMapCustom> errorPm)
        {
            try
            {
                NPOI4ExcelHelper fm = new NPOI4ExcelHelper(filePath);
                DataTable dt = fm.SheetData();
                if (dt == null) { return null; }

                List<ProductItemMapCustom> result = new List<ProductItemMapCustom>();

                Regex RegxProductId = new Regex("^\\d{5}$");
                Regex RegxItemId = new Regex("^\\d{6}$");
                Regex RegxMoney = new Regex("^\\d{1,9}$");

                for (int i = 0, j = dt.Rows.Count; i < j; i++)
                {
                    bool bl = true;
                    bool el = true;
                    bool isNull = false;
                    bool Pro_id = false;//記錄商品編號是否為空
                    bool Itm_id = false;//記錄商品細項編號是否為空
                    PriceMaster prm = new PriceMaster();
                    ProductItemMapCustom pm = new ProductItemMapCustom();
                    pm.channel_id = Convert.ToUInt32(channel_id);
                    for (int m = 0, n = dt.Columns.Count; m < n; m++)
                    {
                        string valStr = dt.Rows[i][m].ToString();
                        switch (dt.Columns[m].ToString().Trim())
                        {
                            case "商品編號(5碼)":
                                if (!string.IsNullOrEmpty(valStr))
                                {
                                    uint _ProductId = 0;
                                    uint.TryParse(valStr ?? "0", out _ProductId);
                                    pm.product_id = _ProductId;
                                    prm.product_id = _ProductId;
                                    if (!RegxProductId.IsMatch(pm.product_id.ToString()))
                                    {
                                        bl = false;
                                    }
                                }
                                else
                                {
                                    Pro_id = true;
                                    isNull = true;
                                    break;
                                }
                                break;
                            case "商品細項編號(6碼)":
                                if (!string.IsNullOrEmpty(valStr))
                                {
                                    if (valStr.Split(',').Length > 1)
                                    {
                                        for (int k = 0; k < valStr.Split(',').Length; k++)
                                        {
                                            if (!RegxItemId.IsMatch(valStr.Split(',')[k]))
                                            {
                                                bl = false;
                                            }
                                        }
                                        pm.group_item_id = CommonFunction.Rank_ItemId(valStr);
                                    }
                                    else
                                    {
                                        uint _itemId = 0;
                                        uint.TryParse(valStr ?? "0", out _itemId);
                                        pm.item_id = _itemId;
                                        pm.group_item_id = _itemId.ToString();
                                        if (!RegxItemId.IsMatch(pm.item_id.ToString()))
                                        {
                                            bl = false;
                                        }
                                    }
                                }
                                else
                                {
                                    Itm_id = true;
                                    isNull = true;
                                    break;
                                    //bl = false;
                                };
                                break;
                            case "外站商品名稱":
                                if (!string.IsNullOrEmpty(valStr))
                                {
                                    pm.product_name = valStr;
                                }
                                else
                                {
                                    bl = false;
                                };
                                break;
                            case "外站商品編號":
                                if (!string.IsNullOrEmpty(valStr))
                                {
                                    pm.channel_detail_id = valStr;
                                }
                                else
                                {
                                    bl = false;
                                }; break;
                            case "外站商品成本":
                                if (!string.IsNullOrEmpty(valStr))
                                {
                                    if (RegxMoney.IsMatch(valStr))
                                    {
                                        pm.product_cost = int.Parse(valStr);
                                    }
                                    else
                                    {
                                        bl = false;
                                    }
                                }
                                else
                                {
                                    bl = false;
                                }
                                ; break;
                            case "外站商品售價":
                                if (!string.IsNullOrEmpty(valStr))
                                {
                                    if (RegxMoney.IsMatch(valStr))
                                    {
                                        pm.product_price = int.Parse(valStr);
                                    }
                                    else
                                    {
                                        bl = false;
                                    }
                                }
                                else
                                {
                                    bl = false;
                                }
                                ; break;
                            case "組合中之數量(0為照組合中之設定)":
                                if (!string.IsNullOrEmpty(valStr))
                                {
                                    if (RegxMoney.IsMatch(valStr))
                                    {
                                        pm.set_num = uint.Parse(valStr);
                                    }
                                    else
                                    {
                                        bl = false;
                                    }
                                }
                                else
                                {
                                    bl = false;
                                } break;
                            case "user_email"://郵箱
                                if (!string.IsNullOrEmpty(valStr))
                                {
                                    if (_callerMgr.Login(valStr) != null)
                                    {
                                        prm.user_id = uint.Parse(_callerMgr.Login(valStr).user_id.ToString());
                                    }
                                }
                                break;
                            case "site_id"://站臺
                                if (!string.IsNullOrEmpty(valStr))
                                {
                                    if (RegxMoney.IsMatch(valStr))
                                    {
                                        prm.site_id = uint.Parse(valStr);
                                    }
                                    else
                                    {
                                        bl = false;
                                    }
                                }
                                else
                                {
                                    bl = false;
                                }
                                break;
                            case "user_level"://站臺等級
                                if (!string.IsNullOrEmpty(valStr))
                                {
                                    if (RegxMoney.IsMatch(valStr))
                                    {
                                        prm.user_level = uint.Parse(valStr);
                                    }
                                    else
                                    {
                                        bl = false;
                                    }
                                }
                                else
                                {
                                    bl = false;
                                }
                                break;
                            default:
                                el = false;
                                break;
                        }
                        //if (isNull)
                        //{
                        //    break;
                        //}
                    }

                    //判斷Excel表頭格式
                    if (!el)
                    {
                        isHeaderError = true;
                        break;
                    }
                    else
                    {
                        isHeaderError = false;
                    }

                    //若單一商品可以無商品編號,若固定組合可以無商品細項編號。其餘類型出現為空數據,則此行記錄無效,不做處理
                    if (Itm_id)
                    {
                        if (_productItemMapDao.CombinationQuery(pm).FirstOrDefault() != null && _productItemMapDao.CombinationQuery(pm).FirstOrDefault().combination == 2)
                        {
                            List<ProductComboMap> pMc = _productItemMapDao.QueryItemId(pm.product_id);
                            if (pMc != null && pMc.Where(e => e.product_spec == 0).Count() == pMc.Count())
                            {
                                string strItem = "";
                                for (int Itemi = 0, Itemj = pMc.Count(); Itemi < Itemj; Itemi++)
                                {
                                    if (Itemi > 0)
                                    {
                                        strItem += ",";
                                    }
                                    strItem += pMc[Itemi].item_id;
                                }
                                
                                pm.group_item_id = CommonFunction.Rank_ItemId(strItem);
                                isNull = false;
                            }
                        }
                    }
                    //單一商品邏輯 add by hufeng0813w 2013/12/23
                    if (Pro_id)
                    {
                        ProductItem pIm = new ProductItem();
                        pIm.Item_Id = uint.Parse(pm.item_id.ToString());
                        //pm.product_id = _productItemDao.Query(pIm).FirstOrDefault().Product_Id;
                        ProductItem itemResult = _productItemDao.Query(pIm).FirstOrDefault();
                        if (itemResult != null)
                        {
                            prm.product_id = pm.product_id = itemResult.Product_Id;
                            ProductMapCustom mapcusResult = _productItemMapDao.CombinationQuery(pm).FirstOrDefault();
                            if (mapcusResult != null && mapcusResult.combination == 1)
                            {
                                isNull = false;
                            }
                        }

                    }
                    if (isNull)
                    {
                        continue;
                    }
                    //獲取price_master_id
                    if (prm.product_id != 0)
                    {
                        pm.price_master_id = _priceMasterMgr.QueryPriceMasterId(prm);
                    }
                    else
                    {
                        bl = false;
                    }

                    //判斷內容格式
                    if (!bl)
                    {
                        pm.msg = Resource.CoreMessage.GetResource("ERROR_FORMAT");
                    }
                    else
                    {
                        ProductMapCustom map = _productItemMapDao.CombinationQuery(pm).FirstOrDefault();
                        if (map != null)
                        {
                            uint Combination = map.combination;
                            if (Combination != 2)
                            {
                                ProductItem pi = new ProductItem();
                                pi.Item_Id = uint.Parse(pm.item_id.ToString());
                                if (_productItemMgr.Query(pi).Count == 0)
                                {
                                    pm.msg = Resource.CoreMessage.GetResource("ITEMID_ID_NOT_EXISTS");
                                    bl = false;
                                }
                                else
                                {
                                    if (_productItemMapDao.Exist(pm) > 0)
                                    {
                                        pm.msg = Resource.CoreMessage.GetResource("COMPARE_EXISTS");
                                        bl = false;
                                    }
                                    else
                                    {
                                        ProductItemMapCustom existItem = result.Where(m => m.item_id == pm.item_id).FirstOrDefault();
                                        if (existItem != null)
                                        {
                                            pm.msg = Resource.CoreMessage.GetResource("COMPARE_EXISTS");
                                            bl = false;
                                        }
                                    }
                                }
                            }
                            else
                            {
                                #region
                                for (int l = 0; l < pm.group_item_id.Split(',').Length; l++)
                                {
                                    if (_productItemMapDao.Comb_Compare(pm.product_id, uint.Parse(pm.group_item_id.Split(',')[l])) == 0)
                                    {
                                        pm.msg = Resource.CoreMessage.GetResource("ITEMID_ID_NOT_COMBINATION");
                                        bl = false;
                                    }
                                    else
                                    {
                                        #region
                                        if (l == 0)
                                        {
                                            if (_productItemMapDao.Comb_Exist(pm) > 0)
                                            {
                                                pm.msg = Resource.CoreMessage.GetResource("COMPARE_EXISTS");
                                                bl = false;
                                            }
                                            else
                                            {
                                                ProductItemMapCustom existItem = result.Where(m => m.group_item_id == pm.group_item_id).FirstOrDefault();
                                                if (existItem != null)
                                                {
                                                    pm.msg = Resource.CoreMessage.GetResource("COMPARE_EXISTS");
                                                    bl = false;
                                                }
                                            }
                                        }
                                        #endregion
                                    }
                                }
                                #endregion
                            }
                        }
                        else
                        {
                            bl = false;
                            pm.msg = Resource.CoreMessage.GetResource("PRODUCT_NOT_EXIST");
                        }
                    }

                    if (!bl)
                    {
                        errorPm.Add(pm);
                    }
                    else
                    {
                        result.Add(pm);
                    }
                }
                return result; // _access.getObjByTable<ProductItemMap>(dt);
            }
            catch (Exception ex)
            {
                throw new Exception("ProductItemMapExcelMgr-->ReadFile-->" + ex.Message, ex);
            }
        } 
Esempio n. 28
0
 public string SaveSql(ProductItem item)
 {
     item.Replace4MySQL();
     StringBuilder stb = new StringBuilder("insert into product_item(`item_id`,`spec_id_1`,`spec_id_2`,`item_cost`,`item_money`,");
     stb.Append("`event_product_start`,`event_product_end`,`event_item_cost`,`event_item_money`,`item_stock`,`item_alarm`,`item_status`,`item_code`,`barcode`,`product_id`)values({0},");
     stb.AppendFormat("{0},{1},{2}", item.Spec_Id_1, item.Spec_Id_2, item.Item_Cost);
     stb.AppendFormat(",{0},{1},{2},{3}", item.Item_Money, item.Event_Product_Start, item.Event_Product_End, item.Event_Item_Cost);
     stb.AppendFormat(",{0},{1},{2},{3}", item.Event_Item_Money, item.Item_Stock, item.Item_Alarm, item.Item_Status);
     stb.AppendFormat(",'{0}','{1}'", item.Item_Code, item.Barcode);
     stb.Append(",{1});select @@identity;");
     return stb.ToString();
 }
Esempio n. 29
0
       public bool UpdateIpodCheck(IpodQuery query,IpoNvdQuery ipoNvd_query)
       {
           Boolean result = false;
           try
           {
               ArrayList aList = new ArrayList();
               ITableHistoryImplMgr _tableHistoryMgr = new TableHistoryMgr(conStr);//實例化歷史記錄的類
               
               Int64 n_Time = BLL.gigade.Common.CommonFunction.GetPHPTime();
               Function myFun = new Function();
               myFun.FunctionCode = "/WareHouse/Check";
               List<Function> funList = _functionMgr.Query(myFun);
               int functionid = funList.Count == 0 ? 0 : funList[0].RowId;
               HistoryBatch batch = new HistoryBatch { functionid = functionid };
               batch.kuser = query.user_email;

               //獲取添加IpoNvd的SQL
               string ipoNvdSql = _IpodDao.GetInsertIpoNvdSql(ipoNvd_query);
               aList.Add(ipoNvdSql);

               //獲取歷史記錄SQL
               string Check = _IpodDao.UpdateIpodCheck(query);

               //獲取修改庫存SQL  
                string Stock = string.Empty;
                ProductItem item = new ProductItem();
                item = _IpodDao.GetStockHistorySql(query, out Stock);
                
                batch.batchno = n_Time + "_" + query.change_user + "_" + item.Product_Id;
                if (item != null)
                {
                    item.Item_Stock = query.item_stock;
                    aList.Add(Stock);
                    aList.Add(Check);
                    result = _tableHistoryMgr.SaveHistory<ProductItem>(item, batch, aList);
                }

                //獲取修改商品Ignore SQL  
                string Ignore_Stock = string.Empty;
                Product product = new Product();
                product = _IpodDao.GetIgnoreHistorySql(query, out Ignore_Stock);
                if (product != null)
                {
                    product.Ignore_Stock = 0;
                    aList.Clear();
                    aList.Add(Ignore_Stock);
                    result = _tableHistoryMgr.SaveHistory<Product>(product, batch, aList);
                }

               
               return result;
           }
           catch (Exception ex)
           {

               throw new Exception("IpoMgr-->UpdateIpodCheck-->" + ex.Message, ex);
           }
       }
Esempio n. 30
0
        public int Save(ProductItem saveModel)
        {
            try
            {
                //StringBuilder stb = new StringBuilder("insert into product_item (`product_id`,`spec_id_1`,`spec_id_2`,`item_cost`,`item_money`,`event_product_start`,`event_product_end`,`event_item_cost`,`event_item_money`,`item_stock`,`item_alarm`,`item_status`,`item_code`,`barcode`,`item_id`)");
                //stb.AppendFormat(" values ({0},{1},{2},{3},{4},{5},{6},{7},{8},{9},{10},{11},'{12}','{13}',{14})", saveModel.Product_Id, saveModel.Spec_Id_1, saveModel.Spec_Id_2, saveModel.Item_Cost, saveModel.Item_Money, saveModel.Event_Product_Start, saveModel.Event_Product_End, saveModel.Event_Item_Cost, saveModel.Event_Item_Money, saveModel.Item_Stock, saveModel.Item_Alarm, saveModel.Item_Status, saveModel.Item_Code, saveModel.Barcode, saveModel.Item_Id);
                //edit by xiangwang0413w 2014/10/17 不再更新product_item裡的價格
                StringBuilder stb = new StringBuilder("insert into product_item (`product_id`,`spec_id_1`,`spec_id_2`,`event_product_start`,`event_product_end`,`item_stock`,`item_alarm`,`item_status`,`item_code`,`barcode`,`item_id`)");
                stb.AppendFormat(" values ({0},{1},{2},{3},{4},{5},{6},{7},'{8}','{9}',{10})", saveModel.Product_Id, saveModel.Spec_Id_1, saveModel.Spec_Id_2, saveModel.Event_Product_Start, saveModel.Event_Product_End, saveModel.Item_Stock, saveModel.Item_Alarm, saveModel.Item_Status, saveModel.Item_Code, saveModel.Barcode, saveModel.Item_Id);

                return _dbAccess.execCommand(stb.ToString());
            }
            catch (Exception ex)
            {
                throw new Exception("ProductItemDao.Save-->" + ex.Message, ex);
            }
        }