//商品指定主料位-互搬
        public HttpResponseBase IplasUploadExcelEnter()
        {
            string newName = string.Empty;
            string json = string.Empty;
            List<IplasQuery> store = new List<IplasQuery>();
            try
            {

                DTIplasEnterExcel.Clear();
                DTIplasEnterExcel.Columns.Clear();

                DTIplasEnterExcel.Columns.Add("商品細項編號", typeof(String));
                DTIplasEnterExcel.Columns.Add("原料位", typeof(String));
                DTIplasEnterExcel.Columns.Add("新料位", typeof(String));
                DTIplasEnterExcel.Columns.Add("不能搬移的原因", typeof(String));
                int result = 0;
                int count = 0;//總匯入數
                int errorcount = 0;//數據異常個數
                int comtentcount = 0;//內容不符合格式
                int create_user = (Session["caller"] as Caller).user_id;
                int item_idcount = 0;//商品細項編號不存在
                int item_id_have_locid = 0;//商品細項編號已存在主料位
                int locid_lock = 0;//商品料位已經被鎖定
                StringBuilder strsql = new StringBuilder();
                if (Request.Files["IplasImportExcelFile"] != null && Request.Files["IplasImportExcelFile"].ContentLength > 0)
                {
                    HttpPostedFileBase excelFile = Request.Files["IplasImportExcelFile"];
                    //FileManagement fileManagement = new FileManagement();
                    newName = Server.MapPath(excelPath) + excelFile.FileName;
                    excelFile.SaveAs(newName);
                    DataTable dt = new DataTable();
                    NPOI4ExcelHelper helper = new NPOI4ExcelHelper(newName);
                    dt = helper.SheetData();

                    if (dt.Rows.Count > 0)
                    {
                        _IiplasMgr = new IplasMgr(mySqlConnectionString);



                        #region 測試
                        #region 循環Excel的數據
                        Iloc ic = new BLL.gigade.Model.Iloc();
                        Iplas ips = new Iplas();
                        int i = 0;
                        if (dt.Columns.Count < 3)
                        {
                            DataRow drtwo = DTIplasEnterExcel.NewRow();
                            drtwo[0] = "這個是商品細項編號";
                            drtwo[1] = "這個是商品原料位";
                            drtwo[2] = "這個是商品新料位";
                            drtwo[3] = "請匯入足夠的列數";
                            DTIplasEnterExcel.Rows.Add(drtwo);
                            errorcount++;
                        }
                        else
                        {
                            foreach (DataRow dr in dt.Rows)
                            {
                                if (string.IsNullOrEmpty(dr[0].ToString()) && string.IsNullOrEmpty(dr[1].ToString()) && string.IsNullOrEmpty(dr[2].ToString()))
                                {
                                    continue;
                                }

                                i++;
                                try
                                {
                                    if (!string.IsNullOrEmpty(dr[0].ToString()) && Regex.IsMatch(dr[0].ToString(), @"^\d{6}$") && !string.IsNullOrEmpty(dr[1].ToString()) && Regex.IsMatch(dr[1].ToString(), @"^[A-Z]{2}\d{3}[A-Z]\d{2}$") && !string.IsNullOrEmpty(dr[2].ToString()) && Regex.IsMatch(dr[2].ToString(), @"^[A-Z]{2}\d{3}[A-Z]\d{2}$"))
                                    {
                                        ic.loc_id = dr[2].ToString();
                                        //ic.lsta_id = "F";
                                        //ic.lcat_id = "S";
                                        //ic.create_dtim = DateTime.Now;
                                        //ic.change_dtim = DateTime.Now;
                                        //ic.create_user = 2;
                                        //ic.change_user = 2;
                                        //ic.loc_status = 1;
                                        ips.item_id = Convert.ToUInt32(dr[0]);
                                        ips.loc_id = dr[1].ToString();


                                        //根據商品編號查看是否存在主料位
                                        int item_id_exsit = _IiplasMgr.YesOrNoExist(Convert.ToInt32(dr[0]));//檢查item_id是否存在
                                        int loc_id_exsit = _IiplasMgr.YesOrNoLocIdExsit(dr[1].ToString());//判斷原料位是否存在
                                        int item_loc_id = _IiplasMgr.YesOrNoLocIdExsit(Convert.ToInt32(dr[0]), dr[1].ToString());//判斷原料位是否為該商品的主料位
                                        int New_loc_id_exsit = _IiplasMgr.YesOrNoLocIdExsit(dr[2].ToString());//判斷新料位是否存在
                                        int loc_id_lock = _IiplasMgr.GetLocCount(ic);//判斷新料位是否鎖定

                                        if (_IiplasMgr.IsTrue(ips) == "false")//首先判斷item_id是否存在
                                        {
                                            DataRow drtwo = DTIplasEnterExcel.NewRow();
                                            drtwo[0] = dr[0].ToString();
                                            drtwo[1] = dr[1].ToString();
                                            drtwo[2] = dr[2].ToString();
                                            drtwo[3] = "商品細項編號不存在";
                                            DTIplasEnterExcel.Rows.Add(drtwo);
                                            errorcount++;
                                            item_idcount++;
                                            continue;
                                        }
                                        else//如果存在item_id
                                        {
                                            if (loc_id_exsit <= 0)//表示原料為不存在料位//------------------------------
                                            {
                                                DataRow drtwo = DTIplasEnterExcel.NewRow();
                                                drtwo[0] = dr[0].ToString();
                                                drtwo[1] = dr[1].ToString();
                                                drtwo[2] = dr[2].ToString();
                                                drtwo[3] = "商品原料位不存在";
                                                DTIplasEnterExcel.Rows.Add(drtwo);
                                                errorcount++;
                                                locid_lock++;
                                                continue;
                                            }
                                            if (item_loc_id <= 0)//表示原料位不是此商品的原料位//------------------------------
                                            {
                                                DataRow drtwo = DTIplasEnterExcel.NewRow();
                                                drtwo[0] = dr[0].ToString();
                                                drtwo[1] = dr[1].ToString();
                                                drtwo[2] = dr[2].ToString();
                                                drtwo[3] = "原料位不是此商品的料位";
                                                DTIplasEnterExcel.Rows.Add(drtwo);
                                                errorcount++;
                                                locid_lock++;
                                                continue;
                                            }
                                            if (New_loc_id_exsit <= 0)//表示新料位不存在//------------------------------
                                            {
                                                DataRow drtwo = DTIplasEnterExcel.NewRow();
                                                drtwo[0] = dr[0].ToString();
                                                drtwo[1] = dr[1].ToString();
                                                drtwo[2] = dr[2].ToString();
                                                drtwo[3] = "新料位不存在";
                                                DTIplasEnterExcel.Rows.Add(drtwo);
                                                errorcount++;
                                                item_id_have_locid++;
                                                continue;
                                            }
                                            else
                                            {
                                                if (loc_id_lock > 0)//如果新料位存在並且沒有被鎖定--plas新增,iloc更改狀態
                                                {

                                                    ips = _IiplasMgr.getplas(ips);
                                                    ips.loc_id = dr[2].ToString();
                                                    ips.change_user = (Session["caller"] as Caller).user_id;
                                                    ips.change_dtim = DateTime.Now;
                                                    ips.item_id = Convert.ToUInt32(dr[0]);
                                                    if (_IiplasMgr.UpIplas(ips) > 0)
                                                    {
                                                        strsql.Append(ips.loc_id);

                                                        //strsql.AppendFormat("Insert into iplas (dc_id,whse_id,loc_id,change_dtim,change_user,create_dtim,create_user,lcus_id,luis_id,item_id,prdd_id,loc_rpln_lvl_uoi,loc_stor_cse_cap,ptwy_anch,flthru_anch,pwy_loc_cntl) Values ('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}','{14}','{15}');", ips.dc_id, ips.whse_id, ips.loc_id.ToString().ToUpper(), CommonFunction.DateTimeToString(ips.change_dtim), ips.change_user, CommonFunction.DateTimeToString(ips.create_dtim), ips.create_user, ips.lcus_id, ips.luis_id, ips.item_id, ips.prdd_id, ips.loc_rpln_lvl_uoi, ips.loc_stor_cse_cap, ips.ptwy_anch, ips.flthru_anch, ips.pwy_loc_cntl);//插入數據到表iplas表中
                                                        //strsql.AppendFormat(@" set sql_safe_updates = 0; update iloc set lsta_id='{0}',change_user='******',change_dtim='{2}' where loc_id='{3}';set sql_safe_updates = 1; ", "A", ips.change_user, BLL.gigade.Common.CommonFunction.DateTimeToString(ips.change_dtim), ips.loc_id.ToString().ToUpper());
                                                        count++;
                                                        result++;
                                                    }
                                                    else
                                                    {
                                                        DataRow drtwo = DTIplasEnterExcel.NewRow();
                                                        drtwo[0] = dr[0].ToString();
                                                        drtwo[1] = dr[1].ToString();
                                                        drtwo[2] = dr[2].ToString();
                                                        drtwo[3] = "未知原因導入失敗";
                                                        DTIplasEnterExcel.Rows.Add(drtwo);
                                                        errorcount++;
                                                        continue;
                                                    }
                                                }
                                                else
                                                {
                                                    DataRow drtwo = DTIplasEnterExcel.NewRow();
                                                    drtwo[0] = dr[0].ToString();
                                                    drtwo[1] = dr[1].ToString();
                                                    drtwo[2] = dr[2].ToString();
                                                    drtwo[3] = "新料位已經被鎖定或非主料位";
                                                    DTIplasEnterExcel.Rows.Add(drtwo);
                                                    errorcount++;
                                                    item_id_have_locid++;
                                                    continue;
                                                }
                                            }


                                        }
                                    }
                                    else
                                    {
                                        DataRow drtwo = DTIplasEnterExcel.NewRow();
                                        drtwo[0] = dr[0].ToString();
                                        drtwo[1] = dr[1].ToString();
                                        drtwo[2] = dr[2].ToString();
                                        drtwo[3] = "商品細項編號或者料位不符合格式";
                                        DTIplasEnterExcel.Rows.Add(drtwo);
                                        errorcount++;
                                        comtentcount++;
                                        continue;
                                    }
                                }
                                catch
                                {
                                    DataRow drtwo = DTIplasEnterExcel.NewRow();
                                    drtwo[0] = dr[0].ToString();
                                    drtwo[1] = dr[1].ToString();
                                    drtwo[2] = dr[2].ToString();
                                    drtwo[3] = "數據異常";
                                    DTIplasEnterExcel.Rows.Add(drtwo);
                                    errorcount++;
                                    continue;
                                }
                            }
                        }
                        #endregion


                        #endregion

                        if (strsql.ToString().Trim() != "")
                        {
                            //result = _IiplasMgr.ExcelImportIplas(strsql.ToString());
                            if (result > 0)
                            {
                                json = "{success:true,total:" + count + ",error:" + errorcount + ",item_idcount:" + item_idcount + ",item_id_have_locid:" + item_id_have_locid + ",comtentcount:" + comtentcount + ",locid_lock:" + locid_lock + "}";
                            }
                            else
                            {
                                json = "{success:false}";
                            }
                        }
                        else
                        {
                            json = "{success:true,total:" + 0 + ",error:" + errorcount + ",item_idcount:" + item_idcount + ",item_id_have_locid:" + item_id_have_locid + ",comtentcount:" + comtentcount + ",locid_lock:" + locid_lock + "}";
                        }
                    }
                    else
                    {
                        json = "{success:true,total:" + 0 + ",error:" + errorcount + ",item_idcount:" + item_idcount + ",item_id_have_locid:" + item_id_have_locid + ",comtentcount:" + comtentcount + ",locid_lock:" + locid_lock + "}";
                    }
                }
            }
            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,data:" + "" + "}";
            }
            this.Response.Clear();
            this.Response.Write(json);
            this.Response.End();
            return this.Response;
        }
        public HttpResponseBase GetIPlasEdit()
        {
            string json = string.Empty;
            IplasQuery iplas = new IplasQuery();
            Iloc iloc = new Iloc();
            Iupc upc = new Iupc();
            _IiplasMgr = new IplasMgr(mySqlConnectionString);
            _IlocMgr = new IlocMgr(mySqlConnectionString);
            _ipalet = new PalletMoveMgr(mySqlConnectionString);
            try
            {
                if (string.IsNullOrEmpty(Request.Params["plas_id"]))//首先考慮添加情況
                {
                    string itemid = Request.Params["item_id"];
                    DataTable dt = _ipalet.GetProdInfo(itemid);
                    if (dt.Rows.Count > 0)
                    {
                        iplas.item_id = uint.Parse(dt.Rows[0]["item_id"].ToString());
                    }
                    else
                    {
                        iplas.item_id = 0;
                    }
                    if (_IiplasMgr.IsTrue(iplas) == "false")
                    {
                        json = "{success:false,msg:\"" + "商品編號不存在" + "\"}";
                        this.Response.Clear();
                        this.Response.Write(json);
                        this.Response.End();
                        return this.Response;
                    }
                    if (_IiplasMgr.GetIplasid(iplas) > 0)
                    {
                        json = "{success:false,msg:\"" + "此商品已存在主料位" + "\"}";
                        this.Response.Clear();
                        this.Response.Write(json);
                        this.Response.End();
                        return this.Response;
                    }
                    iloc.loc_id = Request.Params["loc_id"].ToString().ToUpper();
                    if (_IiplasMgr.GetLocCount(iloc) <= 0)
                    {
                        json = "{success:false,msg:\"" + "非主料位或主料位已鎖定" + "\"}";
                        this.Response.Clear();
                        this.Response.Write(json);
                        this.Response.End();
                        return this.Response;
                    }
                    iplas.loc_id = Request.Params["loc_id"].ToString().ToUpper();
                    if (_IiplasMgr.GetIplasCount(iplas).Count > 0)//主料位重複
                    {
                        json = "{success:false,msg:\"" + "主料位重複" + "\"}";
                        this.Response.Clear();
                        this.Response.Write(json);
                        this.Response.End();
                        return this.Response;
                    }
                    iplas.loc_stor_cse_cap = int.Parse(Request.Params["loc_stor_cse_cap"]);
                    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);//判斷主料位和商品編號沒有問題,插入Iplas表的同時.操作iloc表,設置其為已指派料位
                    json = "{success:true}";
                }
                else//編輯
                {
                    iplas.plas_id = int.Parse(Request.Params["plas_id"]);
                    upc.upc_id = Request.Params["upcid"];
                    iplas.item_id = uint.Parse(Request.Params["item_id"]);
                    iplas.loc_id = Request.Params["loc_id"].ToString().ToUpper();
                    iloc.loc_id = iplas.loc_id;
                    if (_IiplasMgr.GetLocCount(iloc) <= 0)
                    {
                        json = "{success:false,msg:\"" + "非主料位或主料位已鎖定" + "\"}";
                        this.Response.Clear();
                        this.Response.Write(json);
                        this.Response.End();
                        return this.Response;
                    }
                    if (_IiplasMgr.GetIplasCount(iplas).Count > 0)//主料位重複
                    {
                        json = "{success:false,msg:\"" + "該主料位不可用!" + "\"}";
                        this.Response.Clear();
                        this.Response.Write(json);
                        this.Response.End();
                        return this.Response;
                    }
                    iplas.loc_stor_cse_cap = int.Parse(Request.Params["loc_stor_cse_cap"]);
                    iplas.change_user = (Session["caller"] as Caller).user_id;
                    iplas.change_dtim = DateTime.Now;
                    _IiplasMgr.UpIplas(iplas);
                    json = "{success:true}";
                }
            }
            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;
        }