public List<ProductItemMap> QueryAll(ProductItemMap p)
        {

            try
            {
                return _ProductItemMapDao.QueryAll(p);
            }
            catch (Exception ex)
            {
                throw new Exception("ProductItemMapMgr-->QueryAll-->" + ex.Message, ex);
            }
        }
 public string DeleteProductMap()
 {
     ProductItemMap p = new ProductItemMap();
     p.rid = UInt32.Parse(Request.Form["rid"]);
     p.channel_detail_id = Request.Form["pno"];
     p.channel_id = UInt32.Parse(Request.Form["cid"]);
     _ProductItemMapMgr = new ProductItemMapMgr(connectionString);
     int rows = _ProductItemMapMgr.Delete(p);
     if (rows == -1)
     {
         jsonStr = "{success:false,rpackCode:'" + Resources.ProductItemMap.EXIST_DELETE_FAIL + "'}";
     }
     else
     {
         jsonStr = "{success:true,rpackCode:'" + Resources.ProductItemMap.DELETE_SUCCESS + "'}";
     }
     return jsonStr;
 }
 public HttpResponseBase GroupQuery()
 {
     string result = "{success:false}";
     try
     {
         uint pid = uint.Parse(Request.Params["ProductId"] ?? "0");
         uint channel_id = uint.Parse(Request.Params["cId"] ?? "0");
         uint pmId = uint.Parse(Request.Params["pmId"] ?? "0");
         ProductItemMapMgr _mapMgr = new ProductItemMapMgr(connectionString);
         _ProductItemMapExcelImplMgr = new ProductItemMapExcelMgr(connectionString);
         List<BLL.gigade.Model.Custom.ProductMapCustom> resultList = _mapMgr.CombinationQuery(new ProductItemMapCustom { product_id = pid });
         int pileCount = resultList.LastOrDefault().pile_id;
         if (resultList.Count() > 0)
         {
             List<List<ProductComboMap>> itemAll = new List<List<ProductComboMap>>();
             List<ProductComboMap> itemList = new List<ProductComboMap>();
             for (int i = 0, j = resultList.Count(); i < j; i++)
             {
                 itemList.Add(_mapMgr.ProductComboItemQuery(int.Parse(resultList[i].child_id.ToString()), int.Parse(pid.ToString())).FirstOrDefault());
             }
             for (int Pi = 1; Pi <= pileCount; Pi++)
             {
                 itemAll.Add(itemList.Where(e => e.pile_id == Pi).ToList());
             }
             string s = "";
             getCombo(0, itemAll, "", ref s);
             s = s.Substring(0, s.Length - 1);
             string strb = "[";
             if (!string.IsNullOrEmpty(s))
             {
                 for (int Si = 0, Sj = s.Split('&').Length; Si < Sj; Si++)
                 {
                     ProductItemMap _productitemmap = new ProductItemMap();
                     _productitemmap.product_id = pid;
                     _productitemmap.channel_id = channel_id;
                     _productitemmap.price_master_id = pmId;//edit by xiangwang0413w 2014/07/07
                     _productitemmap.group_item_id = CommonFunction.Rank_ItemId(s.Split('&')[Si].ToString());
                     _productitemmap = _ProductItemMapExcelImplMgr.QueryProductItemMap(_productitemmap).FirstOrDefault();
                     strb += "{";
                     for (int Li = 0, Lj = s.Split('&')[Si].Split(',').Length; Li < Lj; Li++)
                     {
                         uint ItemStr = uint.Parse(s.Split('&')[Si].Split(',')[Li].ToString());
                         string product_name = itemAll[Li].Where(e => e.item_id == ItemStr).FirstOrDefault().product_name;
                         string spec_name_1 = itemAll[Li].Where(e => e.item_id == ItemStr).FirstOrDefault().spec_name_1;
                         string spec_name_2 = itemAll[Li].Where(e => e.item_id == ItemStr).FirstOrDefault().spec_name_2;
                         string set_num = itemAll[Li].Where(e => e.item_id == ItemStr).FirstOrDefault().set_num.ToString();
                         strb += "item_id_" + (Li + 1).ToString() + ":" + s.Split('&')[Si].Split(',')[Li].ToString() + ",product_name_" + (Li + 1).ToString() + ":'" + product_name + (spec_name_1 != "" ? "(" + spec_name_1 + " " + spec_name_2 + ")" : "") + "',product_num_" + (Li + 1).ToString() + ":" + set_num;
                         if (Li != Lj - 1)
                         {
                             strb += ",";
                         }
                     }
                     strb += ",group_item_id:'" + BLL.gigade.Common.CommonFunction.Rank_ItemId(s.Split('&')[Si].ToString()) + "'";
                     if (_productitemmap != null)
                     {
                         strb += ",rid:" + _productitemmap.rid + ",product_name:'" + _productitemmap.product_name + "',channel_detail_id:'" + _productitemmap.channel_detail_id + "',product_cost:" + _productitemmap.product_cost + ",product_price:" + _productitemmap.product_price;
                     }
                     else
                     {
                         strb += ",product_name:'',channel_detail_id:'',product_cost:'',product_price:''";
                     }
                     strb += "}";
                     if (Si != Sj - 1)
                     {
                         strb += ",";
                     }
                 }
             }
             strb += "]";
             result = "{success:true,data:" + strb + "}";
         }
     }
     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);
     }
     this.Response.Clear();
     this.Response.Write(result);
     this.Response.End();
     return this.Response;
 }
        public HttpResponseBase OptionalQuery()
        {
            string result = "{success:false}";
            try
            {
                uint pid = uint.Parse(Request.Params["ProductId"] ?? "0");
                uint channel_id = uint.Parse(Request.Params["cId"] ?? "0");
                uint pmId = uint.Parse(Request.Form["pmId"] ?? "0");
                string type = Request.Params["type"] ?? "";
                if (pid != 0)
                {
                    ProductMapSetMgr _mapsetMgr = new ProductMapSetMgr(connectionString);
                    ProductItemMapMgr _mapMgr = new ProductItemMapMgr(connectionString);
                    _ProductItemMapExcelImplMgr = new ProductItemMapExcelMgr(connectionString);
                    List<BLL.gigade.Model.Custom.ProductMapCustom> resultList = _mapMgr.CombinationQuery(new ProductItemMapCustom { product_id = pid });
                    //查詢是否已經建立過對照
                    List<BLL.gigade.Model.ProductMapSet> maplist = _mapsetMgr.Query(pid);
                    List<ProductComboMap> itemAll = new List<ProductComboMap>();
                    for (int i = 0, j = resultList.Count(); i < j; i++)
                    {
                        itemAll.Add(_mapMgr.ProductComboItemQuery(int.Parse(resultList[i].child_id.ToString()), int.Parse(pid.ToString())).FirstOrDefault());
                    }
                    //獲取任選中是否有必選單位 hufeng0813w
                    string str_must_itemId = "";
                    for (int i = 0, j = itemAll.Count; i < j; i++)
                    {
                        if (itemAll[i].set_num > 0)
                        {
                            if (str_must_itemId != "")
                            {
                                str_must_itemId += ",";
                            }
                            str_must_itemId += itemAll[i].item_id;
                        }
                    }
                    str_must_itemId = CommonFunction.Rank_ItemId(str_must_itemId);
                    string optional = "";
                    string StrOptional = "";

                    #region 僅限一單位勾選
                    if (resultList[0].buy_limit == 1)
                    {
                        //遞歸獲取所有的組合
                        GetOptional(0, itemAll, "", ref optional, 0, itemAll[0].g_must_buy);
                        optional = optional.Substring(0, optional.Length - 2).Replace(",&", "&");
                        //進行必選的篩選 hufeng0813w
                        if (str_must_itemId != "")
                        {
                            optional = CheckHas(optional, str_must_itemId);
                        }
                        StrOptional = "[";
                        if (!string.IsNullOrEmpty(optional))
                        {
                            for (int i = 0, Li = optional.Split('&').Length; i < Li; i++)
                            {
                                if (StrOptional != "" && i != 0)
                                {
                                    StrOptional += ",";
                                }
                                ProductItemMap _productitemmap = new ProductItemMap();
                                _productitemmap.product_id = pid;
                                _productitemmap.channel_id = channel_id;
                                _productitemmap.price_master_id = pmId;//edit by xiangwang0413w 2014/07/02
                                _productitemmap.group_item_id = CommonFunction.Rank_ItemId(optional.Split('&')[i].ToString());
                                _productitemmap = _ProductItemMapExcelImplMgr.QueryProductItemMap(_productitemmap).FirstOrDefault();
                                StrOptional += "{";
                                for (int j = 0, Lj = optional.Split('&')[i].Split(',').Length; j < Lj; j++)
                                {
                                    string product_name = itemAll.Where(e => e.item_id == uint.Parse(optional.Split('&')[i].Split(',')[j])).FirstOrDefault().product_name;
                                    string spec_name_1 = itemAll.Where(e => e.item_id == uint.Parse(optional.Split('&')[i].Split(',')[j])).FirstOrDefault().spec_name_1;
                                    string spec_name_2 = itemAll.Where(e => e.item_id == uint.Parse(optional.Split('&')[i].Split(',')[j])).FirstOrDefault().spec_name_2;
                                    //先判斷是否已經建立對照 
                                    string set_num = maplist.Count == 0 ? itemAll.Where(e => e.item_id == uint.Parse(optional.Split('&')[i].Split(',')[j])).FirstOrDefault().set_num.ToString()
                                        : (maplist.Where(e => e.item_id == uint.Parse(optional.Split('&')[i].Split(',')[j]) && e.map_rid == (_productitemmap == null ? 0 : _productitemmap.rid)).FirstOrDefault() == null ? itemAll.Where(e => e.item_id == uint.Parse(optional.Split('&')[i].Split(',')[j])).FirstOrDefault().set_num.ToString()
                                        : maplist.Where(e => e.item_id == uint.Parse(optional.Split('&')[i].Split(',')[j]) && e.map_rid == (_productitemmap == null ? 0 : _productitemmap.rid)).FirstOrDefault().set_num.ToString());
                                    string s_must_buy = itemAll.Where(e => e.item_id == uint.Parse(optional.Split('&')[i].Split(',')[j])).FirstOrDefault().set_num.ToString();//必選數量
                                    StrOptional += "item_id_" + (j + 1).ToString() + ":" + optional.Split('&')[i].Split(',')[j].ToString() + ",product_name_" + (j + 1).ToString() + ":'" + product_name + (spec_name_1 != "" ? "(" + spec_name_1 + " " + spec_name_2 + ")" : "") + "',product_num_" + (j + 1).ToString() + ":" + set_num + ",s_must_buy_" + (j + 1) + ":" + s_must_buy;
                                    if (j != Lj - 1)
                                    {
                                        StrOptional += ",";
                                    }
                                }

                                StrOptional += ",group_item_id:'" + BLL.gigade.Common.CommonFunction.Rank_ItemId(optional.Split('&')[i].ToString()) + "'";
                                if (_productitemmap != null)
                                {
                                    StrOptional += ",rid:" + _productitemmap.rid + ",product_name:'" + _productitemmap.product_name + "',channel_detail_id:'" + _productitemmap.channel_detail_id + "',product_cost:" + _productitemmap.product_cost + ",product_price:" + _productitemmap.product_price;
                                }
                                else
                                {
                                    StrOptional += ",product_name:'',channel_detail_id:'',product_cost:'',product_price:''";
                                }
                                StrOptional += "}";
                            }
                        }
                        StrOptional += "]";
                    }
                    #endregion

                    #region 僅限一單位不勾選
                    else
                    {
                        //不是必須所有item_id 都需要拼接上 add by hufeng0813w 2014/03/31
                        for (int i = 0, j = itemAll.Count; i < j; i++)
                        {
                            if (i != 0)
                            {
                                optional += ",";
                            }
                            optional += itemAll[i].item_id;
                        }
                        //end add by hufeng0813w 2014/03/31
                        ProductItemMap _pitemMap = new ProductItemMap();
                        _pitemMap.product_id = pid;
                        _pitemMap.channel_id = channel_id;
                        _pitemMap.price_master_id = pmId;//edit by xiangwang0413w 2014/07/02
                        List<ProductItemMap> _listPitemMap = _mapMgr.QueryOldItemMap(_pitemMap);

                        #region 查詢最初的商品信息
                        if (type == "searchInfo")
                        {
                            StrOptional = "[";
                            if (!string.IsNullOrEmpty(optional))
                            {
                                for (int i = 0, Li = optional.Split('&').Length; i < Li; i++)
                                {
                                    if (StrOptional != "" && i != 0)
                                    {
                                        StrOptional += ",";
                                    }
                                    ProductItemMap _productitemmap = new ProductItemMap();
                                    _productitemmap.product_id = pid;
                                    _productitemmap.channel_id = channel_id;
                                    _productitemmap.price_master_id = pmId;//edit by xiangwang0413w 2014/07/02
                                    _productitemmap.group_item_id = CommonFunction.Rank_ItemId(optional.Split('&')[i].ToString());
                                    _productitemmap = _ProductItemMapExcelImplMgr.QueryProductItemMap(_productitemmap).FirstOrDefault();
                                    StrOptional += "{";
                                    for (int j = 0, Lj = optional.Split('&')[i].Split(',').Length; j < Lj; j++)
                                    {
                                        string product_name = itemAll.Where(e => e.item_id == uint.Parse(optional.Split('&')[i].Split(',')[j])).FirstOrDefault().product_name;
                                        string spec_name_1 = itemAll.Where(e => e.item_id == uint.Parse(optional.Split('&')[i].Split(',')[j])).FirstOrDefault().spec_name_1;
                                        string spec_name_2 = itemAll.Where(e => e.item_id == uint.Parse(optional.Split('&')[i].Split(',')[j])).FirstOrDefault().spec_name_2;
                                        //先判斷是否已經建立對照 
                                        string set_num = maplist.Count == 0 ? itemAll.Where(e => e.item_id == uint.Parse(optional.Split('&')[i].Split(',')[j])).FirstOrDefault().set_num.ToString()
                                            : (maplist.Where(e => e.item_id == uint.Parse(optional.Split('&')[i].Split(',')[j]) && e.map_rid == (_productitemmap == null ? 0 : _productitemmap.rid)).FirstOrDefault() == null ? itemAll.Where(e => e.item_id == uint.Parse(optional.Split('&')[i].Split(',')[j])).FirstOrDefault().set_num.ToString()
                                            : maplist.Where(e => e.item_id == uint.Parse(optional.Split('&')[i].Split(',')[j]) && e.map_rid == (_productitemmap == null ? 0 : _productitemmap.rid)).FirstOrDefault().set_num.ToString());
                                        string s_must_buy = itemAll.Where(e => e.item_id == uint.Parse(optional.Split('&')[i].Split(',')[j])).FirstOrDefault().set_num.ToString();//必選數量
                                        StrOptional += "item_id_" + (j + 1).ToString() + ":" + optional.Split('&')[i].Split(',')[j].ToString() + ",product_name_" + (j + 1).ToString() + ":'" + product_name + (spec_name_1 != "" ? "(" + spec_name_1 + " " + spec_name_2 + ")" : "") + "',product_num_" + (j + 1).ToString() + ":" + set_num + ",s_must_buy_" + (j + 1) + ":" + s_must_buy;
                                        if (j != Lj - 1)
                                        {
                                            StrOptional += ",";
                                        }
                                    }

                                    StrOptional += ",group_item_id:'" + BLL.gigade.Common.CommonFunction.Rank_ItemId(optional.Split('&')[i].ToString()) + "'";
                                    if (_productitemmap != null)
                                    {
                                        StrOptional += ",rid:" + _productitemmap.rid + ",product_name:'" + _productitemmap.product_name + "',channel_detail_id:'" + _productitemmap.channel_detail_id + "',product_cost:" + _productitemmap.product_cost + ",product_price:" + _productitemmap.product_price;
                                    }
                                    else
                                    {
                                        StrOptional += ",product_name:'',channel_detail_id:'',product_cost:'',product_price:''";
                                    }
                                    StrOptional += "}";
                                }
                            }
                            StrOptional += "]";
                        }
                        #endregion

                        #region --建立過對照
                        else if (_listPitemMap.Count > 0)
                        {
                            StrOptional = "[";
                            for (int i = 0, j = _listPitemMap.Count; i < j; i++)
                            {
                                //對照下面的item_id
                                string list_groupItem = optional;
                                if (i != 0)
                                {
                                    StrOptional += ",";
                                }
                                StrOptional += "{";
                                for (int m = 0, Lj = list_groupItem.Split(',').Length; m < Lj; m++)
                                {
                                    string product_name = itemAll.Where(e => e.item_id == uint.Parse(list_groupItem.Split(',')[m])).FirstOrDefault().product_name;
                                    string spec_name_1 = itemAll.Where(e => e.item_id == uint.Parse(list_groupItem.Split(',')[m])).FirstOrDefault().spec_name_1;
                                    string spec_name_2 = itemAll.Where(e => e.item_id == uint.Parse(list_groupItem.Split(',')[m])).FirstOrDefault().spec_name_2;
                                    //先判斷是否已經建立對照 
                                    string set_num = _mapsetMgr.Query(_listPitemMap[i].rid, uint.Parse(list_groupItem.Split(',')[m])).FirstOrDefault() == null ? "0" : _mapsetMgr.Query(_listPitemMap[i].rid, uint.Parse(list_groupItem.Split(',')[m])).FirstOrDefault().set_num.ToString();
                                    string s_must_buy = itemAll.Where(e => e.item_id == uint.Parse(list_groupItem.Split(',')[m])).FirstOrDefault().set_num.ToString();//必選數量
                                    StrOptional += "item_id_" + (m + 1).ToString() + ":" + list_groupItem.Split(',')[m].ToString() + ",product_name_" + (m + 1).ToString() + ":'" + product_name + (spec_name_1 != "" ? "(" + spec_name_1 + " " + spec_name_2 + ")" : "") + "',product_num_" + (m + 1).ToString() + ":" + set_num + ",s_must_buy_" + (m + 1) + ":" + s_must_buy;
                                    if (m != Lj - 1)
                                    {
                                        StrOptional += ",";
                                    }
                                }

                                StrOptional += ",group_item_id:'" + list_groupItem + "'";
                                if (_listPitemMap != null)
                                {
                                    StrOptional += ",rid:" + _listPitemMap[i].rid + ",product_name:'" + _listPitemMap[i].product_name + "',channel_detail_id:'" + _listPitemMap[i].channel_detail_id + "',product_cost:" + _listPitemMap[i].product_cost + ",product_price:" + _listPitemMap[i].product_price;
                                }
                                else
                                {
                                    StrOptional += ",product_name:'',channel_detail_id:'',product_cost:'',product_price:''";
                                }
                                StrOptional += "}";
                            }
                            StrOptional += "]";
                        }
                        #endregion

                        #region --沒有建立過對照
                        else
                        {
                            StrOptional = "[";
                            if (!string.IsNullOrEmpty(optional))
                            {
                                for (int i = 0, Li = optional.Split('&').Length; i < Li; i++)
                                {
                                    if (StrOptional != "" && i != 0)
                                    {
                                        StrOptional += ",";
                                    }
                                    ProductItemMap _productitemmap = new ProductItemMap();
                                    _productitemmap.product_id = pid;
                                    _productitemmap.channel_id = channel_id;
                                    _productitemmap.price_master_id = pmId;//edit by xiangwang0413w 2014/07/02
                                    _productitemmap.group_item_id = CommonFunction.Rank_ItemId(optional.Split('&')[i].ToString());
                                    _productitemmap = _ProductItemMapExcelImplMgr.QueryProductItemMap(_productitemmap).FirstOrDefault();
                                    StrOptional += "{";
                                    for (int j = 0, Lj = optional.Split('&')[i].Split(',').Length; j < Lj; j++)
                                    {
                                        string product_name = itemAll.Where(e => e.item_id == uint.Parse(optional.Split('&')[i].Split(',')[j])).FirstOrDefault().product_name;
                                        string spec_name_1 = itemAll.Where(e => e.item_id == uint.Parse(optional.Split('&')[i].Split(',')[j])).FirstOrDefault().spec_name_1;
                                        string spec_name_2 = itemAll.Where(e => e.item_id == uint.Parse(optional.Split('&')[i].Split(',')[j])).FirstOrDefault().spec_name_2;
                                        //先判斷是否已經建立對照 
                                        string set_num = maplist.Count == 0 ? itemAll.Where(e => e.item_id == uint.Parse(optional.Split('&')[i].Split(',')[j])).FirstOrDefault().set_num.ToString()
                                            : (maplist.Where(e => e.item_id == uint.Parse(optional.Split('&')[i].Split(',')[j]) && e.map_rid == (_productitemmap == null ? 0 : _productitemmap.rid)).FirstOrDefault() == null ? itemAll.Where(e => e.item_id == uint.Parse(optional.Split('&')[i].Split(',')[j])).FirstOrDefault().set_num.ToString()
                                            : maplist.Where(e => e.item_id == uint.Parse(optional.Split('&')[i].Split(',')[j]) && e.map_rid == (_productitemmap == null ? 0 : _productitemmap.rid)).FirstOrDefault().set_num.ToString());
                                        string s_must_buy = itemAll.Where(e => e.item_id == uint.Parse(optional.Split('&')[i].Split(',')[j])).FirstOrDefault().set_num.ToString();//必選數量
                                        StrOptional += "item_id_" + (j + 1).ToString() + ":" + optional.Split('&')[i].Split(',')[j].ToString() + ",product_name_" + (j + 1).ToString() + ":'" + product_name + (spec_name_1 != "" ? "(" + spec_name_1 + " " + spec_name_2 + ")" : "") + "',product_num_" + (j + 1).ToString() + ":" + set_num + ",s_must_buy_" + (j + 1) + ":" + s_must_buy;
                                        if (j != Lj - 1)
                                        {
                                            StrOptional += ",";
                                        }
                                    }

                                    StrOptional += ",group_item_id:'" + BLL.gigade.Common.CommonFunction.Rank_ItemId(optional.Split('&')[i].ToString()) + "'";
                                    if (_productitemmap != null)
                                    {
                                        StrOptional += ",rid:" + _productitemmap.rid + ",product_name:'" + _productitemmap.product_name + "',channel_detail_id:'" + _productitemmap.channel_detail_id + "',product_cost:" + _productitemmap.product_cost + ",product_price:" + _productitemmap.product_price;
                                    }
                                    else
                                    {
                                        StrOptional += ",product_name:'',channel_detail_id:'',product_cost:'',product_price:''";
                                    }
                                    StrOptional += "}";
                                }
                            }
                            StrOptional += "]";
                        }
                        #endregion
                    }
                    #endregion
                    result = "{success:true,data:" + StrOptional + "}";
                }
            }
            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);
            }
            this.Response.Clear();
            this.Response.Write(result);
            this.Response.End();
            return this.Response;
        }
 public string saveString(ProductItemMap p)
 {
     p.Replace4MySQL();
     return string.Format("insert into product_item_map (`channel_id`, `channel_detail_id`, `item_id`, `product_name`, `product_cost`, `product_price`,`product_id`,`group_item_id`,`price_master_id`) values ({0},'{1}',{2},'{3}',{4},{5},{6},'{7}',{8});select @@identity;", p.channel_id, p.channel_detail_id, p.item_id, p.product_name, p.product_cost, p.product_price, p.product_id, p.group_item_id, p.price_master_id); //edit by xiangwang0413w 2014/07/20 增加站台價格
 }
 public int Save(ProductItemMap p)
 {
     return _ProductItemMapDao.Save(p);
 }
 //匯出商品對照信息-20140805
 public DataTable ProductItemMapExc(ProductItemMap Pip)
 {
     return _ProductItemMapDao.ProductItemMapExc(Pip);
 }
 //查找建立過的對照信息
 public List<ProductItemMap> QueryOldItemMap(ProductItemMap Pip)
 {
     return _ProductItemMapDao.QueryOldItemMap(Pip);
 }
 public DataTable ProductItemMapExc(ProductItemMap m)
 {
     tempStr = @"SELECT  channel_detail_id AS '外站商品編號',product_name AS '外站商品名稱',product_id AS '商品編號(5碼)',case item_id WHEN '0' THEN group_item_id ELSE item_id END AS '商品細項編號(6碼)','0' as '組合中之數量(0為照組合中之設定)',product_price AS '外站商品售價','1' as 'site_id','1' AS 'user_level','0' AS 'user_email' from product_item_map where 1=1 ";
     if (m.rid != 0)
     {
         tempStr += string.Format(" and rid >='{0}' ",m.rid);
     }
     if (m.channel_id != 0)
     {
         tempStr += string.Format(" and channel_id='{0}' ",m.channel_id);
     }
     return _accessMySql.getDataTable(tempStr);
 }
 //查找建立過的對照信息
 public List<ProductItemMap> QueryOldItemMap(ProductItemMap Pip)
 {
     //edit by xiangwang0413w 2014/07/02 增加price_master_id條件查詢
     string sql = string.Format("select  rid,channel_id,channel_detail_id,item_id,product_name,product_cost,product_price,product_id,group_item_id,price_master_id  from product_item_map where product_id='{0}' and channel_id='{1}' and price_master_id={2}", Pip.product_id, Pip.channel_id, Pip.price_master_id);
     return _accessMySql.getDataTableForObj<ProductItemMap>(sql);
 }
 /// <summary>
 /// 查詢固定組合商品的總信息
 /// </summary>
 /// <param name="p"></param>
 /// <returns></returns>
 public List<ProductItemMap> QueryProductItemMap(ProductItemMap p)
 {
     p.Replace4MySQL();
     tempStr = string.Format("select  rid,channel_id,channel_detail_id,item_id,product_name,product_cost,product_price,product_id,group_item_id,price_master_id  from product_item_map where channel_id={0} and product_id={1} and group_item_id='{2}' and price_master_id={3}", p.channel_id, p.product_id, p.group_item_id, p.price_master_id);//edit by xiangwang0413w 20714/07/02
     return _accessMySql.getDataTableForObj<ProductItemMap>(tempStr.ToString());
 }
 public List<ProductItemMap> QueryAll(ProductItemMap p)
 {
     p.Replace4MySQL();
     tempStr = string.Format(@"SELECT  rid,channel_id,channel_detail_id,item_id,product_name,product_cost,product_price,product_id,group_item_id,price_master_id  FROM product_item_map WHERE channel_id = {0} AND channel_detail_id = '{1}'", p.channel_id, p.channel_detail_id);
     return _accessMySql.getDataTableForObj<ProductItemMap>(tempStr);
 }
 public int UpdatePIM(ProductItemMap p)
 {
     p.Replace4MySQL();
     tempStr = string.Format("update product_item_map set product_name='{1}',product_price={2} where channel_detail_id = '{0}' ", p.channel_detail_id, p.product_name, p.product_price);
     return _accessMySql.execCommand(tempStr);
 }
 public string deleteString(ProductItemMap p)
 {
     return string.Format("set sql_safe_updates = 0;delete from product_item_map where rid={0};set sql_safe_updates = 1;", p.rid);
 }
        public int Delete(ProductItemMap p)
        {
            tempStr = string.Format("set sql_safe_updates = 0;delete from product_item_map where rid={0};set sql_safe_updates = 1;", p.rid);
            return _accessMySql.execCommand(tempStr);

        }
 public int Delete(ProductItemMap p)
 {
     try
     {
         List<ChannelOrder> result = _channelorderDao.Query(new ChannelOrder { Channel_Detail_Id = p.channel_detail_id, Channel_Id = int.Parse(p.channel_id.ToString()) });
         if (result.Count() > 0)
         {
             return -1;
         }
         else
         {
             return _ProductItemMapDao.Delete(p);
         }
     }
     catch (Exception ex)
     {
         throw new Exception("ProductItemMapMgr-->Delete-->" + ex.Message, ex);
     }
 }
 public bool ComboDelete(ProductItemMap delete)
 {
     ArrayList delArry = new ArrayList();
     delArry.Add(_mapSetDao.Delete(new ProductMapSet { map_rid = delete.rid }));
     delArry.Add(_ProductItemMapDao.deleteString(delete));
     return _mySqlDao.ExcuteSqls(delArry);
 }
