Beispiel #1
0
        /// <summary>
        /// 操作商品細項
        /// </summary>
        /// <param name="pe">需要操作的商品條件</param>
        /// <returns>操作是否成功</returns>
        public bool UpdateProductExt(List<ProductExtCustom> lists , Caller _caller,string controlId)
        {
            bool flag = true;
            IFunctionImplMgr _functionMgr = new FunctionMgr(conStr); //用於找到控件的function信息
            ITableHistoryImplMgr _tableHistoryMgr; //用於歷史記錄保存的類
            IProductExtImplMgr _productExtMgr = new ProductExtMgr(conStr);
            try
            {
                Function fun = _functionMgr.QueryFunction(controlId, "/ProductParticulars/Index");
                ArrayList aList = new ArrayList();
                _tableHistoryMgr = new TableHistoryMgr(conStr);//實例化歷史記錄的類
                HistoryBatch batch = new HistoryBatch { functionid = fun.RowId };
                Int64 n_Time = CommonFunction.GetPHPTime();
                batch.kuser = _caller.user_email;
                foreach (ProductExtCustom item in lists)
                {
                    aList.Add(pei.UpdateProductExt(item));
                    batch.batchno = n_Time + "_" + "2" + "_" + item.Product_id;//add by wwei0216w 2015/7/6 註:將item_id改為product_id 統一使用product_id查詢
                    flag = _tableHistoryMgr.SaveHistory<ProductExtCustom>(item, batch, aList);
                    if(flag == false)
                    {
                        throw new Exception("ProductExtMgr-->UpdateProductExt Exception!" );
                    }
                }

                return flag;
            }
            catch (Exception ex)
            {
                throw new Exception("ProductExtMgr-->UpdateProductExt-->" + ex.Message, ex);
            }
        }
        public HttpResponseBase ProductDown(int type = 1)
        {
            string json = "{success:true}";
            try
            {
                if (!string.IsNullOrEmpty(Request.Form["Product_Id"]))
                {
                    string[] pro_Ids = Request.Form["Product_Id"].Split('|');
                    uint product_end =0 ;
                    if (!string.IsNullOrEmpty(Request.Form["Product_End"]))
                    {
                        product_end = Convert.ToUInt32(CommonFunction.GetPHPTime(Request.Form["Product_End"]));
                    }
                    //立即下架不改變下架時間
                    //else
                    //{
                    //    product_end = Convert.ToUInt32(CommonFunction.GetPHPTime());
                    //}

                    _functionMgr = new FunctionMgr(connectionString);
                    string function = Request.Params["function"] ?? "";
                    Function fun = _functionMgr.QueryFunction(function, "/ProductList");
                    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 + "_";

                    _prodMgr = new ProductMgr(connectionString);
                    _tableHistoryMgr = new TableHistoryMgr(connectionString);
                    _productStatusHistoryMgr = new ProductStatusHistoryMgr("");
                    ProductStatusHistory proStatusHistory = new ProductStatusHistory { product_status = 6, type = 4, user_id = Convert.ToUInt32((Session["caller"] as Caller).user_id) };
                    ArrayList sqls;
                    foreach (string str in pro_Ids.Distinct())
                    {
                        if (!string.IsNullOrEmpty(str))
                        {
                            uint product_id = uint.Parse(str);
                            Product pro = _prodMgr.Query(new Product { Product_Id = product_id }).FirstOrDefault();
                            if (type == 1 && product_end == 0)//說明是立即下架,就用原來的時間
                            {
                                product_end = pro.Product_End;
                            }
                            //edit by zhuoqin0830w  2015/06/26  添加備註欄位
                            string remark = "";
                            if (pro != null && pro.Product_Status == 5)// && pro.user_id == (Session["caller"] as Caller).user_id
                            {
                                switch (type)
                                {
                                    case 1:
                                        pro.Product_Status = 6;//下架
                                        remark = Request.Form["UnShelve"]; //edit by zhuoqin0830w  2015/06/26  添加備註欄位
                                        pro.Product_End = product_end;  //將 pro.Product_End = product_end 代碼提前  避免下架不販售的時候沒有下架時間  edit by zhuoqin0830w  2015/07/15
                                        break;
                                    case 2:
                                        pro.Product_Status = 99;//下架不販售
                                        remark = Request.Form["Remark"]; //edit by zhuoqin0830w  2015/06/26  添加備註欄位
                                        IProductExtImplMgr _prodExtMgr = new ProductExtMgr(connectionString);
                                        _prodExtMgr.UpdatePendDel(product_id, true);
                                        break;
                                }

                                sqls = new ArrayList();
                                sqls.Add(_prodMgr.Update(pro));
                                batch.batchno = batchNo + pro.Product_Id;
                                proStatusHistory.product_id = product_id;
                                //edit by zhuoqin0830w  2015/06/26  添加備註欄位
                                proStatusHistory.remark = remark;
                                sqls.Add(_productStatusHistoryMgr.Save(proStatusHistory));
                                if (!_tableHistoryMgr.SaveHistory<Product>(pro, batch, sqls))
                                {
                                    json = "{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);
                json = "{success:false}";
            }
            this.Response.Clear();
            this.Response.Write(json);
            this.Response.End();
            return this.Response;
        }
        /// <summary>
        /// 查詢商品價格歷史記錄
        /// </summary>
        /// <returns></returns>
        //public ActionResult GetPricesHistory(string productID_5, string productID_6, string time_start, string time_end)
        //{
        //    int[] id_5 = (from i in productID_5.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries) select int.Parse(i)).ToArray();
        //    int[] id_6 = (from i in productID_6.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries) select int.Parse(i)).ToArray();
        //    try
        //    {
        //        IProductExtImplMgr _prodcutExt = new ProductExtMgr(connectionString);
        //        return Json(_prodcutExt.QueryHistoryInfo(new ProductExtCustom { Product_id = Convert.ToUInt32(id_5), Item_id = Convert.ToUInt32(id_6) }));
        //    }
        //    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 new EmptyResult();
        //    }
        //}


        /// <summary>
        /// 歷史記錄匯出方法
        /// </summary>
        /// <returns></returns>
        public ActionResult HistoryExcel(string productID_5, string productID_6, string time_start, string time_end, int brand_id = 0)
        {
            try
            {
                string xmlPath = "../XML/ProductItemHistory.xml";

                IProductExtImplMgr _productExtMgr = new ProductExtMgr(connectionString);
                ProductExtCustom pe = new ProductExtCustom { Product_id = 12306 };

                int[] id_5 = (from i in productID_5.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries) select int.Parse(i)).ToArray();
                int[] id_6 = (from i in productID_6.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries) select int.Parse(i)).ToArray();
                string productIds = string.Join(",", id_5);
                string itemIds = string.Join(",", id_6);

                MemoryStream ms = _productExtMgr.OutToExcel(Server.MapPath(xmlPath), Convert.ToInt64(time_start), Convert.ToInt64(time_end), brand_id, itemIds, productIds);
                if (ms == null)
                {
                    return new EmptyResult();
                }
                return File(ms.ToArray(), "application/-excel", DateTime.Now.ToString("yyyyMMddhhmmss") + ".xls");
            }
            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 new EmptyResult();
            }
        }
 /// <summary>
 /// 查詢商品細項歷史記錄
 /// </summary>
 /// <returns></returns>
 public ActionResult GetParticularsHistory(string productID_5, string productID_6, string time_start, string time_end, int brand_id = 0)
 {
     int[] id_5 = (from i in productID_5.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries) select int.Parse(i)).ToArray();
     int[] id_6 = (from i in productID_6.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries) select int.Parse(i)).ToArray();
     string productIds = string.Join(",", id_5);
     string itemIds = string.Join(",", id_6);
     Int64 timeStartPHP = time_start == "" ? 0 : Convert.ToInt64(time_start);
     Int64 timeEndPHP = time_end == "" ? 0 : Convert.ToInt64(time_end);
     try
     {
         IProductExtImplMgr _prodcutExt = new ProductExtMgr(connectionString);
         return Json(_prodcutExt.QueryHistoryInfo(timeStartPHP, timeEndPHP, brand_id, itemIds, productIds));
     }
     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 new EmptyResult();
     }
 }
 public JsonResult GetItemDate()
 {
     string result = "false";
     string ReturnDate = "";
     try
     {
         int item_id = 0;
         DateTime returnDate;
         DateTime date =Convert.ToDateTime(Request.Params["date"]);
         string dateType = Request.Params["dateType"];
         if(!int.TryParse(Request.Params["item_id"],out item_id)){
             return Json(new { success = result, date = ReturnDate });
         }
         IProductExtImplMgr productExt = new ProductExtMgr(mySqlConnectionString);
         int Cde_dt_incr = productExt.GetCde_dt_incr(item_id);
         if (dateType == "made")
         {
             returnDate = date.AddDays(Cde_dt_incr);
         }
         else {
             returnDate = date.AddDays(-Cde_dt_incr);
         }
         ReturnDate = returnDate.ToString("yyyy - MM - dd");
         result = "ture";
     }
     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 = result,date=ReturnDate });
 }
        public HttpResponseBase SaveIinvd()
        {
            string json = "{success:false,message:'系統異常'}";
            try
            {
                int temp = 0;
                if (int.TryParse(Request.Params["prod_qty"], out temp))
                {
                    if (temp > 0)
                    {
                        IinvdQuery iinvd = new IinvdQuery();
                        if (!string.IsNullOrEmpty(Request.Params["loc_id"]))
                        {
                            iinvd.plas_loc_id = Request.Params["loc_id"];
                        }
                        if (!string.IsNullOrEmpty(Request.Params["item_id"]))
                        {
                            if (int.TryParse(Request.Params["item_id"], out temp))
                            {
                                iinvd.item_id = uint.Parse(Request.Params["item_id"]);
                            }
                        }

                        #region 判斷是否指定主料位
                        IlocQuery ilocquery = new IlocQuery();
                        _IiplasMgr = new IplasMgr(mySqlConnectionString);
                        IplasQuery iplasquery = new IplasQuery();
                        iplasquery.item_id = iinvd.item_id;
                        IIlocImplMgr ilocMgr = new IlocMgr(mySqlConnectionString);
                        IplasDao iplasdao = new IplasDao(mySqlConnectionString);
                        int total = 0;
                        ilocquery.loc_id = iinvd.plas_loc_id;
                        ilocquery.lcat_id = "0";
                        ilocquery.lsta_id = "";
                        ilocquery.IsPage = false;
                        List<IlocQuery> listiloc = ilocMgr.GetIocList(ilocquery, out total);
                        if (listiloc.Count > 0)
                        {
                            string lcat_id = listiloc.Count == 0 ? "" : listiloc[0].lcat_id;
                            if (lcat_id == "S")
                            {
                                string item_id = iplasdao.Getlocid(ilocquery.loc_id);
                                if (item_id == "")
                                {
                                    Iplas iplas = new Iplas();
                                    if (int.TryParse(Request.Params["item_id"], out temp))
                                    {
                                        iplas.item_id = uint.Parse(Request.Params["item_id"]);
                                        if (_IiplasMgr.IsTrue(iplas) == "false")
                                        {
                                            json = "{success:false,message:'不存在該商品編號'}";
                                            this.Response.Clear();
                                            this.Response.Write(json);
                                            this.Response.End();
                                            return this.Response;
                                        }
                                        if (_IiplasMgr.GetIplasid(iplasquery) > 0)
                                        {
                                            json = "{success:false,message:'此商品主料位非該料位'}";
                                            this.Response.Clear();
                                            this.Response.Write(json);
                                            this.Response.End();
                                            return this.Response;
                                        }
                                        Iloc iloc = new Iloc();
                                        iloc.loc_id = iinvd.plas_loc_id;
                                        if (_IiplasMgr.GetLocCount(iloc) <= 0)
                                        {
                                            json = "{success:false,message:'該料位已鎖定或被指派'}";
                                            this.Response.Clear();
                                            this.Response.Write(json);
                                            this.Response.End();
                                            return this.Response;
                                        }
                                        iplas.loc_id = iloc.loc_id;
                                        iplas.loc_stor_cse_cap = 100;
                                        iplas.create_user = (Session["caller"] as Caller).user_id;
                                        iplas.create_dtim = DateTime.Now;
                                        iplas.change_user = (Session["caller"] as Caller).user_id;
                                        iplas.change_dtim = DateTime.Now;
                                        _IiplasMgr.InsertIplas(iplas);
                                    }
                                }
                            }
                        }
                        #endregion
                        iinvd.create_user = (Session["caller"] as Caller).user_id;
                        iinvd.create_dtim = DateTime.Now;
                        iinvd.change_user = iinvd.create_user;
                        iinvd.change_dtim = iinvd.create_dtim;
                        iinvd.ista_id = "A";
                        if (!string.IsNullOrEmpty(Request.Params["loc_id"]))
                        {
                            iinvd.plas_loc_id = Request.Params["loc_id"];
                        }
                        int change_prod_qty = int.Parse(Request.Params["prod_qty"]);
                        iinvd.prod_qty = change_prod_qty;
                        if (!string.IsNullOrEmpty(Request.Params["st_qty"]))
                        {
                            if (int.TryParse(Request.Params["st_qty"], out temp))
                            {
                                iinvd.st_qty = int.Parse(Request.Params["st_qty"]);
                            }
                        }
                        if (!string.IsNullOrEmpty(Request.Params["item_id"]))
                        {
                            if (int.TryParse(Request.Params["item_id"], out temp))
                            {
                                iinvd.item_id = uint.Parse(Request.Params["item_id"]);
                            }
                        }
                        DateTime date = DateTime.Now;
                        if (DateTime.TryParse(Request.Params["datetimepicker1"], out date))
                        {
                            iinvd.made_date = date;
                        }
                        else
                        {
                            iinvd.made_date = DateTime.Now;
                        }
                        _iinvd = new IinvdMgr(mySqlConnectionString);
                        if (Request.Params["pwy_dte_ctl"] == "Y")
                        {
                            iinvd.pwy_dte_ctl = "Y";
                            IProductExtImplMgr productExt = new ProductExtMgr(mySqlConnectionString);
                            int Cde_dt_incr = productExt.GetCde_dt_incr((int)iinvd.item_id);
                            iinvd.cde_dt = date.AddDays(Cde_dt_incr);
                        }
                        else
                        {
                            iinvd.cde_dt = DateTime.Now;
                        }
                        iinvd.prod_qtys = _iinvd.GetProd_qty(Convert.ToInt32(iinvd.item_id), iinvd.plas_loc_id, "", iinvd.row_id.ToString());
                        IialgQuery iialg = new IialgQuery();
                        iialg.cde_dt = iinvd.cde_dt;
                        int prod_qty = 0;// _iinvd.GetProd_qty((int)iinvd.item_id, iinvd.plas_loc_id, "", "");
                        int row = _iinvd.GetIinvdCount(iinvd);
                        if (row > 1)
                        {
                            prod_qty = row - 1;
                            json = "{success:true}";
                        }
                        else
                        {
                            if (_iinvd.Insert(iinvd) == 1)
                            {
                                json = "{success:true}";
                            }
                        }
                        
                        iialg.qty_o = prod_qty;
                        iialg.loc_id = iinvd.plas_loc_id;
                        iialg.item_id = iinvd.item_id;
                        iialg.iarc_id = "循環盤點";
                        iialg.adj_qty = change_prod_qty;
                        iialg.create_dtim = DateTime.Now;
                        iialg.create_user = iinvd.create_user;
                        iialg.type = 2;
                        iialg.doc_no = "C" + DateTime.Now.ToString("yyyyMMddHHmmss");
                        iialg.made_dt = iinvd.made_date;
                        iialg.cde_dt = iinvd.cde_dt;
                        _iialgMgr = new IialgMgr(mySqlConnectionString);
                        _iialgMgr.insertiialg(iialg);

                        IstockChangeQuery istock = new IstockChangeQuery();
                        istock.sc_trans_id = iialg.doc_no;
                        istock.item_id = iinvd.item_id;
                        istock.sc_istock_why = 2;
                        istock.sc_trans_type = 2;
                        istock.sc_num_old = iinvd.prod_qtys;
                        istock.sc_num_chg = iialg.adj_qty;
                        istock.sc_num_new = _iinvd.GetProd_qty((int)iinvd.item_id, iinvd.plas_loc_id,"N","");
                        istock.sc_time = iinvd.create_dtim;
                        istock.sc_user = iinvd.create_user;
                        istock.sc_note = "循環盤點";
                        IstockChangeMgr istockMgr = new IstockChangeMgr(mySqlConnectionString);
                        istockMgr.insert(istock);
                    }
                    else
                    {
                        json = "{success:false,message:'庫存不能小於1'}";
                    }
                }
                else
                {                  
                    json = "{success:false,message:'庫存請輸入數字'}";
                }
            }
            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;
        }