Exemple #18
0
        /// <summary>
        /// 合作外站商品查詢
        /// </summary>
        /// <returns></returns>
        public HttpResponseBase OrderInfoQueryByCooperator()
        {
            string jsonStr = "{success:false}";
            string pid = Request.Params["pid"] ?? "";
            uint channelId = 0;
            UInt32.TryParse(Request.Params["channelId"] ?? "0", out channelId);
            if (!string.IsNullOrEmpty(pid))
            {
                IProductItemMapImplMgr _pMapMgr = new ProductItemMapMgr(connectionString);
                IProductItemImplMgr _proItemMgr = new ProductItemMgr(connectionString);
                try
                {
                    ProductItemMap pMap = new ProductItemMap();

                    pMap.channel_detail_id = pid;
                    pMap.channel_id = channelId;
                    List<ProductItemMap> pMapList = _pMapMgr.QueryAll(pMap);
                    IPriceMasterImplMgr priceMgr = new PriceMasterMgr(connectionString);
                    IProductItemImplMgr _itemMgr = new ProductItemMgr(connectionString);
                    PriceMaster priceMap = priceMgr.QueryPriceMaster(new PriceMaster { price_master_id = pMapList.FirstOrDefault().price_master_id });
                    if (pMapList.Count() == 0)
                    {
                        jsonStr = "{success:false}";
                        this.Response.Clear();
                        this.Response.Write(jsonStr);
                        this.Response.End();
                        return this.Response;
                    }
                    uint product_id = pMapList[0].product_id;
                    if (product_id == 0)
                    {
                        product_id = _itemMgr.Query(new ProductItem { Item_Id = uint.Parse(pMapList[0].item_id.ToString()) }).FirstOrDefault().Product_Id;
                    }

                    IProductImplMgr _proMgr = new ProductMgr(connectionString);
                    Product prod = _proMgr.Query(new Product { Product_Id = product_id }).FirstOrDefault();

                    //判断商品是否上架
                    // long ltime = BLL.gigade.Common.CommonFunction.GetPHPTime(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));

                    if (prod.Combination != 1 && prod.Combination != 0)
                    {
                        OrderComboAddCustom orderAdd = _proMgr.OrderQuery(new Product { Product_Id = product_id }, priceMap.user_level, priceMap.user_id, priceMap.site_id);
                        orderAdd.product_id = 0;
                        orderAdd.out_product_id = pMapList[0].channel_detail_id;
                        orderAdd.product_name = pMapList[0].product_name;
                        orderAdd.product_cost = pMapList[0].product_price;
                        jsonStr = "{success:true";
                        string price_scale = "", cost_scale = "";
                        //查詢子商品信息
                        _prodCombMgr = new ProductComboMgr(connectionString);
                        List<ProductComboCustom> prodComList = _prodCombMgr.combQuery(new ProductComboCustom { Parent_Id = int.Parse(product_id.ToString()) });

                        IPriceMasterImplMgr pMgr = new PriceMasterMgr(connectionString);
                        PriceMaster query = new PriceMaster { user_id = priceMap.user_id, user_level = priceMap.user_level, site_id = priceMap.site_id };

                        jsonStr += ",child:[";
                        double childTotalPrice = 0;
                        double childTotalCost = 0;
                        string[] itemList = pMapList[0].group_item_id.ToString().Split(',');
                        foreach (var item in prodComList)
                        {
                            #region 計算子商品總價

                            for (int i = 0; i < itemList.Length; i++)
                            {
                                //在item_price中查找該itemid對應的價格
                                IItemPriceImplMgr iPMgr = new ItemPriceMgr(connectionString);

                                if (prod.Price_type == 1)
                                {
                                    query.product_id = uint.Parse(item.Child_Id.ToString());
                                    query.child_id = 0;
                                }
                                else if (prod.Price_type == 2)
                                {
                                    query.product_id = prod.Product_Id;
                                    query.child_id = int.Parse(item.Child_Id.ToString());
                                }


                                PriceMaster pM = priceMgr.QueryPriceMaster(query);
                                List<ItemPriceCustom> ipList = new List<ItemPriceCustom>();

                                //查詢子商品詳細信息(規格,庫存)
                                ProductItem pItem = new ProductItem();
                                pItem.Item_Id = uint.Parse(itemList[i]);
                                pItem.Product_Id = uint.Parse(item.Child_Id.ToString());
                                List<ProductItem> pItemList = _proItemMgr.Query(pItem);

                                if (pM != null && pItemList.Count > 0)
                                {
                                    //查找外站商品必購數量
                                    IProductMapSetImplMgr msMgr = new ProductMapSetMgr(connectionString);
                                    List<ProductMapSet> mSetList = msMgr.Query(new ProductMapSet { map_rid = uint.Parse(pMapList[0].rid.ToString()), item_id = uint.Parse(itemList[i]) });
                                    if (pM.same_price == 1)
                                    {
                                        childTotalPrice += int.Parse((pM.price * mSetList[0].set_num).ToString());
                                        childTotalCost += int.Parse((pM.cost * mSetList[0].set_num).ToString());
                                    }
                                    else
                                    {
                                        ipList = iPMgr.Query(new ItemPrice
                                        {
                                            item_id = uint.Parse(itemList[i]),
                                            price_master_id = pM.price_master_id
                                        });
                                        if (ipList.Count != 0)
                                        {
                                            if (mSetList.Count == 1)
                                            {
                                                childTotalPrice += int.Parse((ipList[0].item_money * mSetList[0].set_num).ToString());
                                                childTotalCost += int.Parse((ipList[0].item_cost * mSetList[0].set_num).ToString());
                                            }
                                            else
                                            {
                                                //在item_price中未查出對應價格
                                                this.Response.Clear();
                                                this.Response.Write("{success:false,msg:'" + Resources.OrderAdd.COMBO_CHILD_PRICE_NULL + "'}");
                                                this.Response.End();
                                                return this.Response;
                                            }
                                        }
                                    }
                                }


                            }
                            #endregion
                        }

                        double beforePrice = 0;
                        double beforeCost = 0;
                        int minStock = 0;
                        int index = 0;
                        double comboPrice = orderAdd.product_cost;
                        int curIndex = 0;
                        foreach (var item in prodComList)
                        {
                            curIndex++;
                            OrderAddCustom oc = new OrderAddCustom();
                            List<Product> pList = _proMgr.Query(new Product { Product_Id = uint.Parse(item.Child_Id.ToString()) });
                            oc.price_type = prod.Price_type;
                            oc.Product_Id = uint.Parse(item.Child_Id.ToString());
                            oc.ignore_stock = pList[0].Ignore_Stock;
                            oc.newparent_id = pMapList[0].channel_detail_id;
                            //補貨中是否還能販賣
                            if (pList.FirstOrDefault().Shortage == 1)
                            {
                                this.Response.Clear();
                                this.Response.Write("{success:false,msg:'" + Resources.OrderAdd.SHPRT_AGE + "'}");
                                this.Response.End();
                                return this.Response;
                            }
                            //讀取product_name
                            if (prod.Price_type == 1)
                            {
                                query.product_id = oc.Product_Id;
                                query.child_id = 0;
                            }
                            else if (prod.Price_type == 2)
                            {
                                query.product_id = prod.Product_Id;
                                query.child_id = Convert.ToInt32(oc.Product_Id);
                            }
                            PriceMaster pm = pMgr.QueryPriceMaster(query);
                            if (pm != null)
                            {
                                oc.product_name = pm.product_name;
                            }


                            for (int i = 0; i < itemList.Length; i++)
                            {
                                //查詢子商品詳細信息(規格,庫存)
                                ProductItem pItem = new ProductItem();
                                pItem.Item_Id = uint.Parse(itemList[i]);
                                pItem.Product_Id = uint.Parse(item.Child_Id.ToString());
                                oc.Item_Id = pItem.Item_Id;
                                List<ProductItem> pItemList = _proItemMgr.Query(pItem);
                                if (pItemList.Count() != 0)
                                {
                                    index++;

                                    //在item_price中查找該itemid對應的價格
                                    IItemPriceImplMgr iPMgr = new ItemPriceMgr(connectionString);
                                    List<ItemPriceCustom> ipList = new List<ItemPriceCustom>();
                                    if (pm != null)
                                    {
                                        oc.price_master_id = pm.price_master_id;
                                        //查找外站商品必購數量
                                        IProductMapSetImplMgr msMgr = new ProductMapSetMgr(connectionString);
                                        List<ProductMapSet> mSetList = msMgr.Query(new ProductMapSet { map_rid = uint.Parse(pMapList[0].rid.ToString()), item_id = uint.Parse(itemList[i]) });
                                        if (mSetList.Count != 0)
                                        {
                                            oc.s_must_buy = int.Parse(mSetList[0].set_num.ToString());
                                        }
                                        if (prod.Price_type == 1)
                                        {
                                            #region 按比例拆分


                                            if (i == itemList.Length - 1 && curIndex == prodComList.Count)
                                            {
                                                oc.product_cost = uint.Parse(CommonFunction.Math4Cut5Plus((orderAdd.product_cost - beforePrice) / oc.s_must_buy).ToString());
                                                oc.Item_Cost = uint.Parse(CommonFunction.Math4Cut5Plus((orderAdd.cost - beforeCost) / oc.s_must_buy).ToString());

                                            }
                                            else
                                            {
                                                double price = 0.0;
                                                double cost = 0.0;
                                                string price_res = "0";
                                                string cost_res = "0";
                                                double price_result = 0.0;
                                                double cost_result = 0.0;

                                                //规格同价
                                                if (pm.same_price == 1)
                                                {
                                                    if (childTotalPrice != 0)
                                                    {
                                                        double singlePrice = double.Parse((pm.price * oc.s_must_buy).ToString());
                                                        double totalPrice = childTotalPrice;
                                                        double c_scale = singlePrice / totalPrice;
                                                        price = orderAdd.product_cost * c_scale / oc.s_must_buy;
                                                        price_result = CommonFunction.Math4Cut5Plus(price);
                                                        price_res = c_scale.ToString();
                                                    }
                                                    beforePrice += price_result;
                                                    oc.product_cost = uint.Parse(price_result.ToString());
                                                    price_scale += price_res + ",";

                                                    if (childTotalCost != 0)
                                                    {
                                                        double singleCost = double.Parse((pm.cost * oc.s_must_buy).ToString());
                                                        double totalCost = childTotalCost;
                                                        double c_scale = singleCost / totalCost;
                                                        cost = orderAdd.cost * c_scale / oc.s_must_buy;
                                                        cost_result = CommonFunction.Math4Cut5Plus(cost);
                                                        cost_res = c_scale.ToString();
                                                    }
                                                    beforeCost += cost_result;
                                                    oc.Item_Cost = uint.Parse(cost_result.ToString());
                                                    cost_scale += cost_res + ",";


                                                }
                                                else
                                                {
                                                    ipList = iPMgr.Query(new ItemPrice
                                                    {
                                                        item_id = uint.Parse(itemList[i]),
                                                        price_master_id = pm.price_master_id
                                                    });
                                                    if (ipList.Count != 0)
                                                    {
                                                        if (childTotalPrice != 0)
                                                        {
                                                            double singlePrice = double.Parse((ipList[0].item_money * oc.s_must_buy).ToString());
                                                            double totalPrice = childTotalPrice;
                                                            double c_scale = singlePrice / totalPrice;
                                                            price = orderAdd.product_cost * c_scale / oc.s_must_buy;
                                                            price_result = CommonFunction.Math4Cut5Plus(price);
                                                            price_res = c_scale.ToString();
                                                        }
                                                        beforePrice += price_result;
                                                        oc.product_cost = uint.Parse(price_result.ToString());
                                                        price_scale += price_res + ",";

                                                        if (childTotalCost != 0)
                                                        {
                                                            double singleCost = double.Parse((ipList[0].item_cost * oc.s_must_buy).ToString());
                                                            double totalCost = childTotalCost;
                                                            double c_scale = singleCost / totalCost;
                                                            cost = orderAdd.cost * c_scale / oc.s_must_buy;
                                                            cost_result = CommonFunction.Math4Cut5Plus(cost);
                                                            cost_res = c_scale.ToString();
                                                        }
                                                        beforeCost += cost_result;
                                                        oc.Item_Cost = uint.Parse(cost_result.ToString());
                                                        cost_scale += cost_res + ",";
                                                    }
                                                }
                                            }
                                            #endregion
                                        }
                                        else if (prod.Price_type == 2)
                                        {
                                            #region 各自定價

                                            ipList = iPMgr.Query(new ItemPrice { item_id = uint.Parse(itemList[i]), price_master_id = pm.price_master_id });
                                            if (ipList.FirstOrDefault() != null)
                                            {
                                                oc.product_cost = ipList.FirstOrDefault().item_money;
                                            }
                                            #endregion
                                        }
                                    }


                                    if (index == 1)
                                    {
                                        minStock = oc.s_must_buy > 0 ? Convert.ToInt32(pItemList[0].Item_Stock / oc.s_must_buy) : pItemList[0].Item_Stock;
                                    }
                                    oc.Item_Stock = pItemList[0].Item_Stock;
                                    int tmp_stock = oc.s_must_buy > 0 ? Convert.ToInt32(oc.Item_Stock / oc.s_must_buy) : oc.Item_Stock;
                                    if (tmp_stock < minStock)
                                    {
                                        minStock = tmp_stock;
                                    }
                                    //根據spec_id找出spec_name
                                    IProductSpecImplMgr _specMgr = new BLL.gigade.Mgr.ProductSpecMgr(connectionString);
                                    ProductSpec ps1 = _specMgr.query(int.Parse(pItemList[0].Spec_Id_1.ToString()));
                                    if (ps1 != null)
                                    {
                                        oc.Spec_Name_1 = ps1.spec_name;
                                        oc.Spec_Id_1 = ps1.spec_id;
                                    }
                                    ProductSpec ps2 = _specMgr.query(int.Parse(pItemList[0].Spec_Id_2.ToString()));
                                    if (ps2 != null)
                                    {
                                        oc.Spec_Name_2 = ps2.spec_name;
                                        oc.Spec_Id_2 = ps2.spec_id;
                                    }
                                    jsonStr += "{";
                                    jsonStr += "'product_id':'" + oc.Product_Id + "','product_name':'" + oc.product_name + "','item_id':'" + oc.Item_Id + "'";
                                    jsonStr += ",'spec1':'" + oc.Spec_Id_1 + "','spec2':'" + oc.Spec_Id_2 + "','spec1_show':'" + oc.Spec_Name_1 + "',s_must_buy:'" + oc.s_must_buy + "'";
                                    jsonStr += ",'spec2_show':'" + oc.Spec_Name_2 + "','product_cost':'" + oc.product_cost + "',Item_Cost:'" + oc.Item_Cost + "','stock':'" + oc.Item_Stock + "',price_master_id:" + oc.price_master_id;
                                    jsonStr += ",price_type:" + oc.price_type + ",ignore_stock:" + oc.ignore_stock;
                                    if (oc.parent_id != 0)
                                    {
                                        jsonStr += ",parent_id:'" + oc.parent_id + "'";
                                    }
                                    else
                                    {
                                        jsonStr += ",parent_id:'" + oc.newparent_id + "'";
                                    }
                                    jsonStr += "},";
                                }
                            }
                        }
                        if (price_scale != "")
                        {
                            price_scale = price_scale.Substring(0, price_scale.Length - 1);
                        }
                        jsonStr = jsonStr.Substring(0, jsonStr.Length - 1) + "]";
                        jsonStr += ",data:[";
                        jsonStr += "{product_id:'" + orderAdd.out_product_id + "',item_id:0,product_name:'" + orderAdd.product_name + "',product_cost:'" + orderAdd.product_cost + "'";
                        jsonStr += ",s_must_buy:'" + pMapList[0].group_item_id.ToString().Split(',').Length + "',Item_Cost:'" + orderAdd.cost + "',child_cost_scale:'" + cost_scale + "',child_scale:'" + price_scale + "',stock:'" + minStock + "',g_must_buy:'" + pMapList[0].group_item_id.ToString().Split(',').Length + "'}]}";


                    }
                    else
                    {
                        if (prod.Combination == 0)
                        {
                            jsonStr = "{success:false,msg:\"" + Resources.OrderAdd.PRODUCT_NOT_USE_IN_ORDER + "\"}";
                            this.Response.Clear();
                            this.Response.Write(jsonStr);
                            this.Response.End();
                            return this.Response;
                        }
                        else
                        {
                            //單一商品
                            ProductItem pItem = new ProductItem();
                            pItem.Item_Id = UInt32.Parse(pMapList[0].item_id.ToString());


                            List<ProductItem> pItemList = _proItemMgr.Query(pItem);
                            List<Product> pList = _proMgr.Query(new Product { Product_Id = uint.Parse(pItemList[0].Product_Id.ToString()) });
                            //補貨時還能販賣
                            if (pList[0].Shortage == 1)
                            {
                                this.Response.Clear();
                                this.Response.Write("{success:false,msg:'" + Resources.OrderAdd.SHPRT_AGE + "'}");
                                this.Response.End();
                                return this.Response;
                            }
                            if (pItemList.Count() == 0)
                            {
                                jsonStr = "{success:false}";
                                this.Response.Clear();
                                this.Response.Write(jsonStr);
                                this.Response.End();
                                return this.Response;
                            }


                            List<OrderAddCustom> oalist = new List<OrderAddCustom>();

                            OrderAddCustom oc = new OrderAddCustom();

                            oc.Spec_Id_1 = pItemList[0].Spec_Id_1;
                            oc.Spec_Id_2 = pItemList[0].Spec_Id_2;
                            oc.Item_Stock = pItemList[0].Item_Stock;
                            oc.ignore_stock = pList[0].Ignore_Stock;

                            IProductSpecImplMgr _specMgr = new BLL.gigade.Mgr.ProductSpecMgr(connectionString);
                            ProductSpec spec1 = _specMgr.query(Convert.ToInt32(pItemList[0].Spec_Id_1));
                            ProductSpec spec2 = _specMgr.query(Convert.ToInt32(pItemList[0].Spec_Id_2));
                            if (spec1 != null)
                            {
                                oc.Spec_Name_1 = spec1.spec_name;
                            }
                            if (spec2 != null)
                            {
                                oc.Spec_Name_2 = spec2.spec_name;
                            }

                            oalist.Add(oc);

                            StringBuilder stb = new StringBuilder();

                            stb.Append("[");
                            stb.Append("{product_id:'" + pMapList[0].channel_detail_id + "',item_id:" + pMapList[0].item_id + ",product_name:'" + HttpUtility.HtmlEncode(pMapList[0].product_name) + "',spec1:'" + oc.Spec_Id_1.ToString() + "',");
                            stb.Append("spec2:'" + oc.Spec_Id_2.ToString() + "',spec1_show:'" + oc.Spec_Name_1 + "',spec2_show:'" + oc.Spec_Name_2 + "',product_cost:" + pMapList[0].product_price + ",");
                            stb.Append("stock:" + oc.Item_Stock + ",price_master_id:" + oc.price_master_id + ",ignore_stock:" + oc.ignore_stock + "}");
                            stb.Append("]");

                            jsonStr = "{success:true,data:" + stb.ToString() + "}";
                        }
                    }
                }
                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);
                }
            }
            else
            {
                jsonStr = "{success:true,data:{product_id:''}}";
            }

            this.Response.Clear();
            this.Response.Write(jsonStr);
            this.Response.End();
            return this.Response;
        }
 public List<Model.ProductMapSet> Query(ProductItemMap proItemMap)
 {
     string strSql = string.Format("select * from product_map_set where map_rid in (select rid from product_item_map where channel_id = {0} and channel_detail_id='{1}' and price_master_id={2})",proItemMap.channel_id, proItemMap.channel_detail_id,proItemMap.price_master_id);
     return _dbAccess.getDataTableForObj<Model.ProductMapSet>(strSql.ToString());
 }
 public string EditUpload()
 {
     ProductItemMap m = new ProductItemMap();
     int channel_id = int.Parse(Request.Form["channel"]);
     int Ins = 0; int Upd = 0;
     #region 讀取excel文件
     string fileName = Request.Files[0].FileName;
     string filePath = "";
     string fName = "";
     string fExtension = "";
     try
     {
         FileOperator fo = new FileOperator(fileName);
         fExtension = fo.Extension;
         if (fExtension != ".xls" && fExtension != ".xlsx")
         {
             return "{success:false,msg:'" + Resources.ProductItemMap.EXCEL_FORMAT_ERROR + "'}";
         }
         if (!System.IO.Directory.Exists(Server.MapPath(excelPath)))
         {
             System.IO.Directory.CreateDirectory(Server.MapPath(excelPath));
         }
         fName = DateTime.Now.ToString("yyyyMMddhhmmss") + fo.Extension;
         filePath = Server.MapPath(excelPath) + "/" + fName;
     }
     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 "{success:false,msg:'" + Resources.ProductItemMap.EXCEL_FORMAT_ERROR + "'}";
     }
     try
     {
         Request.Files[0].SaveAs(filePath);
     }
     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);
     }
     #endregion
     try
     {
         Resource.CoreMessage = new CoreResource("ProductItemMap");
         //讀取excel裡賣弄的內容
         NPOI4ExcelHelper fm = new NPOI4ExcelHelper(filePath);
         _ProductItemMapMgr = new ProductItemMapMgr(connectionString);
         DataTable dt = fm.SheetData();
         if (dt.Rows.Count > 0)
         {
             for (int i = 0; i < dt.Rows.Count; i++)
             {
                 if (_ProductItemMapMgr.Selrepeat(dt.Rows[i]["外站商品編號"].ToString()) > 0)
                 {//編輯
                     try
                     {
                         m.channel_detail_id = dt.Rows[i]["外站商品編號"].ToString();
                         m.product_name = dt.Rows[i]["外站商品名稱"].ToString();
                         m.product_price = Int32.Parse(dt.Rows[i]["外站商品售價"].ToString());
                         _ProductItemMapMgr.UpdatePIM(m);
                         Upd++;
                     }
                     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);
                     }
                 }
                 else
                 {//保存 未知price_master_id
                     try
                     {
                         m.channel_id = UInt32.Parse(channel_id.ToString());
                         m.channel_detail_id = dt.Rows[i]["外站商品編號"].ToString();
                         m.product_name = dt.Rows[i]["外站商品名稱"].ToString();
                         try
                         {
                             m.product_id = UInt32.Parse(dt.Rows[i]["商品編號(5碼)"].ToString());
                         }
                         catch
                         {
                             m.product_id = 0;
                         }
                         try
                         {
                             m.item_id = UInt32.Parse(dt.Rows[i]["商品細項編號(6碼)"].ToString());
                         }
                         catch
                         {
                             m.item_id = 0;
                         }
                         //m.product_cost = Int32.Parse(dt.Rows[i]["外站商品成本"].ToString());
                         try
                         {
                             m.product_price = Int32.Parse(dt.Rows[i]["外站商品售價"].ToString());
                         }
                         catch
                         {
                             m.product_price = 0;
                         }
                         _ProductItemMapMgr.Save(m);
                         Ins++;
                     }
                     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 "{success:true,msg:'新增成功" + Ins + "條,更新成功" + Upd + "條'}";
         }
         else
             return "{success:false,msg:'Excel no data'}";
     }
     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 "{success:false,msg:'" + Resources.ProductItemMap.IMPORT_FAIL + "'}";
     }
     //return "{success:true,msg:'" + string.Format(Resources.ProductItemMap.IMPORT_SUCCESS_TOTAL, Ins+Upd) + "'}";
 } 
 public int UpdatePIM(ProductItemMap p)
 {
     return _ProductItemMapDao.UpdatePIM(p);
 }
 /// <summary>
 /// 匯出賣場商品對照(payeasy)
 /// </summary>
 public void OutExcel()
 {
     ProductItemMap m = new ProductItemMap();
     string fileName = "ProductMap_" + DateTime.Now.ToString("yyyyMMddhhmm") + ".xls";
     DataTable new_Table = new DataTable();
     _ProductItemMapMgr = new ProductItemMapMgr(connectionString);
     try
     {
         try
         {
             m.rid = UInt32.Parse(Request.Params["rid"]);
         }
         catch (Exception)
         {
             m.rid = 0;
         }
         try
         {
             m.channel_id = UInt32.Parse(Request.Params["channelid"]);
         }
         catch (Exception)
         {
             m.channel_id = 0;
         }
         new_Table = _ProductItemMapMgr.ProductItemMapExc(m);
         MemoryStream ms = ExcelHelperXhf.ExportDT(new_Table, "");
         Response.AddHeader("Content-Disposition", "attachment; filename=" + Server.UrlEncode(fileName));
         Response.BinaryWrite(ms.ToArray());
         //Response.Clear();
         //Response.End();
     }
     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);
     }
 }         
 /// <summary>
 /// 查詢product_item_map表中是否有數據
 /// </summary>
 /// <param name="p"></param>
 /// <returns></returns>
 public List<ProductItemMap> QueryProductItemMap(ProductItemMap p)
 {
     return _productItemMapDao.QueryProductItemMap(p);
 }
        //public int Save(ProductCompare p)
        //{
        //    tempStr = string.Format("insert into product_item_map (`channel_id`, `channel_detail_id`, `item_id`, `product_name`, `product_cost`, `product_price`) values ({0},'{1}',{2},'{3}',{4},{5});", p.channel_id, p.channel_detail_id, p.item_id, p.product_name, p.product_cost, p.product_price);
        //    return _accessMySql.execCommand(tempStr);
        //}

        /// <summary>
        /// 保存商品對照(單一)
        /// </summary>
        /// <param name="p">一條商品信息</param>
        /// <returns></returns>
        public int Save(ProductItemMap p)
        {
            p.Replace4MySQL();
            tempStr = string.Format("insert into product_item_map (`channel_id`, `channel_detail_id`, `item_id`, `product_name`, `product_cost`, `product_price`,`product_id`,`price_master_id`) values ({0},'{1}',{2},'{3}',{4},{5},{6},{7})", p.channel_id, p.channel_detail_id, p.item_id, p.product_name, p.product_cost, p.product_price, p.product_id, p.price_master_id);
            return _accessMySql.execCommand(tempStr);
        }