Пример #1
0
 public JsonResult GetAuthorityGroup()
 {
     try
     {
         BLL.gigade.Model.Vendor vendorModel = new BLL.gigade.Model.Vendor();
         vendorModel = (BLL.gigade.Model.Vendor)Session["vendor"];
         _vendor = new VendorMgr(connectionString);
         string callId = _vendor.GetSingle(vendorModel).vendor_email;
         AuthorityQuery query = new AuthorityQuery { Type = 1, CallId = callId };
         functionGroupMgr = new FunctionVGroupMgr(connectionString);
         List<Function> functions = functionGroupMgr.CallerAuthorityQuery(query);
         var result = from f in functions
                      group f by f.FunctionGroup into fgroup
                      select new { Id = fgroup.Min(m => m.RowId), Text = fgroup.Key };
         return Json(result);
     }
     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("[]");
 }
Пример #2
0
        public ActionResult Index()
        {
            HttpCookie cookies = Request.Cookies["vendor"];
            if (cookies != null)
            {
                ViewBag.LoginEmail = cookies["email"];
            }
            else
            {
                ViewBag.LoginEmail = null;
            }

            if (Session["vendor"] != null)
            {
                return RedirectToAction("", "home");
            }
            else
            {
                string vendorid = Request.QueryString["vendor_id"];
                string key = Request.QueryString["key"];
                string keysec = string.Empty;
                if (!string.IsNullOrEmpty(vendorid) && !string.IsNullOrEmpty(key))
                {
                    int vendor_id = Convert.ToInt32(vendorid);
                    _vendorImp = new VendorMgr(connectionString);
                    string str = _vendorImp.GetLoginId(vendor_id);
                    HashEncrypt hmd5 = new HashEncrypt();
                    string mdlogin_id = hmd5.Md5Encrypt(str, "MD5");
                    keysec = hmd5.Md5Encrypt(mdlogin_id + str, "MD5");
                    if (key.ToString().Trim() != keysec.ToString().Trim())
                    {
                        return View();
                    }
                    else
                    {
                        BLL.gigade.Model.Vendor vendor = new BLL.gigade.Model.Vendor();
                        BLL.gigade.Model.Vendor ven = new BLL.gigade.Model.Vendor();
                        vendor.vendor_id = Convert.ToUInt32(vendorid);
                        _vendorImp = new VendorMgr(connectionString);
                        ven = _vendorImp.GetSingle(vendor);
                        ven.vendor_password = "";
                        Session["vendor"] = ven;
                        Session["lgnName"] = ven.vendor_name_simple;
                        return RedirectToAction("", "home");
                    }
                }
                else
                {
                    return View();
                }

            }
        }
Пример #3
0
 public HttpResponseBase GetAuthorityFun(string id)
 {
     string json = string.Empty;
     try
     {
         BLL.gigade.Model.Vendor vendorModel = new BLL.gigade.Model.Vendor();
         vendorModel = (BLL.gigade.Model.Vendor)Session["vendor"];
         _vendor = new VendorMgr(connectionString);
         string callId = _vendor.GetSingle(vendorModel).vendor_email;
         AuthorityQuery query = new AuthorityQuery { Type = 1, CallId = callId };
         if (!string.IsNullOrEmpty(id))
         {
             query.RowId = Convert.ToInt32(id);
         }
         functionGroupMgr = new FunctionVGroupMgr(connectionString);
         List<Function> functions = functionGroupMgr.CallerAuthorityQuery(query);
         StringBuilder strJson = new StringBuilder("[");
         foreach (Function fun in functions)
         {
             strJson.Append("{");
             strJson.AppendFormat("text:\"{0}\",url:\"{1}\",id:\"{2}\",iconCls:\"{3}\",leaf:true", fun.FunctionName, fun.FunctionCode, fun.RowId, fun.IconCls);
             strJson.Append("}");
         }
         strJson.Append("]");
         json = strJson.ToString().Replace("}{", "},{");
     }
     catch (Exception ex)
     {
         json = "[]";
         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(json);
     this.Response.End();
     return this.Response;
 }
Пример #4
0
        public HttpResponseBase SaveVendor()
        {
            string jsonStr = String.Empty;
            try
            {
                VendorQuery venQuery = new VendorQuery();

                venQuery.user_type = 2;//變更者類型1.供應商2.管理員
                if (Request.Params["vendor_id"].ToString() == "")
                {
                    #region 獲取供應商數據
                    if (!string.IsNullOrEmpty(Request.Params["vendor_status"].ToString()))
                    {
                        venQuery.vendor_status = Convert.ToUInt32(Request.Params["vendor_status"].ToString());
                    }
                    else
                    {
                        venQuery.vendor_status = 1;
                    }

                    _vendorMgr = new VendorMgr(connectionString);
                    if (!string.IsNullOrEmpty(Request.Params["vendor_email"].ToString()))
                    {
                        try
                        {
                            if (_vendorMgr.IsExitEmail(Request.Params["vendor_email"].ToString().ToLower()) != 0)
                            {
                                jsonStr = "{success:true,msg:0}";//返回json數據
                                this.Response.Clear();
                                this.Response.Write(jsonStr);
                                this.Response.End();
                                return this.Response;
                            }
                            else
                            {
                                venQuery.vendor_email = Request.Params["vendor_email"].Trim().ToLower();
                            }
                        }
                        catch (Exception ex)
                        {
                            Log4NetCustom.LogMessage logMessage = new Log4NetCustom.LogMessage();
                            logMessage.Content = string.Format("TargetSite:{0},Source:{1},Message:{2}", ex.TargetSite.Name, ex.Source, ex.Message);
                            logMessage.MethodName = System.Reflection.MethodBase.GetCurrentMethod().Name;
                            log.Error(logMessage);
                            jsonStr = "{success:false,msg:1}";
                            this.Response.Clear();
                            this.Response.Write(jsonStr);
                            this.Response.End();
                            return this.Response;
                        }
                    }
                    else
                    {
                        venQuery.vendor_email = "";
                    }

                    BLL.gigade.Common.HashEncrypt hash = new BLL.gigade.Common.HashEncrypt();
                    if (!string.IsNullOrEmpty(Request.Params["vendor_password"].ToString()))
                    {
                        venQuery.vendor_password = hash.SHA256Encrypt(Request.Params["vendor_password"].ToString());
                    }
                    else
                    {
                        //新增供應商時如果未設置密碼則將統一編號進行加密作為密碼進行保存
                        venQuery.vendor_password = hash.SHA256Encrypt(Request.Params["vendor_invoice"]);
                    }

                    if (!string.IsNullOrEmpty(Request.Params["vendor_name_full"].ToString()))
                    {
                        venQuery.vendor_name_full = Request.Params["vendor_name_full"].ToString().Trim();
                    }
                    else
                    {
                        venQuery.vendor_name_full = "";
                    }
                    if (!string.IsNullOrEmpty(Request.Params["vendor_name_simple"].ToString()))
                    {
                        venQuery.vendor_name_simple = Request.Params["vendor_name_simple"].ToString().Trim();
                    }
                    else
                    {
                        venQuery.vendor_name_simple = "";
                    }
                    if (!string.IsNullOrEmpty(Request.Params["vendor_invoice"].ToString()))
                    {
                        venQuery.vendor_invoice = Request.Params["vendor_invoice"].ToString();
                    }
                    else
                    {
                        venQuery.vendor_invoice = "";
                    }
                    if (!string.IsNullOrEmpty(Request.Params["company_phone"].ToString()))
                    {
                        venQuery.company_phone = Request.Params["company_phone"].ToString();
                    }
                    else
                    {
                        venQuery.company_phone = "";
                    }
                    if (!string.IsNullOrEmpty(Request.Params["company_fax"].ToString()))
                    {
                        venQuery.company_fax = Request.Params["company_fax"].ToString();
                    }
                    else
                    {
                        venQuery.company_fax = "";
                    }
                    if (!string.IsNullOrEmpty(Request.Params["company_person"].ToString()))
                    {
                        venQuery.company_person = Request.Params["company_person"].ToString();
                    }
                    else
                    {
                        venQuery.company_person = "";
                    }
                    if (!string.IsNullOrEmpty(Request.Params["company_zip"].ToString()))
                    {
                        venQuery.company_zip = Convert.ToUInt32(Request.Params["company_zip"].ToString());
                    }
                    else
                    {
                        venQuery.company_zip = 0;
                    }
                    if (!string.IsNullOrEmpty(Request.Params["company_address"].ToString()))
                    {
                        venQuery.company_address = Request.Params["company_address"].ToString();
                    }
                    else
                    {
                        venQuery.company_address = "";
                    }
                    if (!string.IsNullOrEmpty(Request.Params["invoice_zip"].ToString()))
                    {
                        venQuery.invoice_zip = Convert.ToUInt32(Request.Params["invoice_zip"].ToString());
                    }
                    else
                    {
                        venQuery.invoice_zip = 0;
                    }
                    if (!string.IsNullOrEmpty(Request.Params["invoice_address"].ToString()))
                    {
                        venQuery.invoice_address = Request.Params["invoice_address"].ToString();
                    }
                    else
                    {
                        venQuery.invoice_address = "";
                    }

                    if (!string.IsNullOrEmpty(Request.Params["pm"].ToString()))
                    {
                        venQuery.product_manage = Convert.ToUInt32(Request.Params["pm"].ToString());
                    }
                    else
                    {
                        venQuery.product_manage = 0;
                    }
                    if (!string.IsNullOrEmpty(Request.Params["cost_percent"].ToString()))
                    {
                        venQuery.cost_percent = Convert.ToUInt32(Request.Params["cost_percent"].ToString());
                    }
                    else
                    {
                        venQuery.cost_percent = 0;
                    }
                    if (!string.IsNullOrEmpty(Request.Params["creditcard_1_percent"].ToString()))
                    {
                        venQuery.creditcard_1_percent = Convert.ToUInt32(Request.Params["creditcard_1_percent"].ToString());
                    }
                    else
                    {
                        venQuery.creditcard_1_percent = 0;
                    }
                    if (!string.IsNullOrEmpty(Request.Params["creditcard_3_percent"].ToString()))
                    {
                        venQuery.creditcard_3_percent = Request.Params["creditcard_3_percent"].ToString();
                    }
                    else
                    {
                        venQuery.creditcard_3_percent = "0";
                    }
                    if (!string.IsNullOrEmpty(Request.Params["agreement_createdate"].ToString()))
                    {
                        venQuery.agreement_createdate = Convert.ToUInt32(CommonFunction.GetPHPTime(Request.Params["agreement_createdate"].ToString()));

                    }
                    else
                    {
                        venQuery.agreement_createdate = 0;
                    }
                    if (!string.IsNullOrEmpty(Request.Params["agreement_start"].ToString()))
                    {
                        venQuery.agreement_start = Convert.ToUInt32(CommonFunction.GetPHPTime(Request.Params["agreement_start"].ToString()));
                    }
                    else
                    {
                        venQuery.agreement_start = 0;
                    }
                    if (!string.IsNullOrEmpty(Request.Params["agreement_end"].ToString()))
                    {
                        venQuery.agreement_end = Convert.ToUInt32(CommonFunction.GetPHPTime(Request.Params["agreement_end"].ToString()));
                    }
                    else
                    {
                        venQuery.agreement_end = 0;
                    }
                    if (!string.IsNullOrEmpty(Request.Params["checkout_type"].ToString()))
                    {
                        venQuery.checkout_type = Convert.ToUInt32(Request.Params["checkout_type"].ToString());
                    }
                    else
                    {
                        venQuery.checkout_type = 1;
                    }
                    if (venQuery.checkout_type == 3)
                    {
                        if (!string.IsNullOrEmpty(Request.Params["checkout_other"].ToString()))
                        {
                            venQuery.checkout_other = Request.Params["checkout_other"].ToString();
                        }
                        else
                        {
                            venQuery.checkout_other = "";
                        }
                    }
                    if (!string.IsNullOrEmpty(Request.Params["bank_code"].ToString()))
                    {
                        venQuery.bank_code = Request.Params["bank_code"].ToString();
                    }
                    else
                    {
                        venQuery.bank_code = "";
                    }
                    if (!string.IsNullOrEmpty(Request.Params["bank_name"].ToString()))
                    {
                        venQuery.bank_name = Request.Params["bank_name"].ToString();
                    }
                    else
                    {
                        venQuery.bank_name = "";
                    }
                    if (!string.IsNullOrEmpty(Request.Params["bank_number"].ToString()))
                    {
                        venQuery.bank_number = Request.Params["bank_number"].ToString();
                    }
                    else
                    {
                        venQuery.bank_number = "";
                    }
                    if (!string.IsNullOrEmpty(Request.Params["bank_account"].ToString()))
                    {
                        venQuery.bank_account = Request.Params["bank_account"].ToString();
                    }
                    else
                    {
                        venQuery.bank_account = "";
                    }
                    if (!string.IsNullOrEmpty(Request.Params["bank_number"].ToString()))
                    {
                        venQuery.bank_number = Request.Params["bank_number"].ToString();
                    }
                    else
                    {
                        venQuery.bank_number = "";
                    }
                    if (!string.IsNullOrEmpty(Request.Params["freight_low_limit"].ToString()))
                    {
                        venQuery.freight_low_limit = Convert.ToUInt32(Request.Params["freight_low_limit"].ToString());
                    }
                    else
                    {
                        venQuery.freight_low_limit = 0;
                    }
                    if (!string.IsNullOrEmpty(Request.Params["freight_low_money"].ToString()))
                    {
                        venQuery.freight_low_money = Convert.ToUInt32(Request.Params["freight_low_money"].ToString());
                    }
                    else
                    {
                        venQuery.freight_low_money = 0;
                    }
                    if (!string.IsNullOrEmpty(Request.Params["freight_return_low_money"].ToString()))
                    {
                        venQuery.freight_return_low_money = Convert.ToUInt32(Request.Params["freight_return_low_money"].ToString());
                    }
                    else
                    {
                        venQuery.freight_return_low_money = 0;
                    }
                    if (!string.IsNullOrEmpty(Request.Params["freight_normal_limit"].ToString()))
                    {
                        venQuery.freight_normal_limit = Convert.ToUInt32(Request.Params["freight_normal_limit"].ToString());
                    }
                    else
                    {
                        venQuery.freight_normal_limit = 0;
                    }
                    if (!string.IsNullOrEmpty(Request.Params["freight_normal_money"].ToString()))
                    {
                        venQuery.freight_normal_money = Convert.ToUInt32(Request.Params["freight_normal_money"].ToString());
                    }
                    else
                    {
                        venQuery.freight_normal_money = 0;
                    }
                    if (!string.IsNullOrEmpty(Request.Params["freight_return_normal_money"].ToString()))
                    {
                        venQuery.freight_return_normal_money = Convert.ToUInt32(Request.Params["freight_return_normal_money"].ToString());
                    }
                    else
                    {
                        venQuery.freight_return_normal_money = 0;
                    }
                    if (!string.IsNullOrEmpty(Request.Params["assist"].ToString()))
                    {
                        venQuery.assist = Convert.ToUInt32(Request.Params["assist"].ToString());
                    }
                    else
                    {
                        venQuery.assist = 0;
                    }
                    //if (!string.IsNullOrEmpty(Request.Params["dispatch"].ToString()))
                    //{
                    //    venQuery.dispatch = Convert.ToUInt32(Request.Params["dispatch"].ToString());
                    //}
                    //else
                    //{
                    //    venQuery.dispatch = 0;
                    //}
                    //if (!string.IsNullOrEmpty(Request.Params["product_mode"].ToString()))
                    //{
                    //    venQuery.product_mode = Convert.ToUInt32(Request.Params["product_mode"].ToString());
                    //}
                    //else
                    //{
                    //    venQuery.product_mode = 1;
                    //}
                    if (!string.IsNullOrEmpty(Request.Params["procurement_days"].ToString()))
                    {
                        venQuery.procurement_days = Convert.ToInt32(Request.Params["procurement_days"].ToString());
                    }
                    else
                    {
                        venQuery.procurement_days = 0;
                    }
                    if (!string.IsNullOrEmpty(Request.Params["self_send_days"].ToString()))
                    {
                        venQuery.self_send_days = Convert.ToInt32(Request.Params["self_send_days"].ToString());
                    }
                    else
                    {
                        venQuery.self_send_days = 0;
                    }
                    if (!string.IsNullOrEmpty(Request.Params["stuff_ware_days"].ToString()))
                    {
                        venQuery.stuff_ware_days = Convert.ToInt32(Request.Params["stuff_ware_days"].ToString());
                    }
                    else
                    {
                        venQuery.stuff_ware_days = 0;
                    }
                    if (!string.IsNullOrEmpty(Request.Params["dispatch_days"].ToString()))
                    {
                        venQuery.dispatch_days = Convert.ToInt32(Request.Params["dispatch_days"].ToString());
                    }
                    else
                    {
                        venQuery.dispatch_days = 0;
                    }

                    if (!string.IsNullOrEmpty(Request.Params["gigade_bunus_percent"].ToString()))
                    {
                        venQuery.gigade_bunus_percent = Convert.ToUInt32(Request.Params["gigade_bunus_percent"].ToString());
                    }
                    else
                    {
                        venQuery.gigade_bunus_percent = 0;
                    }
                    if (!string.IsNullOrEmpty(Request.Params["gigade_bunus_threshold"].ToString()))
                    {
                        venQuery.gigade_bunus_threshold = Convert.ToUInt32(Request.Params["gigade_bunus_threshold"].ToString());
                    }
                    else
                    {
                        venQuery.gigade_bunus_threshold = 0;
                    }
                    if (!string.IsNullOrEmpty(Request.Params["vendor_note"].ToString()))
                    {
                        venQuery.vendor_note = Request.Params["vendor_note"].ToString();
                    }
                    else
                    {
                        venQuery.vendor_note = "";
                    }

                    if (!string.IsNullOrEmpty(Request.Params["prod_cate"].ToString()))
                    {
                        venQuery.prod_cate = Request.Params["prod_cate"].ToString();
                    }
                    else
                    {
                        venQuery.prod_cate = "";
                    }
                    if (!string.IsNullOrEmpty(Request.Params["buy_cate"].ToString()))
                    {
                        venQuery.buy_cate = Request.Params["buy_cate"].ToString();
                    }
                    else
                    {
                        venQuery.buy_cate = "";
                    }
                    if (!string.IsNullOrEmpty(Request.Params["tax_type"].ToString()))
                    {
                        venQuery.tax_type = Request.Params["tax_type"].ToString();
                    }
                    else
                    {
                        venQuery.tax_type = "";
                    }
                    #endregion

                    #region   //對聯絡人的 信息處理


                    if (!string.IsNullOrEmpty(Request.Params["conactValues"].ToString()))
                    {
                        string contact = Request.Params["conactValues"].ToString();
                        string[] contactarr = contact.Split('|');
                        string[] contact1;
                        for (int i = 0; i < contactarr.Length - 1; i++)
                        {
                            contact1 = contactarr[i].Split(',');
                            if (i == 0)
                            {
                                venQuery.contact_type_1 = 4;
                                venQuery.contact_name_1 = contact1[1];
                                venQuery.contact_phone_1_1 = contact1[2];
                                venQuery.contact_phone_2_1 = contact1[3];
                                venQuery.contact_mobile_1 = contact1[4];
                                venQuery.contact_email_1 = contact1[5].ToLower();
                            }
                            else if (i == 1)
                            {
                                venQuery.contact_type_2 = Convert.ToUInt32(ContactType(contact1[0].ToString()));
                                venQuery.contact_name_2 = contact1[1];
                                venQuery.contact_phone_1_2 = contact1[2];
                                venQuery.contact_phone_2_2 = contact1[3];
                                venQuery.contact_mobile_2 = contact1[4];
                                venQuery.contact_email_2 = contact1[5].ToLower().ToLower();
                            }
                            else if (i == 2)
                            {
                                venQuery.contact_type_3 = Convert.ToUInt32(ContactType(contact1[0].ToString()));
                                venQuery.contact_name_3 = contact1[1];
                                venQuery.contact_phone_1_3 = contact1[2];
                                venQuery.contact_phone_2_3 = contact1[3];
                                venQuery.contact_mobile_3 = contact1[4];
                                venQuery.contact_email_3 = contact1[5].ToLower();
                            }
                            else if (i == 3)
                            {
                                venQuery.contact_type_4 = Convert.ToUInt32(ContactType(contact1[0].ToString()));
                                venQuery.contact_name_4 = contact1[1];
                                venQuery.contact_phone_1_4 = contact1[2];
                                venQuery.contact_phone_2_4 = contact1[3];
                                venQuery.contact_mobile_4 = contact1[4];
                                venQuery.contact_email_4 = contact1[5].ToLower();
                            }
                            else if (i == 4)
                            {
                                venQuery.contact_type_5 = Convert.ToUInt32(ContactType(contact1[0].ToString()));
                                venQuery.contact_name_5 = contact1[1];
                                venQuery.contact_phone_1_5 = contact1[2];
                                venQuery.contact_phone_2_5 = contact1[3];
                                venQuery.contact_mobile_5 = contact1[4];
                                venQuery.contact_email_5 = contact1[5].ToLower();
                            }

                        }


                    }
                    #endregion
                    venQuery.ip = Request.UserHostAddress;
                    venQuery.file_name = "VendorList.chtml";
                    venQuery.created = DateTime.Now;
                    venQuery.kuser_id = Convert.ToUInt32((System.Web.HttpContext.Current.Session["caller"] as Caller).user_id.ToString());
                    venQuery.export_flag = 1;
                    venQuery.kuser = (int)venQuery.kuser_id;
                    venQuery.kdate = venQuery.created;
                    //供應商類型
                    if (!string.IsNullOrEmpty(Request.Params["gigade_vendor_type"]))
                    {
                        venQuery.vendor_type = Request.Params["gigade_vendor_type"].ToString();
                    }
                    mgr = new CallerMgr(connectionString);
                    Caller caller = new Caller();
                    caller = mgr.GetUserById(Convert.ToInt32(venQuery.kuser_id));
                    venQuery.kuser_name = caller.user_username;

                    return VendorAdd(venQuery);
                }
                else
                {
                    venQuery.vendor_id = Convert.ToUInt32(Request.Params["vendor_id"].ToString());
                    venQuery.vendor_code = Request.Params["vendor_code"].ToString();
                    _vendorMgr = new VendorMgr(connectionString);
                    _configMgr = new ConfigMgr(connectionString);
                    Vendor oldven = _vendorMgr.GetSingle(venQuery);
                    StringBuilder update_log = new StringBuilder();
                    List<TableChangeLog> list = new List<TableChangeLog>();

                    #region 獲取供應商數據
                    uint isUint = 0;//判斷字符串是否能夠轉換為uint類型
                    if (uint.TryParse(Request.Params["vendor_status"].ToString(), out isUint))
                    {
                        venQuery.vendor_status = Convert.ToUInt32(Request.Params["vendor_status"].ToString());
                        if (oldven.vendor_status != venQuery.vendor_status)
                        {//1:啟用2:停用3:失格
                            // update_log.AppendFormat("vendor_status:{0}:{1}:供應商狀態#", oldven.vendor_status, venQuery.vendor_status);
                            TableChangeLog item = new TableChangeLog();
                            item.change_field = "vendor_status";
                            item.old_value = oldven.vendor_status.ToString();
                            item.new_value = venQuery.vendor_status.ToString();
                            item.field_ch_name = "供應商狀態";
                            list.Add(item);
                        }
                    }
                    else
                    {
                        venQuery.vendor_status = oldven.vendor_status;
                    }
                    //供應商類型
                    if (!string.IsNullOrEmpty(Request.Params["gigade_vendor_type"]))
                    {
                        venQuery.vendor_type = Request.Params["gigade_vendor_type"].ToString();

                    }
                    int tmp = 0;
                    string[] strs = venQuery.vendor_type.Split(',');
                    for (int i = 0; i < strs.Length; i++)
                    {
                        if (!int.TryParse(strs[i], out tmp))
                        {
                            venQuery.vendor_type = oldven.vendor_type;
                            break;
                        }
                    }
                    if (oldven.vendor_type != venQuery.vendor_type)
                    {
                        // update_log.AppendFormat("vendor_type:{0}:{1}:供應商類型#", oldven.vendor_type, venQuery.vendor_type);
                        TableChangeLog item = new TableChangeLog();
                        item.change_field = "vendor_type";
                        item.old_value = oldven.vendor_type;
                        item.new_value = venQuery.vendor_type;
                        item.field_ch_name = "供應商類型";
                        list.Add(item);
                    }
                    if (!string.IsNullOrEmpty(Request.Params["vendor_email"].ToString()))
                    {
                        int total = _vendorMgr.IsExitEmail(Request.Params["vendor_email"].ToString().ToLower());
                        try
                        {
                            if (total > 1)
                            {
                                jsonStr = "{success:true,msg:0}";//返回json數據
                                this.Response.Clear();
                                this.Response.Write(jsonStr);
                                this.Response.End();
                                return this.Response;
                            }
                            else
                            {
                                if (total == 1)
                                {
                                    if (Request.Params["vendor_email"].ToString().ToLower() == oldven.vendor_email.ToLower())
                                    {
                                        venQuery.vendor_email = oldven.vendor_email.ToLower();
                                    }
                                    else
                                    {
                                        jsonStr = "{success:true,msg:0}";//返回json數據rue
                                        this.Response.Clear();
                                        this.Response.Write(jsonStr);
                                        this.Response.End();
                                        return this.Response;
                                    }
                                }
                                else if (total == 0)
                                {
                                    venQuery.vendor_email = Request.Params["vendor_email"].ToString().ToLower();
                                    if (oldven.vendor_email != venQuery.vendor_email)
                                    {
                                        // update_log.AppendFormat("vendor_email:{0}:{1}:公司Email#", oldven.vendor_email, venQuery.vendor_email);
                                        TableChangeLog item = new TableChangeLog();
                                        item.change_field = "vendor_email";
                                        item.old_value = oldven.vendor_email;
                                        item.new_value = venQuery.vendor_email;
                                        item.field_ch_name = "公司Email";
                                        list.Add(item);
                                    }
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            Log4NetCustom.LogMessage logMessage = new Log4NetCustom.LogMessage();
                            logMessage.Content = string.Format("TargetSite:{0},Source:{1},Message:{2}", ex.TargetSite.Name, ex.Source, ex.Message);
                            logMessage.MethodName = System.Reflection.MethodBase.GetCurrentMethod().Name;
                            log.Error(logMessage);
                            jsonStr = "{success:false,msg:1}";
                            this.Response.Clear();
                            this.Response.Write(jsonStr);
                            this.Response.End();
                            return this.Response;
                        }
                    }
                    else
                    {
                        venQuery.vendor_email = oldven.vendor_email;
                    }
                    //if (!string.IsNullOrEmpty(Request.Params["vendor_password"].ToString()))
                    //{
                    //    BLL.gigade.Common.HashEncrypt hash = new BLL.gigade.Common.HashEncrypt();
                    //    venQuery.vendor_password = hash.SHA256Encrypt(Request.Params["vendor_password"].ToString());
                    //}
                    //else
                    //{
                    //    venQuery.vendor_password = oldven.vendor_password;
                    //}
                    if (!string.IsNullOrEmpty(Request.Params["vendor_name_full"].ToString()))
                    {
                        venQuery.vendor_name_full = Request.Params["vendor_name_full"].ToString().Trim();
                    }
                    else
                    {
                        venQuery.vendor_name_full = oldven.vendor_name_full;
                    }
                    if (!string.IsNullOrEmpty(Request.Params["vendor_name_simple"].ToString()))
                    {
                        venQuery.vendor_name_simple = Request.Params["vendor_name_simple"].ToString().Trim();
                    }
                    else
                    {
                        venQuery.vendor_name_simple = oldven.vendor_name_simple;
                    }
                    if (!string.IsNullOrEmpty(Request.Params["vendor_invoice"].ToString()))
                    {
                        venQuery.vendor_invoice = Request.Params["vendor_invoice"].ToString();
                        if (oldven.vendor_invoice != venQuery.vendor_invoice)
                        {
                            // update_log.AppendFormat("vendor_invoice:{0}:{1}:統一編號#", oldven.vendor_invoice, venQuery.vendor_invoice);
                            TableChangeLog item = new TableChangeLog();
                            item.change_field = "vendor_invoice";
                            item.old_value = oldven.vendor_invoice;
                            item.new_value = venQuery.vendor_invoice;
                            item.field_ch_name = "統一編號";
                            list.Add(item);
                        }
                    }
                    else
                    {
                        venQuery.vendor_invoice = oldven.vendor_invoice;
                    }
                    if (!string.IsNullOrEmpty(Request.Params["company_phone"].ToString()))
                    {
                        venQuery.company_phone = Request.Params["company_phone"].ToString();
                        if (oldven.company_phone != venQuery.company_phone)
                        {
                            //update_log.AppendFormat("company_phone:{0}:{1}:公司電話#", oldven.company_phone, venQuery.company_phone);
                            TableChangeLog item = new TableChangeLog();
                            item.change_field = "company_phone";
                            item.old_value = oldven.company_phone;
                            item.new_value = venQuery.company_phone;
                            item.field_ch_name = "公司電話";
                            list.Add(item);
                        }
                    }
                    else
                    {
                        venQuery.company_phone = oldven.company_phone;
                    }
                    if (!string.IsNullOrEmpty(Request.Params["company_fax"].ToString()))
                    {
                        venQuery.company_fax = Request.Params["company_fax"].ToString();
                        if (oldven.company_fax != venQuery.company_fax)
                        {
                            // update_log.AppendFormat("company_fax:{0}:{1}:公司傳真#", oldven.company_fax, venQuery.company_fax);
                            TableChangeLog item = new TableChangeLog();
                            item.change_field = "company_fax";
                            item.old_value = oldven.company_fax;
                            item.new_value = venQuery.company_fax;
                            item.field_ch_name = "公司傳真";
                            list.Add(item);
                        }
                    }


                    if (!string.IsNullOrEmpty(Request.Params["company_person"].ToString()))
                    {
                        venQuery.company_person = Request.Params["company_person"].ToString();
                        if (oldven.company_person != venQuery.company_person)
                        {
                            //update_log.AppendFormat("company_person:{0}:{1}:公司負責人#", oldven.company_person, venQuery.company_person);
                            TableChangeLog item = new TableChangeLog();
                            item.change_field = "company_person";
                            item.old_value = oldven.company_person;
                            item.new_value = venQuery.company_person;
                            item.field_ch_name = "公司負責人";
                            list.Add(item);
                        }
                    }

                    if (!string.IsNullOrEmpty(Request.Params["company_zip"].ToString()))
                    {

                        venQuery.company_zip = Convert.ToUInt32(Request.Params["company_zip"].ToString());

                    }

                    venQuery.company_address = Request.Params["company_address"].ToString();
                    if (oldven.company_zip != venQuery.company_zip || oldven.company_address != venQuery.company_address)
                    {
                        //update_log.AppendFormat("company_address:{0}:{1}:公司地址#", oldven.company_zip + "&" + oldven.company_address, venQuery.company_zip + "&" + venQuery.company_address);
                        TableChangeLog item = new TableChangeLog();
                        item.change_field = "company_address";
                        item.old_value = oldven.company_zip + "&" + oldven.company_address;
                        item.new_value = venQuery.company_zip + "&" + venQuery.company_address;
                        item.field_ch_name = "公司地址";
                        list.Add(item);
                    }
                    if (!string.IsNullOrEmpty(Request.Params["invoice_zip"].ToString()))
                    {
                        venQuery.invoice_zip = Convert.ToUInt32(Request.Params["invoice_zip"].ToString());
                    }

                    venQuery.invoice_address = Request.Params["invoice_address"].ToString();

                    if (oldven.invoice_zip != venQuery.invoice_zip || oldven.invoice_address != venQuery.invoice_address)
                    {
                        //update_log.AppendFormat("invoice_address:{0}:{1}:發票地址#", oldven.invoice_zip + "&" + oldven.invoice_address, venQuery.invoice_zip + "&" + venQuery.invoice_address);
                        TableChangeLog item = new TableChangeLog();
                        item.change_field = "invoice_address";
                        item.old_value = oldven.invoice_zip + "&" + oldven.invoice_address;
                        item.new_value = venQuery.invoice_zip + "&" + venQuery.invoice_address;
                        item.field_ch_name = "發票地址";
                        list.Add(item);
                    }
                    venQuery.erp_id = oldven.erp_id;
                    if (uint.TryParse(Request.Params["cost_percent"].ToString(), out isUint))
                    {
                        venQuery.cost_percent = Convert.ToUInt32(Request.Params["cost_percent"].ToString());
                        if (oldven.cost_percent != venQuery.cost_percent)
                        {
                            //update_log.AppendFormat("cost_percent:{0}:{1}:成本百分比#", oldven.cost_percent, venQuery.cost_percent);
                            TableChangeLog item = new TableChangeLog();
                            item.change_field = "cost_percent";
                            item.old_value = oldven.cost_percent.ToString();
                            item.new_value = venQuery.cost_percent.ToString();
                            item.field_ch_name = "成本百分比";
                            list.Add(item);
                        }
                    }
                    else
                    {
                        venQuery.cost_percent = 0;
                    }


                    if (uint.TryParse(Request.Params["creditcard_1_percent"].ToString(), out isUint))
                    {
                        venQuery.creditcard_1_percent = Convert.ToUInt32(Request.Params["creditcard_1_percent"].ToString());
                    }
                    else
                    {
                        venQuery.creditcard_1_percent = 0;
                    }

                    if (!string.IsNullOrEmpty(Request.Params["creditcard_3_percent"].ToString()))
                    {
                        venQuery.creditcard_3_percent = Request.Params["creditcard_3_percent"].ToString();
                    }
                    else
                    {
                        venQuery.creditcard_3_percent = "0";
                    }
                    if (!string.IsNullOrEmpty(Request.Params["agreement_createdate"].ToString()))
                    {
                        venQuery.agreement_createdate = Convert.ToUInt32(CommonFunction.GetPHPTime(Request.Params["agreement_createdate"].ToString()));
                        if (oldven.agreement_createdate != venQuery.agreement_createdate)
                        {

                            //update_log.AppendFormat("agreement_createdate:{0}:{1}:合約簽訂日期#", CommonFunction.GetNetTime(oldven.agreement_createdate).ToShortDateString(), CommonFunction.GetNetTime(venQuery.agreement_createdate).ToShortDateString());
                            TableChangeLog item = new TableChangeLog();
                            item.change_field = "agreement_createdate";
                            item.old_value = CommonFunction.GetNetTime(oldven.agreement_createdate).ToShortDateString();
                            item.new_value = CommonFunction.GetNetTime(venQuery.agreement_createdate).ToShortDateString();
                            item.field_ch_name = "合約簽訂日期";
                            list.Add(item);
                        }
                    }
                    else
                    {
                        venQuery.agreement_createdate = oldven.agreement_createdate;
                    }
                    if (!string.IsNullOrEmpty(Request.Params["agreement_start"].ToString()))
                    {
                        venQuery.agreement_start = Convert.ToUInt32(CommonFunction.GetPHPTime(Request.Params["agreement_start"].ToString()));
                        if (oldven.agreement_start != venQuery.agreement_start)
                        {
                            // update_log.AppendFormat("agreement_start:{0}:{1}:合約開始日#", CommonFunction.GetNetTime(oldven.agreement_start).ToShortDateString(), CommonFunction.GetNetTime(venQuery.agreement_start).ToShortDateString());
                            TableChangeLog item = new TableChangeLog();
                            item.change_field = "agreement_start";
                            item.old_value = CommonFunction.GetNetTime(oldven.agreement_start).ToShortDateString();
                            item.new_value = CommonFunction.GetNetTime(venQuery.agreement_start).ToShortDateString();
                            item.field_ch_name = "合約開始日";
                            list.Add(item);
                        }
                    }
                    else
                    {
                        venQuery.agreement_start = oldven.agreement_start;
                    }
                    if (!string.IsNullOrEmpty(Request.Params["agreement_end"].ToString()))
                    {
                        venQuery.agreement_end = Convert.ToUInt32(CommonFunction.GetPHPTime(Request.Params["agreement_end"].ToString()));
                        if (oldven.agreement_end != venQuery.agreement_end)
                        {
                            // update_log.AppendFormat("agreement_end:{0}:{1}:合約結束日#", CommonFunction.GetNetTime(oldven.agreement_end).ToShortDateString(), CommonFunction.GetNetTime(venQuery.agreement_end).ToShortDateString());
                            TableChangeLog item = new TableChangeLog();
                            item.change_field = "agreement_end";
                            item.old_value = CommonFunction.GetNetTime(oldven.agreement_end).ToShortDateString();
                            item.new_value = CommonFunction.GetNetTime(venQuery.agreement_end).ToShortDateString();
                            item.field_ch_name = "合約結束日";
                            list.Add(item);
                        }
                    }
                    else
                    {
                        venQuery.agreement_end = oldven.agreement_end;
                    }
                    if (uint.TryParse(Request.Params["checkout_type"].ToString(), out isUint))
                    {
                        venQuery.checkout_type = Convert.ToUInt32(Request.Params["checkout_type"].ToString());
                    }
                    else
                    {
                        venQuery.checkout_type = oldven.checkout_type;
                    }
                    if (venQuery.checkout_type == 3)
                    {
                        if (!string.IsNullOrEmpty(Request.Params["checkout_other"].ToString()))
                        {
                            venQuery.checkout_other = Request.Params["checkout_other"].ToString();
                        }
                        else
                        {
                            venQuery.checkout_other = oldven.checkout_other;
                        }
                    }
                    if (!string.IsNullOrEmpty(Request.Params["bank_code"].ToString()))
                    {
                        venQuery.bank_code = Request.Params["bank_code"].ToString();
                        if (oldven.bank_code != venQuery.bank_code)
                        {
                            //update_log.AppendFormat("bank_code:{0}:{1}:銀行代碼#", oldven.bank_code, venQuery.bank_code);
                            TableChangeLog item = new TableChangeLog();
                            item.change_field = "bank_code";
                            item.old_value = oldven.bank_code;
                            item.new_value = venQuery.bank_code;
                            item.field_ch_name = "銀行代碼";
                            list.Add(item);
                        }
                    }
                    else
                    {
                        venQuery.bank_code = oldven.bank_code;
                    }
                    if (!string.IsNullOrEmpty(Request.Params["bank_name"].ToString()))
                    {
                        venQuery.bank_name = Request.Params["bank_name"].ToString();
                        if (oldven.bank_name != venQuery.bank_name)
                        {
                            //update_log.AppendFormat("bank_name:{0}:{1}:銀行名稱#", oldven.bank_name, venQuery.bank_name);
                            TableChangeLog item = new TableChangeLog();
                            item.change_field = "bank_name";
                            item.old_value = oldven.bank_name;
                            item.new_value = venQuery.bank_name;
                            item.field_ch_name = "銀行名稱";
                            list.Add(item);
                        }
                    }
                    else
                    {
                        venQuery.bank_name = oldven.bank_name;
                    }
                    if (!string.IsNullOrEmpty(Request.Params["bank_number"].ToString()))
                    {
                        venQuery.bank_number = Request.Params["bank_number"].ToString();
                        if (oldven.bank_number != venQuery.bank_number)
                        {
                            // update_log.AppendFormat("bank_number:{0}:{1}:銀行賬號#", oldven.bank_number, venQuery.bank_number);
                            TableChangeLog item = new TableChangeLog();
                            item.change_field = "bank_number";
                            item.old_value = oldven.bank_number;
                            item.new_value = venQuery.bank_number;
                            item.field_ch_name = "銀行賬號";
                            list.Add(item);
                        }
                    }
                    else
                    {
                        venQuery.bank_number = oldven.bank_number;
                    }
                    if (!string.IsNullOrEmpty(Request.Params["bank_account"].ToString()))
                    {
                        venQuery.bank_account = Request.Params["bank_account"].ToString();
                        if (oldven.bank_account != venQuery.bank_account)
                        {
                            //update_log.AppendFormat("bank_account:{0}:{1}:銀行戶名#", oldven.bank_account, venQuery.bank_account);
                            TableChangeLog item = new TableChangeLog();
                            item.change_field = "bank_account";
                            item.old_value = oldven.bank_account;
                            item.new_value = venQuery.bank_account;
                            item.field_ch_name = "銀行戶名";
                            list.Add(item);
                        }
                    }
                    else
                    {
                        venQuery.bank_account = oldven.bank_account;
                    }
                    if (!string.IsNullOrEmpty(Request.Params["bank_number"].ToString()))
                    {
                        venQuery.bank_number = Request.Params["bank_number"].ToString();
                    }
                    else
                    {
                        venQuery.bank_number = oldven.bank_number;
                    }

                    if (uint.TryParse(Request.Params["freight_low_limit"].ToString(), out isUint))
                    {
                        venQuery.freight_low_limit = Convert.ToUInt32(Request.Params["freight_low_limit"].ToString());
                    }
                    else
                    {
                        venQuery.freight_low_limit = 0;
                    }
                    if (uint.TryParse(Request.Params["freight_low_money"].ToString(), out isUint))
                    {
                        venQuery.freight_low_money = Convert.ToUInt32(Request.Params["freight_low_money"].ToString());
                    }
                    else
                    {
                        venQuery.freight_low_money = 0;
                    }
                    if (uint.TryParse(Request.Params["freight_return_low_money"].ToString(), out isUint))
                    {
                        venQuery.freight_return_low_money = Convert.ToUInt32(Request.Params["freight_return_low_money"].ToString());
                    }
                    else
                    {
                        venQuery.freight_return_low_money = 0;
                    }
                    if (uint.TryParse(Request.Params["freight_normal_limit"].ToString(), out isUint))
                    {
                        venQuery.freight_normal_limit = Convert.ToUInt32(Request.Params["freight_normal_limit"].ToString());
                    }
                    else
                    {
                        venQuery.freight_normal_limit = 0;
                    }
                    if (uint.TryParse(Request.Params["freight_normal_money"].ToString(), out isUint))
                    {
                        venQuery.freight_normal_money = Convert.ToUInt32(Request.Params["freight_normal_money"].ToString());
                    }
                    else
                    {
                        venQuery.freight_normal_money = 0;
                    }
                    if (uint.TryParse(Request.Params["freight_return_normal_money"].ToString(), out isUint))
                    {
                        venQuery.freight_return_normal_money = Convert.ToUInt32(Request.Params["freight_return_normal_money"].ToString());
                    }
                    else
                    {
                        venQuery.freight_return_normal_money = 0;
                    }
                    if (uint.TryParse(Request.Params["assist"].ToString(), out isUint))
                    {
                        venQuery.assist = Convert.ToUInt32(Request.Params["assist"].ToString());
                    }
                    else
                    {
                        venQuery.assist = venQuery.assist;
                    }
                    //if (uint.TryParse(Request.Params["dispatch"].ToString(), out isUint))
                    //{
                    //    venQuery.dispatch = Convert.ToUInt32(Request.Params["dispatch"].ToString());
                    //}
                    //else
                    //{
                    //    venQuery.dispatch = 0;
                    //}
                    //if (uint.TryParse(Request.Params["product_mode"].ToString(), out isUint))
                    //{
                    //    venQuery.product_mode = Convert.ToUInt32(Request.Params["product_mode"].ToString());
                    //}
                    //else
                    //{
                    //    venQuery.product_mode = 0;
                    //}
                    //try
                    //{
                    //    //Regex email = new System.Text.RegularExpressions.Regex("(([a-z0-9]{1})([\\.a-z0-9_-]*)@([a-z0-9]+)(\\.([a-z0-9]+)){1,3})");
                    //    //Regex name = new System.Text.RegularExpressions.Regex("[\u4e00-\u9fa5]");
                    //    //if (email.IsMatch(Request.Params["pm"].ToString()))
                    //    //{
                    //    //    venQuery.product_manage = _configMgr.QueryByEmail(Request.Params["pm"].ToString());
                    //    //}
                    //    //else if (name.IsMatch(Request.Params["pm"].ToString()))
                    //    //{
                    //    //    venQuery.product_manage = _configMgr.QueryByName(Request.Params["pm"].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);
                    //    venQuery.product_manage = 0;
                    //}
                    if (!string.IsNullOrEmpty(Request.Params["procurement_days"].ToString()))
                    {
                        venQuery.procurement_days = Convert.ToInt32(Request.Params["procurement_days"].ToString());
                    }
                    else
                    {
                        venQuery.procurement_days = 0;
                    }
                    if (!string.IsNullOrEmpty(Request.Params["self_send_days"].ToString()))
                    {
                        venQuery.self_send_days = Convert.ToInt32(Request.Params["self_send_days"].ToString());
                        if (oldven.self_send_days != venQuery.self_send_days)
                        {
                            //update_log.AppendFormat("self_send_days:{0}:{1}:自出出貨天數#", oldven.self_send_days, venQuery.self_send_days);
                            TableChangeLog item = new TableChangeLog();
                            item.change_field = "self_send_days";
                            item.old_value = oldven.self_send_days.ToString();
                            item.new_value = venQuery.self_send_days.ToString();
                            item.field_ch_name = "自出出貨天數";
                            list.Add(item);
                        }
                    }
                    else
                    {
                        venQuery.self_send_days = 0;
                    }
                    if (!string.IsNullOrEmpty(Request.Params["stuff_ware_days"].ToString()))
                    {
                        venQuery.stuff_ware_days = Convert.ToInt32(Request.Params["stuff_ware_days"].ToString());
                        if (oldven.stuff_ware_days != venQuery.stuff_ware_days)
                        {
                            // update_log.AppendFormat("stuff_ware_days:{0}:{1}:寄倉出貨天數#", oldven.stuff_ware_days, venQuery.stuff_ware_days);
                            TableChangeLog item = new TableChangeLog();
                            item.change_field = "stuff_ware_days";
                            item.old_value = oldven.stuff_ware_days.ToString();
                            item.new_value = venQuery.stuff_ware_days.ToString();
                            item.field_ch_name = "寄倉出貨天數";
                            list.Add(item);
                        }
                    }
                    else
                    {
                        venQuery.stuff_ware_days = 0;
                    }
                    if (!string.IsNullOrEmpty(Request.Params["dispatch_days"].ToString()))
                    {
                        venQuery.dispatch_days = Convert.ToInt32(Request.Params["dispatch_days"].ToString());
                        if (oldven.dispatch_days != venQuery.dispatch_days)
                        {
                            // update_log.AppendFormat("dispatch_days:{0}:{1}:調度出貨天數#", oldven.dispatch_days, venQuery.dispatch_days);
                            TableChangeLog item = new TableChangeLog();
                            item.change_field = "dispatch_days";
                            item.old_value = oldven.dispatch_days.ToString();
                            item.new_value = venQuery.dispatch_days.ToString();
                            item.field_ch_name = "調度出貨天數";
                            list.Add(item);
                        }
                    }
                    else
                    {
                        venQuery.dispatch_days = 0;
                    }
                    if (Request.Params["pm"].ToString() == "")
                    {
                        venQuery.product_manage = 0;
                    }
                    else
                    {
                        if (uint.TryParse(Request.Params["pm"].ToString(), out isUint))
                        {
                            venQuery.product_manage = Convert.ToUInt32(Request.Params["pm"].ToString());
                        }
                        else
                        {
                            venQuery.product_manage = oldven.product_manage;
                        }
                    }
                    if (oldven.product_manage != venQuery.product_manage)
                    {
                        // update_log.AppendFormat("product_manage:{0}:{1}:管理人員#", oldven.product_manage, venQuery.product_manage);
                        TableChangeLog item = new TableChangeLog();
                        item.change_field = "product_manage";
                        item.old_value = oldven.product_manage.ToString();
                        item.new_value = venQuery.product_manage.ToString();
                        item.field_ch_name = "管理人員";
                        list.Add(item);
                    }
                    if (uint.TryParse(Request.Params["gigade_bunus_percent"].ToString(), out isUint))
                    {
                        venQuery.gigade_bunus_percent = Convert.ToUInt32(Request.Params["gigade_bunus_percent"].ToString());
                    }
                    else
                    {
                        venQuery.gigade_bunus_percent = 0;
                    }
                    if (uint.TryParse(Request.Params["gigade_bunus_threshold"].ToString(), out isUint))
                    {
                        venQuery.gigade_bunus_threshold = Convert.ToUInt32(Request.Params["gigade_bunus_threshold"].ToString());
                    }
                    else
                    {
                        venQuery.gigade_bunus_threshold = 0;
                    }
                    venQuery.vendor_note = Request.Params["vendor_note"].ToString();
                    #endregion

                    #region 對聯絡人的 信息處理
                    string delcon = string.Empty;

                    if (!string.IsNullOrEmpty(Request.Params["delconnect"].ToString()))
                    {
                        delcon = Request.Params["delconnect"].ToString().TrimEnd(',');
                        var delArr = delcon.Split(',');
                        int re_1 = 0, re_2 = 0, re_3 = 0;
                        if (delArr.Length == 4)
                        {
                            //update_log.AppendFormat("contact_type_2:{0}:{1}:原第二聯絡人類型#", oldven.contact_type_2, 7);                           
                            //update_log.AppendFormat("contact_name_2:{0}:{1}:原第二聯絡人姓名#", oldven.contact_name_2, "刪除");                          
                            //update_log.AppendFormat("contact_phone_1_2:{0}:{1}:原第二聯絡人電話一#", oldven.contact_phone_1_2, "刪除");
                            //update_log.AppendFormat("contact_phone_2_2:{0}:{1}:原第二聯絡人電話二#", oldven.contact_phone_2_2, "刪除");
                            //update_log.AppendFormat("contact_mobile_2:{0}:{1}:原第二聯絡人手機號碼#", oldven.contact_mobile_2, "刪除");
                            //update_log.AppendFormat("contact_email_2:{0}:{1}:原第二聯絡人郵箱#", oldven.contact_email_2, "刪除");
                            //update_log.AppendFormat("contact_type_3:{0}:{1}:原第三聯絡人類型#", oldven.contact_type_3, 7);
                            //update_log.AppendFormat("contact_name_3:{0}:{1}:原第三聯絡人姓名#", oldven.contact_name_3, "刪除");
                            //update_log.AppendFormat("contact_phone_1_3:{0}:{1}:原第三聯絡人電話一#", oldven.contact_phone_1_3, "刪除");
                            //update_log.AppendFormat("contact_phone_2_3:{0}:{1}:原第三聯絡人電話二#", oldven.contact_phone_2_3, "刪除");
                            //update_log.AppendFormat("contact_mobile_3:{0}:{1}:原第三聯絡人手機號碼#", oldven.contact_mobile_3, "刪除");
                            //update_log.AppendFormat("contact_email_3:{0}:{1}:原第三聯絡人郵箱#", oldven.contact_email_3, "刪除");
                            //update_log.AppendFormat("contact_type_4:{0}:{1}:原第四聯絡人類型#", oldven.contact_type_4, 7);
                            //update_log.AppendFormat("contact_name_4:{0}:{1}:原第四聯絡人姓名#", oldven.contact_name_4, "刪除");
                            //update_log.AppendFormat("contact_phone_1_4:{0}:{1}:原第四聯絡人電話一#", oldven.contact_phone_1_4, "刪除");
                            //update_log.AppendFormat("contact_phone_2_4:{0}:{1}:原第四聯絡人電話二#", oldven.contact_phone_2_4, "刪除");
                            //update_log.AppendFormat("contact_mobile_4:{0}:{1}:原第四聯絡人手機號碼#", oldven.contact_mobile_4, "刪除");
                            //update_log.AppendFormat("contact_email_4:{0}:{1}:原第四聯絡人郵箱#", oldven.contact_email_4, "刪除");
                            //update_log.AppendFormat("contact_type_5:{0}:{1}:第五聯絡人類型#", oldven.contact_type_5, 7);
                            //update_log.AppendFormat("contact_name_5:{0}:{1}:第五聯絡人姓名#", oldven.contact_name_5, "刪除");
                            //update_log.AppendFormat("contact_phone_1_5:{0}:{1}:第五聯絡人電話一#", oldven.contact_phone_1_5, "刪除");
                            //update_log.AppendFormat("contact_phone_2_5:{0}:{1}:第五聯絡人電話二#", oldven.contact_phone_2_5, "刪除");
                            //update_log.AppendFormat("contact_mobile_5:{0}:{1}:第五聯絡人手機號碼#", oldven.contact_mobile_5, "刪除");
                            //update_log.AppendFormat("contact_email_5:{0}:{1}:第五聯絡人郵箱#", oldven.contact_email_5, "刪除");

                            list.Add(new TableChangeLog() { change_field = "contact_type_2", old_value = oldven.contact_type_2.ToString(), new_value = "7", field_ch_name = "原第二聯絡人類型" });
                            list.Add(new TableChangeLog() { change_field = "contact_name_2", old_value = oldven.contact_name_2, new_value = "刪除", field_ch_name = "原第二聯絡人姓名" });
                            list.Add(new TableChangeLog() { change_field = "contact_phone_1_2", old_value = oldven.contact_phone_1_2, new_value = "刪除", field_ch_name = "原第二聯絡人電話一" });
                            list.Add(new TableChangeLog() { change_field = "contact_phone_2_2", old_value = oldven.contact_phone_2_2, new_value = "刪除", field_ch_name = "原第二聯絡人電話二" });
                            list.Add(new TableChangeLog() { change_field = "contact_mobile_2", old_value = oldven.contact_mobile_2, new_value = "刪除", field_ch_name = "原第二聯絡人手機號碼" });
                            list.Add(new TableChangeLog() { change_field = "contact_email_2", old_value = oldven.contact_email_2, new_value = "刪除", field_ch_name = "原第二聯絡人郵箱" });
                            list.Add(new TableChangeLog() { change_field = "contact_type_3", old_value = oldven.contact_type_3.ToString(), new_value = "7", field_ch_name = "原第三聯絡人類型" });
                            list.Add(new TableChangeLog() { change_field = "contact_name_3", old_value = oldven.contact_name_3, new_value = "刪除", field_ch_name = "原第三聯絡人姓名" });
                            list.Add(new TableChangeLog() { change_field = "contact_phone_1_3", old_value = oldven.contact_phone_1_3, new_value = "刪除", field_ch_name = "原第三聯絡人電話一" });
                            list.Add(new TableChangeLog() { change_field = "contact_phone_2_3", old_value = oldven.contact_phone_2_3, new_value = "刪除", field_ch_name = "原第三聯絡人電話二" });
                            list.Add(new TableChangeLog() { change_field = "contact_mobile_3", old_value = oldven.contact_mobile_3, new_value = "刪除", field_ch_name = "原第三聯絡人手機號碼" });
                            list.Add(new TableChangeLog() { change_field = "contact_email_3", old_value = oldven.contact_email_3, new_value = "刪除", field_ch_name = "原第三聯絡人郵箱" });
                            list.Add(new TableChangeLog() { change_field = "contact_type_4", old_value = oldven.contact_type_4.ToString(), new_value = "7", field_ch_name = "原第四聯絡人類型" });
                            list.Add(new TableChangeLog() { change_field = "contact_name_4", old_value = oldven.contact_name_4, new_value = "刪除", field_ch_name = "原第四聯絡人姓名" });
                            list.Add(new TableChangeLog() { change_field = "contact_phone_1_4", old_value = oldven.contact_phone_1_4, new_value = "刪除", field_ch_name = "原第四聯絡人電話一" });
                            list.Add(new TableChangeLog() { change_field = "contact_phone_2_4", old_value = oldven.contact_phone_2_4, new_value = "刪除", field_ch_name = "原第四聯絡人電話二" });
                            list.Add(new TableChangeLog() { change_field = "contact_mobile_4", old_value = oldven.contact_mobile_4, new_value = "刪除", field_ch_name = "原第四聯絡人手機號碼" });
                            list.Add(new TableChangeLog() { change_field = "contact_email_4", old_value = oldven.contact_email_4, new_value = "刪除", field_ch_name = "原第四聯絡人郵箱" });
                            list.Add(new TableChangeLog() { change_field = "contact_type_5", old_value = oldven.contact_type_5.ToString(), new_value = "7", field_ch_name = "第五聯絡人類型" });
                            list.Add(new TableChangeLog() { change_field = "contact_name_5", old_value = oldven.contact_name_5, new_value = "刪除", field_ch_name = "第五聯絡人姓名" });
                            list.Add(new TableChangeLog() { change_field = "contact_phone_1_5", old_value = oldven.contact_phone_1_5, new_value = "刪除", field_ch_name = "第五聯絡人電話一" });
                            list.Add(new TableChangeLog() { change_field = "contact_phone_2_5", old_value = oldven.contact_phone_2_5, new_value = "刪除", field_ch_name = "第五聯絡人電話二" });
                            list.Add(new TableChangeLog() { change_field = "contact_mobile_5", old_value = oldven.contact_mobile_5, new_value = "刪除", field_ch_name = "第五聯絡人手機號碼" });
                            list.Add(new TableChangeLog() { change_field = "contact_email_5", old_value = oldven.contact_email_5, new_value = "刪除", field_ch_name = "第五聯絡人郵箱" });
                        }
                        else
                        {
                            for (int i = 0; i < delArr.Length; i++)
                            {
                                int del = Convert.ToInt32(delArr[i]);

                                if (del == 1 && re_1 == 0 && oldven.contact_type_2 != 0)
                                {
                                    re_1++;
                                    //update_log.AppendFormat("contact_type_2:{0}:{1}:原第二聯絡人類型#", oldven.contact_type_2, 7);
                                    //update_log.AppendFormat("contact_name_2:{0}:{1}:原第二聯絡人姓名#", oldven.contact_name_2, "刪除");
                                    //update_log.AppendFormat("contact_phone_1_2:{0}:{1}:原第二聯絡人電話一#", oldven.contact_phone_1_2, "刪除");
                                    //update_log.AppendFormat("contact_phone_2_2:{0}:{1}:原第二聯絡人電話二#", oldven.contact_phone_2_2, "刪除");
                                    //update_log.AppendFormat("contact_mobile_2:{0}:{1}:原第二聯絡人手機號碼#", oldven.contact_mobile_2, "刪除");
                                    //update_log.AppendFormat("contact_email_2:{0}:{1}:原第二聯絡人郵箱#", oldven.contact_email_2, "刪除");

                                    list.Add(new TableChangeLog() { change_field = "contact_type_2", old_value = oldven.contact_type_2.ToString(), new_value = "7", field_ch_name = "原第二聯絡人類型" });
                                    list.Add(new TableChangeLog() { change_field = "contact_name_2", old_value = oldven.contact_name_2, new_value = "刪除", field_ch_name = "原第二聯絡人姓名" });
                                    list.Add(new TableChangeLog() { change_field = "contact_phone_1_2", old_value = oldven.contact_phone_1_2, new_value = "刪除", field_ch_name = "原第二聯絡人電話一" });
                                    list.Add(new TableChangeLog() { change_field = "contact_phone_2_2", old_value = oldven.contact_phone_2_2, new_value = "刪除", field_ch_name = "原第二聯絡人電話二" });
                                    list.Add(new TableChangeLog() { change_field = "contact_mobile_2", old_value = oldven.contact_mobile_2, new_value = "刪除", field_ch_name = "原第二聯絡人手機號碼" });
                                    list.Add(new TableChangeLog() { change_field = "contact_email_2", old_value = oldven.contact_email_2, new_value = "刪除", field_ch_name = "原第二聯絡人郵箱" });

                                }
                                else if (((del == 2 && re_2 == 0) || re_1 == 1) && oldven.contact_type_3 != 0)
                                {
                                    if (re_1 == 1)
                                    {
                                        re_1++;
                                    }
                                    else
                                    {
                                        re_2++;
                                    }
                                    //update_log.AppendFormat("contact_type_3:{0}:{1}:原第三聯絡人類型#", oldven.contact_type_3, 7);
                                    //update_log.AppendFormat("contact_name_3:{0}:{1}:原第三聯絡人姓名#", oldven.contact_name_3, "刪除");
                                    //update_log.AppendFormat("contact_phone_1_3:{0}:{1}:原第三聯絡人電話一#", oldven.contact_phone_1_3, "刪除");
                                    //update_log.AppendFormat("contact_phone_2_3:{0}:{1}:原第三聯絡人電話二#", oldven.contact_phone_2_3, "刪除");
                                    //update_log.AppendFormat("contact_mobile_3:{0}:{1}:原第三聯絡人手機號碼#", oldven.contact_mobile_3, "刪除");
                                    //update_log.AppendFormat("contact_email_3:{0}:{1}:原第三聯絡人郵箱#", oldven.contact_email_3, "刪除");
                                    list.Add(new TableChangeLog() { change_field = "contact_type_3", old_value = oldven.contact_type_3.ToString(), new_value = "7", field_ch_name = "原第三聯絡人類型" });
                                    list.Add(new TableChangeLog() { change_field = "contact_name_3", old_value = oldven.contact_name_3, new_value = "刪除", field_ch_name = "原第三聯絡人姓名" });
                                    list.Add(new TableChangeLog() { change_field = "contact_phone_1_3", old_value = oldven.contact_phone_1_3, new_value = "刪除", field_ch_name = "原第三聯絡人電話一" });
                                    list.Add(new TableChangeLog() { change_field = "contact_phone_2_3", old_value = oldven.contact_phone_2_3, new_value = "刪除", field_ch_name = "原第三聯絡人電話二" });
                                    list.Add(new TableChangeLog() { change_field = "contact_mobile_3", old_value = oldven.contact_mobile_3, new_value = "刪除", field_ch_name = "原第三聯絡人手機號碼" });
                                    list.Add(new TableChangeLog() { change_field = "contact_email_3", old_value = oldven.contact_email_3, new_value = "刪除", field_ch_name = "原第三聯絡人郵箱" });
                                }
                                else if (((del == 3 && re_3 == 0) || re_1 == 2 || re_2 == 1) && oldven.contact_type_4 != 0)
                                {
                                    if (re_1 == 2)
                                    {
                                        re_1++;
                                    }
                                    else if (re_2 == 1)
                                    {
                                        re_2++;
                                    }
                                    else
                                    {
                                        re_3++;
                                    }
                                    //update_log.AppendFormat("contact_type_4:{0}:{1}:原第四聯絡人類型#", oldven.contact_type_4, 7);
                                    //update_log.AppendFormat("contact_name_4:{0}:{1}:原第四聯絡人姓名#", oldven.contact_name_4, "刪除");
                                    //update_log.AppendFormat("contact_phone_1_4:{0}:{1}:原第四聯絡人電話一#", oldven.contact_phone_1_4, "刪除");
                                    //update_log.AppendFormat("contact_phone_2_4:{0}:{1}:原第四聯絡人電話二#", oldven.contact_phone_2_4, "刪除");
                                    //update_log.AppendFormat("contact_mobile_4:{0}:{1}:原第四聯絡人手機號碼#", oldven.contact_mobile_4, "刪除");
                                    //update_log.AppendFormat("contact_email_4:{0}:{1}:原第四聯絡人郵箱#", oldven.contact_email_4, "刪除");
                                    list.Add(new TableChangeLog() { change_field = "contact_type_4", old_value = oldven.contact_type_4.ToString(), new_value = "7", field_ch_name = "原第四聯絡人類型" });
                                    list.Add(new TableChangeLog() { change_field = "contact_name_4", old_value = oldven.contact_name_4, new_value = "刪除", field_ch_name = "原第四聯絡人姓名" });
                                    list.Add(new TableChangeLog() { change_field = "contact_phone_1_4", old_value = oldven.contact_phone_1_4, new_value = "刪除", field_ch_name = "原第四聯絡人電話一" });
                                    list.Add(new TableChangeLog() { change_field = "contact_phone_2_4", old_value = oldven.contact_phone_2_4, new_value = "刪除", field_ch_name = "原第四聯絡人電話二" });
                                    list.Add(new TableChangeLog() { change_field = "contact_mobile_4", old_value = oldven.contact_mobile_4, new_value = "刪除", field_ch_name = "原第四聯絡人手機號碼" });
                                    list.Add(new TableChangeLog() { change_field = "contact_email_4", old_value = oldven.contact_email_4, new_value = "刪除", field_ch_name = "原第四聯絡人郵箱" });
                                }
                                else if ((del == 4 || re_1 == 3 || re_2 == 2 || re_3 == 1) && oldven.contact_type_5 != 0)
                                {


                                    //update_log.AppendFormat("contact_type_5:{0}:{1}:第五聯絡人類型#", oldven.contact_type_5, 7);
                                    //update_log.AppendFormat("contact_name_5:{0}:{1}:第五聯絡人姓名#", oldven.contact_name_5, "刪除");
                                    //update_log.AppendFormat("contact_phone_1_5:{0}:{1}:第五聯絡人電話一#", oldven.contact_phone_1_5, "刪除");
                                    //update_log.AppendFormat("contact_phone_2_5:{0}:{1}:第五聯絡人電話二#", oldven.contact_phone_2_5, "刪除");
                                    //update_log.AppendFormat("contact_mobile_5:{0}:{1}:第五聯絡人手機號碼#", oldven.contact_mobile_5, "刪除");
                                    //update_log.AppendFormat("contact_email_5:{0}:{1}:第五聯絡人郵箱#", oldven.contact_email_5, "刪除");
                                    list.Add(new TableChangeLog() { change_field = "contact_type_5", old_value = oldven.contact_type_5.ToString(), new_value = "7", field_ch_name = "第五聯絡人類型" });
                                    list.Add(new TableChangeLog() { change_field = "contact_name_5", old_value = oldven.contact_name_5, new_value = "刪除", field_ch_name = "第五聯絡人姓名" });
                                    list.Add(new TableChangeLog() { change_field = "contact_phone_1_5", old_value = oldven.contact_phone_1_5, new_value = "刪除", field_ch_name = "第五聯絡人電話一" });
                                    list.Add(new TableChangeLog() { change_field = "contact_phone_2_5", old_value = oldven.contact_phone_2_5, new_value = "刪除", field_ch_name = "第五聯絡人電話二" });
                                    list.Add(new TableChangeLog() { change_field = "contact_mobile_5", old_value = oldven.contact_mobile_5, new_value = "刪除", field_ch_name = "第五聯絡人手機號碼" });
                                    list.Add(new TableChangeLog() { change_field = "contact_email_5", old_value = oldven.contact_email_5, new_value = "刪除", field_ch_name = "第五聯絡人郵箱" });
                                }
                            }
                        }
                    }


                    string[] contactarr = null;
                    if (!string.IsNullOrEmpty(Request.Params["conactValues"].ToString()))
                    {

                        string contact = Request.Params["conactValues"].ToString();
                        contactarr = contact.Split('|');
                    }
                    for (int i = 0; i < 5; i++)
                    {
                        string[] contact1 = null;
                        if (contactarr != null && contactarr.Length > i + 1)
                        {
                            contact1 = contactarr[i].Split(',');
                        }
                        if (i == 0)
                        {
                            if (contact1 != null)
                            {
                                venQuery.contact_type_1 = 4;
                                venQuery.contact_name_1 = contact1[1];
                                venQuery.contact_phone_1_1 = contact1[2];
                                venQuery.contact_phone_2_1 = contact1[3];
                                venQuery.contact_mobile_1 = contact1[4];
                                venQuery.contact_email_1 = contact1[5].ToLower();

                                if (oldven.contact_type_1 != venQuery.contact_type_1)
                                {
                                    // update_log.AppendFormat("contact_type_1:{0}:{1}:第一聯絡人類型#", oldven.contact_type_1, venQuery.contact_type_1);
                                    list.Add(new TableChangeLog() { change_field = "contact_type_1", old_value = oldven.contact_type_1.ToString(), new_value = venQuery.contact_type_1.ToString(), field_ch_name = "第一聯絡人類型" });
                                }
                                if (oldven.contact_name_1 != venQuery.contact_name_1)
                                {
                                    // update_log.AppendFormat("contact_name_1:{0}:{1}:第一聯絡人姓名#", oldven.contact_name_1, venQuery.contact_name_1);
                                    list.Add(new TableChangeLog() { change_field = "contact_name_1", old_value = oldven.contact_name_1, new_value = venQuery.contact_name_1, field_ch_name = "第一聯絡人姓名" });
                                }
                                if (oldven.contact_phone_1_1 != venQuery.contact_phone_1_1)
                                {
                                    //update_log.AppendFormat("contact_phone_1_1:{0}:{1}:第一聯絡人電話一#", oldven.contact_phone_1_1, venQuery.contact_phone_1_1);
                                    list.Add(new TableChangeLog() { change_field = "contact_phone_1_1", old_value = oldven.contact_phone_1_1, new_value = venQuery.contact_phone_1_1, field_ch_name = "第一聯絡人電話一" });
                                }
                                if (oldven.contact_phone_2_1 != venQuery.contact_phone_2_1)
                                {
                                    // update_log.AppendFormat("contact_phone_2_1:{0}:{1}:第一聯絡人電話二#", oldven.contact_phone_2_1, venQuery.contact_phone_2_1);
                                    list.Add(new TableChangeLog() { change_field = "contact_phone_2_1", old_value = oldven.contact_phone_2_1, new_value = venQuery.contact_phone_2_1, field_ch_name = "第一聯絡人電話二" });
                                }
                                if (oldven.contact_mobile_1 != venQuery.contact_mobile_1)
                                {
                                    // update_log.AppendFormat("contact_mobile_1:{0}:{1}:第一聯絡人手機號碼#", oldven.contact_mobile_1, venQuery.contact_mobile_1);
                                    list.Add(new TableChangeLog() { change_field = "contact_mobile_1", old_value = oldven.contact_mobile_1, new_value = venQuery.contact_mobile_1, field_ch_name = "第一聯絡人手機號碼" });
                                }
                                if (oldven.contact_email_1 != venQuery.contact_email_1)
                                {
                                    //update_log.AppendFormat("contact_email_1:{0}:{1}:第一聯絡人郵箱#", oldven.contact_email_1, venQuery.contact_email_1);
                                    list.Add(new TableChangeLog() { change_field = "contact_email_1", old_value = oldven.contact_email_1, new_value = venQuery.contact_email_1, field_ch_name = "第一聯絡人郵箱" });
                                }

                            }
                        }
                        else if (i == 1)
                        {


                            if (contact1 != null)
                            {
                                venQuery.contact_type_2 = Convert.ToUInt32(ContactType(contact1[0].ToString()));
                                venQuery.contact_name_2 = contact1[1];
                                venQuery.contact_phone_1_2 = contact1[2];
                                venQuery.contact_phone_2_2 = contact1[3];
                                venQuery.contact_mobile_2 = contact1[4];
                                venQuery.contact_email_2 = contact1[5].ToLower().ToLower();

                                if (oldven.contact_type_2 != venQuery.contact_type_2)
                                {
                                    // update_log.AppendFormat("contact_type_2:{0}:{1}:第二聯絡人類型#", oldven.contact_type_2, venQuery.contact_type_2);
                                    list.Add(new TableChangeLog() { change_field = "contact_type_2", old_value = oldven.contact_type_2.ToString(), new_value = venQuery.contact_type_2.ToString(), field_ch_name = "第二聯絡人類型" });
                                }
                                if (oldven.contact_name_2 != venQuery.contact_name_2)
                                {
                                    //update_log.AppendFormat("contact_name_2:{0}:{1}:第二聯絡人姓名#", oldven.contact_name_2, venQuery.contact_name_2);
                                    list.Add(new TableChangeLog() { change_field = "contact_name_2", old_value = oldven.contact_name_2, new_value = venQuery.contact_name_2, field_ch_name = "第二聯絡人姓名" });
                                }
                                if (oldven.contact_phone_1_2 != venQuery.contact_phone_1_2)
                                {
                                    //update_log.AppendFormat("contact_phone_1_2:{0}:{1}:第二聯絡人電話一#", oldven.contact_phone_1_2, venQuery.contact_phone_1_2);
                                    list.Add(new TableChangeLog() { change_field = "contact_phone_1_2", old_value = oldven.contact_phone_1_2, new_value = venQuery.contact_phone_1_2, field_ch_name = "第二聯絡人電話一" });
                                }
                                if (oldven.contact_phone_2_2 != venQuery.contact_phone_2_2)
                                {
                                    //update_log.AppendFormat("contact_phone_2_2:{0}:{1}:第二聯絡人電話二#", oldven.contact_phone_2_2, venQuery.contact_phone_2_2);
                                    list.Add(new TableChangeLog() { change_field = "contact_phone_2_2", old_value = oldven.contact_phone_2_2, new_value = venQuery.contact_phone_2_2, field_ch_name = "第二聯絡人電話二" });
                                }
                                if (oldven.contact_mobile_2 != venQuery.contact_mobile_2)
                                {
                                    // update_log.AppendFormat("contact_mobile_2:{0}:{1}:第二聯絡人手機號碼#", oldven.contact_mobile_2, venQuery.contact_mobile_2);
                                    list.Add(new TableChangeLog() { change_field = "contact_mobile_2", old_value = oldven.contact_mobile_2, new_value = venQuery.contact_mobile_2, field_ch_name = "第二聯絡人手機號碼" });
                                }
                                if (oldven.contact_email_2 != venQuery.contact_email_2)
                                {
                                    // update_log.AppendFormat("contact_email_2:{0}:{1}:第二聯絡人郵箱#", oldven.contact_email_2, venQuery.contact_email_2);
                                    list.Add(new TableChangeLog() { change_field = "contact_email_2", old_value = oldven.contact_email_2, new_value = venQuery.contact_email_2, field_ch_name = "第二聯絡人郵箱" });
                                }
                            }
                        }
                        else if (i == 2)
                        {


                            if (contact1 != null)
                            {
                                venQuery.contact_type_3 = Convert.ToUInt32(ContactType(contact1[0].ToString()));
                                venQuery.contact_name_3 = contact1[1];
                                venQuery.contact_phone_1_3 = contact1[2];
                                venQuery.contact_phone_2_3 = contact1[3];
                                venQuery.contact_mobile_3 = contact1[4];
                                venQuery.contact_email_3 = contact1[5].ToLower();
                                if (oldven.contact_type_3 != venQuery.contact_type_3)
                                {
                                    //update_log.AppendFormat("contact_type_3:{0}:{1}:第三聯絡人類型#", oldven.contact_type_3, venQuery.contact_type_3);
                                    list.Add(new TableChangeLog() { change_field = "contact_type_3", old_value = oldven.contact_type_3.ToString(), new_value = venQuery.contact_type_3.ToString(), field_ch_name = "第三聯絡人類型" });
                                }
                                if (oldven.contact_name_3 != venQuery.contact_name_3)
                                {
                                    //update_log.AppendFormat("contact_name_3:{0}:{1}:第三聯絡人姓名#", oldven.contact_name_3, venQuery.contact_name_3);
                                    list.Add(new TableChangeLog() { change_field = "contact_name_3", old_value = oldven.contact_name_3, new_value = venQuery.contact_name_3, field_ch_name = "第三聯絡人姓名" });
                                }
                                if (oldven.contact_phone_1_3 != venQuery.contact_phone_1_3)
                                {
                                    // update_log.AppendFormat("contact_phone_1_3:{0}:{1}:第三聯絡人電話一#", oldven.contact_phone_1_3, venQuery.contact_phone_1_3);
                                    list.Add(new TableChangeLog() { change_field = "contact_phone_1_3", old_value = oldven.contact_phone_1_3, new_value = venQuery.contact_phone_1_3, field_ch_name = "第三聯絡人電話一" });
                                }
                                if (oldven.contact_phone_2_3 != venQuery.contact_phone_2_3)
                                {
                                    // update_log.AppendFormat("contact_phone_2_3:{0}:{1}:第三聯絡人電話二#", oldven.contact_phone_2_3, venQuery.contact_phone_2_3);
                                    list.Add(new TableChangeLog() { change_field = "contact_phone_2_3", old_value = oldven.contact_phone_2_3, new_value = venQuery.contact_phone_2_3, field_ch_name = "第三聯絡人電話二" });
                                }
                                if (oldven.contact_mobile_3 != venQuery.contact_mobile_3)
                                {
                                    //  update_log.AppendFormat("contact_mobile_3:{0}:{1}:第三聯絡人手機號碼#", oldven.contact_mobile_3, venQuery.contact_mobile_3);
                                    list.Add(new TableChangeLog() { change_field = "contact_mobile_3", old_value = oldven.contact_mobile_3, new_value = venQuery.contact_mobile_3, field_ch_name = "第三聯絡人手機號碼" });
                                }
                                if (oldven.contact_email_3 != venQuery.contact_email_3)
                                {
                                    // update_log.AppendFormat("contact_email_3:{0}:{1}:第三聯絡人郵箱#", oldven.contact_email_3, venQuery.contact_email_3);
                                    list.Add(new TableChangeLog() { change_field = "contact_email_3", old_value = oldven.contact_email_3, new_value = venQuery.contact_email_3, field_ch_name = "第三聯絡人郵箱" });
                                }
                            }
                        }
                        else if (i == 3)
                        {


                            if (contact1 != null)
                            {
                                venQuery.contact_type_4 = Convert.ToUInt32(ContactType(contact1[0].ToString()));
                                venQuery.contact_name_4 = contact1[1];
                                venQuery.contact_phone_1_4 = contact1[2];
                                venQuery.contact_phone_2_4 = contact1[3];
                                venQuery.contact_mobile_4 = contact1[4];
                                venQuery.contact_email_4 = contact1[5].ToLower();
                                if (oldven.contact_type_4 != venQuery.contact_type_4)
                                {
                                    //update_log.AppendFormat("contact_type_4:{0}:{1}:第四聯絡人類型#", oldven.contact_type_4, venQuery.contact_type_4);
                                    list.Add(new TableChangeLog() { change_field = "contact_type_4", old_value = oldven.contact_type_4.ToString(), new_value = venQuery.contact_type_4.ToString(), field_ch_name = "原第四聯絡人類型" });
                                }
                                if (oldven.contact_name_4 != venQuery.contact_name_4)
                                {
                                    // update_log.AppendFormat("contact_name_4:{0}:{1}:第四聯絡人姓名#", oldven.contact_name_4, venQuery.contact_name_4);
                                    list.Add(new TableChangeLog() { change_field = "contact_name_4", old_value = oldven.contact_name_4, new_value = venQuery.contact_name_4, field_ch_name = "第四聯絡人姓名" });
                                }
                                if (oldven.contact_phone_1_4 != venQuery.contact_phone_1_4)
                                {
                                    //update_log.AppendFormat("contact_phone_1_4:{0}:{1}:第四聯絡人電話一#", oldven.contact_phone_1_4, venQuery.contact_phone_1_4);
                                    list.Add(new TableChangeLog() { change_field = "contact_phone_1_4", old_value = oldven.contact_phone_1_4, new_value = venQuery.contact_phone_1_4, field_ch_name = "第四聯絡人電話一" });
                                }
                                if (oldven.contact_phone_2_4 != venQuery.contact_phone_2_4)
                                {
                                    // update_log.AppendFormat("contact_phone_2_4:{0}:{1}:第四聯絡人電話二#", oldven.contact_phone_2_4, venQuery.contact_phone_2_4);
                                    list.Add(new TableChangeLog() { change_field = "contact_phone_2_4", old_value = oldven.contact_phone_2_4, new_value = venQuery.contact_phone_2_4, field_ch_name = "第四聯絡人電話二" });
                                }
                                if (oldven.contact_mobile_4 != venQuery.contact_mobile_4)
                                {
                                    // update_log.AppendFormat("contact_mobile_4:{0}:{1}:第四聯絡人手機號碼#", oldven.contact_mobile_4, venQuery.contact_mobile_4);
                                    list.Add(new TableChangeLog() { change_field = "contact_mobile_4", old_value = oldven.contact_mobile_4, new_value = venQuery.contact_mobile_4, field_ch_name = "第四聯絡人手機號碼" });
                                }
                                if (oldven.contact_email_4 != venQuery.contact_email_4)
                                {
                                    // update_log.AppendFormat("contact_email_4:{0}:{1}:第四聯絡人郵箱#", oldven.contact_email_4, venQuery.contact_email_4);
                                    list.Add(new TableChangeLog() { change_field = "contact_email_4", old_value = oldven.contact_email_4, new_value = venQuery.contact_email_4, field_ch_name = "第四聯絡人郵箱" });
                                }
                            }
                        }
                        else if (i == 4)
                        {


                            if (contact1 != null)
                            {
                                venQuery.contact_type_5 = Convert.ToUInt32(ContactType(contact1[0].ToString()));
                                venQuery.contact_name_5 = contact1[1];
                                venQuery.contact_phone_1_5 = contact1[2];
                                venQuery.contact_phone_2_5 = contact1[3];
                                venQuery.contact_mobile_5 = contact1[4];
                                venQuery.contact_email_5 = contact1[5].ToLower();
                                if (oldven.contact_type_5 != venQuery.contact_type_5)
                                {
                                    //update_log.AppendFormat("contact_type_5:{0}:{1}:第五聯絡人類型#", oldven.contact_type_5, venQuery.contact_type_5);
                                    list.Add(new TableChangeLog() { change_field = "contact_type_5", old_value = oldven.contact_type_5.ToString(), new_value = venQuery.contact_type_5.ToString(), field_ch_name = "第五聯絡人類型" });
                                }
                                if (oldven.contact_name_5 != venQuery.contact_name_5)
                                {
                                    // update_log.AppendFormat("contact_name_5:{0}:{1}:第五聯絡人姓名#", oldven.contact_name_5, venQuery.contact_name_5);
                                    list.Add(new TableChangeLog() { change_field = "contact_name_5", old_value = oldven.contact_name_5, new_value = venQuery.contact_name_5, field_ch_name = "第五聯絡人姓名" });
                                }
                                if (oldven.contact_phone_1_5 != venQuery.contact_phone_1_5)
                                {
                                    // update_log.AppendFormat("contact_phone_1_5:{0}:{1}:第五聯絡人電話一#", oldven.contact_phone_1_5, venQuery.contact_phone_1_5);
                                    list.Add(new TableChangeLog() { change_field = "contact_phone_1_5", old_value = oldven.contact_phone_1_5, new_value = venQuery.contact_phone_1_5, field_ch_name = "第五聯絡人電話一" });
                                }
                                if (oldven.contact_phone_2_5 != venQuery.contact_phone_2_5)
                                {
                                    // update_log.AppendFormat("contact_phone_2_5:{0}:{1}:第五聯絡人電話二#", oldven.contact_phone_2_5, venQuery.contact_phone_2_5);
                                    list.Add(new TableChangeLog() { change_field = "contact_phone_2_5", old_value = oldven.contact_phone_2_5, new_value = venQuery.contact_phone_2_5, field_ch_name = "第五聯絡人電話二" });
                                }
                                if (oldven.contact_mobile_5 != venQuery.contact_mobile_5)
                                {
                                    //update_log.AppendFormat("contact_mobile_5:{0}:{1}:第五聯絡人手機號碼#", oldven.contact_mobile_5, venQuery.contact_mobile_5);
                                    list.Add(new TableChangeLog() { change_field = "contact_mobile_5", old_value = oldven.contact_mobile_5, new_value = venQuery.contact_mobile_5, field_ch_name = "第五聯絡人手機號碼" });
                                }
                                if (oldven.contact_email_5 != venQuery.contact_email_5)
                                {
                                    //update_log.AppendFormat("contact_email_5:{0}:{1}:第五聯絡人郵箱#", oldven.contact_email_5, venQuery.contact_email_5);
                                    list.Add(new TableChangeLog() { change_field = "contact_email_5", old_value = oldven.contact_email_5, new_value = venQuery.contact_email_5, field_ch_name = "第五聯絡人郵箱" });
                                }
                            }
                        }
                    }

                    #endregion


                    venQuery.ip = Request.UserHostAddress;
                    venQuery.file_name = "VendorList.chtml";
                    venQuery.created = DateTime.Now;
                    venQuery.kuser_id = Convert.ToUInt32((System.Web.HttpContext.Current.Session["caller"] as Caller).user_id.ToString());
                    venQuery.export_flag = 1;
                    mgr = new CallerMgr(connectionString);
                    Caller caller = new Caller();
                    caller = mgr.GetUserById(Convert.ToInt32(venQuery.kuser_id));
                    venQuery.kuser_name = caller.user_username;
                    return VendorEdit(venQuery, list);
                }
            }
            catch (Exception ex)
            {
                Log4NetCustom.LogMessage logMessage = new Log4NetCustom.LogMessage();
                logMessage.Content = string.Format("TargetSite:{0},Source:{1},Message:{2}", ex.TargetSite.Name, ex.Source, ex.Message);
                logMessage.MethodName = System.Reflection.MethodBase.GetCurrentMethod().Name;
                log.Error(logMessage);
                jsonStr = "{success:false}";
            }

            this.Response.Clear();
            this.Response.Write(jsonStr.ToString());
            this.Response.End();
            return this.Response;
        }
Пример #5
0
        public HttpResponseBase QueryContactTable()
        {
            _vendorMgr = new VendorMgr(connectionString);
            DataTable _dt = new DataTable();
            _dt.Columns.Add("contact_type", typeof(string));
            _dt.Columns.Add("contact_name", typeof(string));
            _dt.Columns.Add("contact_phone1", typeof(string));
            _dt.Columns.Add("contact_phone2", typeof(string));
            _dt.Columns.Add("contact_mobile", typeof(string));
            _dt.Columns.Add("contact_email", typeof(string));
            string json = string.Empty;
            #region 字典保存出貨窗口
            Dictionary<uint, string> ContactType = new Dictionary<uint, string>();
            ContactType.Add(1, "負責人");
            ContactType.Add(2, "業務窗口");
            ContactType.Add(3, "圖/文窗口");
            ContactType.Add(4, "出貨負責窗口");
            ContactType.Add(5, "帳務連絡窗口");
            ContactType.Add(6, "客服窗口");
            #endregion
            Vendor ven = new Vendor();
            try
            {
                if (!string.IsNullOrEmpty(Request.Params["vendor_id"]))
                {

                    ven.vendor_id = Convert.ToUInt32(Request.QueryString["vendor_id"]);
                    ven = _vendorMgr.GetSingle(ven);

                }
                if (ContactType.Keys.Contains(ven.contact_type_1))
                {
                    DataRow row = _dt.NewRow();
                    row["contact_type"] = "出貨窗口";
                    row["contact_name"] = ven.contact_name_1;
                    row["contact_phone1"] = ven.contact_phone_1_1;
                    row["contact_phone2"] = ven.contact_phone_2_1;
                    row["contact_mobile"] = ven.contact_mobile_1;
                    row["contact_email"] = ven.contact_email_1;
                    _dt.Rows.Add(row);
                }
                if (ContactType.Keys.Contains(ven.contact_type_2))
                {
                    DataRow row = _dt.NewRow();
                    row["contact_type"] = ContactType[ven.contact_type_2];
                    row["contact_name"] = ven.contact_name_2;
                    row["contact_phone1"] = ven.contact_phone_1_2;
                    row["contact_phone2"] = ven.contact_phone_2_2;
                    row["contact_mobile"] = ven.contact_mobile_2;
                    row["contact_email"] = ven.contact_email_2;
                    _dt.Rows.Add(row);
                }
                if (ContactType.Keys.Contains(ven.contact_type_3))
                {
                    DataRow row = _dt.NewRow();
                    row["contact_type"] = ContactType[ven.contact_type_3];
                    row["contact_name"] = ven.contact_name_3;
                    row["contact_phone1"] = ven.contact_phone_1_3;
                    row["contact_phone2"] = ven.contact_phone_2_3;
                    row["contact_mobile"] = ven.contact_mobile_3;
                    row["contact_email"] = ven.contact_email_3;
                    _dt.Rows.Add(row);
                }
                if (ContactType.Keys.Contains(ven.contact_type_4))
                {
                    DataRow row = _dt.NewRow();
                    row["contact_type"] = ContactType[ven.contact_type_4];
                    row["contact_name"] = ven.contact_name_4;
                    row["contact_phone1"] = ven.contact_phone_1_4;
                    row["contact_phone2"] = ven.contact_phone_2_4;
                    row["contact_mobile"] = ven.contact_mobile_4;
                    row["contact_email"] = ven.contact_email_4;
                    _dt.Rows.Add(row);
                }
                if (ContactType.Keys.Contains(ven.contact_type_5))
                {
                    DataRow row = _dt.NewRow();
                    row["contact_type"] = ContactType[ven.contact_type_5];
                    row["contact_name"] = ven.contact_name_5;
                    row["contact_phone1"] = ven.contact_phone_1_5;
                    row["contact_phone2"] = ven.contact_phone_2_5;
                    row["contact_mobile"] = ven.contact_mobile_5;
                    row["contact_email"] = ven.contact_email_5;
                    _dt.Rows.Add(row);
                }
                IsoDateTimeConverter timeConverter = new IsoDateTimeConverter();
                //这里使用自定义日期格式,如果不使用的话,默认是ISO8601格式     
                timeConverter.DateTimeFormat = "yyyy-MM-dd HH:mm:ss";
                json = "{success:true,'msg':'user',data:" + JsonConvert.SerializeObject(_dt, Formatting.Indented, timeConverter) + "}";//返回json數據
            }
            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,totalCount:0,data:[]}";
            }

            this.Response.Clear();
            this.Response.Write(json);
            this.Response.End();
            return this.Response;
        }
Пример #6
0
        /// <summary>
        /// 供應商後台:訂單管理>供應商調度出貨>要出的貨物信息
        /// </summary>
        /// <returns></returns>
        public HttpResponseBase AllOrderDeliver()
        {
            uint Normal_Subtotal = 0;//常溫商品總額--
            uint Hypothermia_Subtotal = 0;//低溫商品總額---
            uint All_Normal_Subtotal = 0;//當日常溫運費總額
            uint All_Hypothermia_Subtotal = 0;//當日低溫運費總額
            uint Order_Freight_Normal = 0;//常溫運費
            uint Order_Freight_Low = 0;//低溫運費
            uint All_Order_Freight_Normal = 0;//當日常溫運費--
            uint All_Order_Freight_Low = 0;//當日低溫運費--

            string json = string.Empty;
            try
            {
                string detail_id = "";
                if (!string.IsNullOrEmpty(Request.Params["rowIDs"]))
                {
                    detail_id = Request.Params["rowIDs"];
                }
                detail_id = detail_id.TrimEnd(',');//去掉最後一個分割符號
                string[] Sid_Row = detail_id.Split(',');//拆分
                string Sid = Sid_Row[Sid_Row.Length - 1];//獲取最後一個計算出出貨時間
                //通過sid去order_slave查詢order_id;
                //通過order_id查詢在order_master中order_date_pay。
                OrderSlaveQuery query = new OrderSlaveQuery();
                query.Slave_Id = uint.Parse(Sid);
                _IOrderSlaveMgr = new OrderSlaveMgr(mySqlConnectionString);
                DateTime time = _IOrderSlaveMgr.GetOrderDatePay(query).order_date_pay;
                long endtime = CommonFunction.GetPHPTime(time.ToString("yyyy/MM/dd 23:59:59"));
                uint vendor_id = (Session["vendor"] as BLL.gigade.Model.Vendor).vendor_id;
                //(計算這些數據參照自vendor.gigade100.com/order/all_order_deliver.php 第209~266行)
                #region 計算供應商當天的常溫和冷凍的總運費
                List<OrderDetailQuery> query1 = new List<OrderDetailQuery>();
                _OrderDetailMgr = new OrderDetailMgr(mySqlConnectionString);
                query1 = _OrderDetailMgr.GetOrderDetailToSum(vendor_id, endtime);

                foreach (var item in query1)
                {
                    if (item.item_mode == 1)
                        continue;
                    if (item.Product_Freight_Set == PRODUCT_FREIGHT_NORMAL || item.Product_Freight_Set == PRODUCT_FREIGHT_NO_NORMAL)//常溫,常溫免運
                    {
                        if (item.item_mode == 2)//組合商品
                        {
                            All_Normal_Subtotal += item.Single_Price * item.parent_num;
                        }
                        else
                        {
                            All_Normal_Subtotal += item.Single_Price * item.Buy_Num;
                        }
                    }
                    else if (item.Product_Freight_Set == PRODUCT_FREIGHT_LOW || item.Product_Freight_Set == PRODUCT_FREIGHT_NO_LOW) //冷凍,冷凍免運
                    {
                        if (item.item_mode == 2)//組合商品
                        {
                            All_Hypothermia_Subtotal += item.Single_Price * item.parent_num;
                        }
                        else
                        {
                            All_Hypothermia_Subtotal += item.Single_Price * item.Buy_Num;
                        }
                    }
                }
                #endregion

                #region 計算運費


                OrderDetailQuery oddquery = new OrderDetailQuery();
                oddquery.Vendor_Id = vendor_id;
                _OrderDetailMgr = new OrderDetailMgr(mySqlConnectionString);
                int total = 0;

                string sq = string.Format(" AND os.slave_id in ({0}) ORDER BY od.slave_id ASC ,od. combined_mode ASC , od.item_mode ASC ", detail_id);
                List<OrderDetailQuery> query2 = new List<OrderDetailQuery>();
                oddquery.Start = Convert.ToInt32(Request.Params["start"] ?? "0");//用於分頁的變量
                oddquery.Limit = Convert.ToInt32(Request.Params["limit"] ?? "10");//用於分頁的變量
                query1 = _OrderDetailMgr.AllOrderDeliver(oddquery, out total, sq);

                //uint Normal_Subtotal = 0;//常溫商品總額--
                //uint Hypothermia_Subtotal = 0;//低溫商品總額---
                //uint All_Normal_Subtotal = 0;//當日常溫運費總額
                //uint All_Hypothermia_Subtotal = 0;//當日低溫運費總額
                //uint Order_Freight_Normal = 0;//常溫運費
                //uint Order_Freight_Low = 0;//低溫運費
                //uint All_Order_Freight_Normal = 0;//當日常溫運費--
                //uint All_Order_Freight_Low = 0;//當日低溫運費--


                foreach (var item in query1)
                {
                    if (item.item_mode == 1)
                        continue;
                    //商品總額計算(當下出貨金額與運費)
                    if (item.Product_Freight_Set == PRODUCT_FREIGHT_NORMAL || item.Product_Freight_Set == PRODUCT_FREIGHT_NO_NORMAL)//常溫,常溫免運
                    {
                        if (item.item_mode == 2)
                        {

                            Normal_Subtotal += item.Single_Price * item.parent_num;
                            item.Buy_Num = item.Buy_Num * item.parent_num;
                            item.Single_Price = item.Single_Price * item.parent_num;

                            //Normal_Subtotal += item.Single_Price * item.parent_num;//---
                            //item.Buy_Num = item.Buy_Num * item.parent_num;//-------
                            //item.Single_Money = item.Single_Price * item.Buy_Num;//---------
                        }
                        else
                        {
                            Normal_Subtotal += item.Single_Price * item.Buy_Num;
                            item.Single_Money = item.Single_Price * item.Buy_Num;
                        }
                    }
                    else if (item.Product_Freight_Set == PRODUCT_FREIGHT_LOW || item.Product_Freight_Set == PRODUCT_FREIGHT_NO_LOW)//低溫,低溫免運
                    {
                        if (item.item_mode == 2)
                        {
                            Hypothermia_Subtotal += item.Single_Price * item.parent_num;
                            item.Buy_Num = item.Buy_Num * item.parent_num;
                            item.Single_Price = item.Single_Price * item.parent_num;
                            //Hypothermia_Subtotal += item.Single_Price * item.parent_num;//--------
                            //item.Buy_Num = item.Buy_Num * item.parent_num;//------------
                            //item.Single_Money = item.Single_Price * item.Buy_Num;//---------
                        }
                        else
                        {
                            Hypothermia_Subtotal += item.Single_Price * item.Buy_Num;
                            item.Single_Money = item.Single_Price * item.Buy_Num;
                        }
                    }
                    query2.Add(item);
                }
                _VendorMgr = new VendorMgr(mySqlConnectionString);
                BLL.gigade.Model.Vendor vendor = new BLL.gigade.Model.Vendor();
                vendor.vendor_id = vendor_id;
                vendor = _VendorMgr.GetSingle(vendor);
                //當下運費計算
                if (Normal_Subtotal != 0)
                {
                    if (vendor.freight_normal_limit > Normal_Subtotal)
                    {
                        Order_Freight_Normal = vendor.freight_normal_money;
                    }
                }
                if (Hypothermia_Subtotal != 0)
                {
                    if (vendor.freight_low_limit > Hypothermia_Subtotal && Hypothermia_Subtotal > 0)
                    {
                        Order_Freight_Low = vendor.freight_low_money;
                    }
                }
                //批次單總額運費
                if (All_Normal_Subtotal != 0)
                {
                    if (vendor.freight_normal_limit > All_Normal_Subtotal)
                    {
                        All_Order_Freight_Normal = vendor.freight_normal_money;
                    }
                }
                if (All_Hypothermia_Subtotal != 0)
                {
                    if (vendor.freight_low_limit > All_Order_Freight_Low)
                    {
                        All_Order_Freight_Low = vendor.freight_low_money;
                    }
                }

                #endregion
                IsoDateTimeConverter timeConverter = new IsoDateTimeConverter();
                //这里使用自定义日期格式,如果不使用的话,默认是ISO8601格式     
                timeConverter.DateTimeFormat = "yyyy-MM-dd";
                json = "{success:true,Normal_Subtotal:" + Normal_Subtotal + ",Hypothermia_Subtotal:" + Hypothermia_Subtotal + ",Order_Freight_Normal:" + Order_Freight_Normal + ",Order_Freight_Low:" + Order_Freight_Low;
                json += ",All_Order_Freight_Normal:" + All_Order_Freight_Normal + ",All_Order_Freight_Low:" + All_Order_Freight_Low + ",data:" + JsonConvert.SerializeObject(query2, Formatting.Indented, timeConverter) + "}";//返回json數據
            }
            catch (Exception ex)
            {
                Log4NetCustom.LogMessage logMessage = new Log4NetCustom.LogMessage();
                logMessage.Content = string.Format("TargetSite:{0},Source:{1},Message:{2}", ex.TargetSite.Name, ex.Source, ex.Message);
                logMessage.MethodName = System.Reflection.MethodBase.GetCurrentMethod().Name;
                log.Error(logMessage);
                json = "{success:false,msg:0}";
            }
            this.Response.Clear();
            this.Response.Write(json);
            this.Response.End();
            return this.Response;
        }
Пример #7
0
        /// <summary>
        /// 匯出pdf文檔
        /// </summary>
        //public void WritePdf()
        //{
        //    string newName = string.Empty;
        //    string json = string.Empty;
        //    IpodQuery ipod = new IpodQuery();
        //    IpoQuery ipo = new IpoQuery();

        //    if (!string.IsNullOrEmpty(Request.Params["Poid"]))
        //    {
        //        ipo.po_id = Request.Params["Poid"];
        //    }
        //    if (!string.IsNullOrEmpty(Request.Params["Potype"]))
        //    {
        //        ipo.po_type = Request.Params["Potype"];
        //    }
        //    List<IpodQuery> ipodStore = new List<IpodQuery>();
        //    List<IpoQuery> ipoStore = new List<IpoQuery>();
        //    _ipoMgr = new IpoMgr(mySqlConnectionString);
        //    int totalCount = 0;
        //    ipo.IsPage = false;
        //    ipoStore = _ipoMgr.GetIpoList(ipo, out  totalCount);
        //    try
        //    {
        //        #region 採購單匯出

        //        BaseFont bf = BaseFont.CreateFont("C:\\WINDOWS\\Fonts\\simsun.ttc,1", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
        //        iTextSharp.text.Font fontChinese = new iTextSharp.text.Font(bf, 8, iTextSharp.text.Font.UNDERLINE, iTextSharp.text.BaseColor.RED);
        //        iTextSharp.text.Font font = new iTextSharp.text.Font(bf, 12, iTextSharp.text.Font.BOLD, new iTextSharp.text.BaseColor(0, 0, 0));//黑  
        //        string filename = "採購單"+ DateTime.Now.ToString("yyyyMMddHHmmss") +".pdf";
        //        Document document = new Document(PageSize.A4, (float)5, (float)5, (float)20, (float)0.5);
        //        string newPDFName = Server.MapPath(excelPath) + filename;
        //        PdfWriter writer = PdfWriter.GetInstance(document, new FileStream(newPDFName, FileMode.Create));
        //        document.Open();
        //        //運送方式

        //           _paraMgr = new ParameterMgr(mySqlConnectionString);
        //        List<Parametersrc> parameterStore = new List<Parametersrc>();


        //        parameterStore = _paraMgr.GetElementType("product_freight");

        //        for (int a = 0; a < ipoStore.Count; a++)//循環單頭
        //        {
        //            //GetIpodListExprot
        //            _ipodMgr = new IpodMgr(mySqlConnectionString);
        //            ipod = new IpodQuery();
        //            ipod.po_id = ipoStore[a].po_id;
        //            ipodStore = new List<IpodQuery>();
        //            ipodStore = _ipodMgr.GetIpodListExprot(ipod);
        //            Dictionary<int, List<IpodQuery>> product_freight_set_mapping = new Dictionary<int, List<IpodQuery>>();
        //            #region 通過運送方式把採購單分開--一張採購單,分成常溫,冷凍等採購單


        //            for (int i = 0; i < ipodStore.Count; i++)//通過運送方式保存到字典里
        //            {
        //                ipodStore[i].spec = GetProductSpec(ipodStore[i].item_id.ToString());
        //                IupcQuery upc = new IupcQuery();
        //                upc.item_id = ipodStore[i].item_id;
        //                List<IupcQuery> upcStore = new List<IupcQuery>();
        //                _IiupcMgr = new IupcMgr(mySqlConnectionString);
        //                upcStore = _IiupcMgr.GetIupcByItemID(upc);
        //                if (upcStore.Count > 0)
        //                {
        //                    ipodStore[i].upc_id = upcStore[0].upc_id;
        //                }
        //                int freiset = ipodStore[i].product_freight_set;
        //                if (!product_freight_set_mapping.Keys.Contains(freiset))
        //                {
        //                    List<IpodQuery> s = new List<IpodQuery>();
        //                    product_freight_set_mapping.Add(freiset, s);
        //                }
        //                product_freight_set_mapping[freiset].Add(ipodStore[i]);
        //            }
        //            #endregion

        //            #region 針對匯出一個而無商品的pdf


        //            if (ipodStore.Count == 0)
        //            {

        //                #region 獲取供應商信息

        //                Vendor vendor = new Vendor();
        //                _vendorMgr = new VendorMgr(mySqlConnectionString);

        //                vendor.erp_id = ipoStore[a].vend_id;
        //                vendor = _vendorMgr.GetSingle(vendor);
        //                #endregion
        //                #region 採購單標題


        //                PdfContentByte cb = writer.DirectContent;
        //                cb.BeginText();
        //                cb.SetFontAndSize(bf, 15);
        //                cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "吉甲地好市集股份有限公司", 220, 790, 0);
        //                font = new iTextSharp.text.Font(bf, 12, iTextSharp.text.Font.NORMAL, new iTextSharp.text.BaseColor(0, 0, 0));//黑
        //                cb.SetFontAndSize(bf, 12);
        //                cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "採購單" + "-" + ipoStore[a].po_type_desc, 280, 770, 0);
        //                cb.SetFontAndSize(bf, 8);
        //                cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "公司電話:", 60, 760, 0);
        //                cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "公司傳真:", 470, 760, 0);
        //                cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "製造日期:" + DateTime.Now.ToString("yyyy/MM/dd"), 60, 750, 0);
        //                cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "頁", 510, 750, 0);
        //                cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "次", 530, 750, 0);
        //                #endregion

        //                PdfPTable ptable = new PdfPTable(6);

        //                ptable.WidthPercentage = 150;//表格寬度
        //                font = new iTextSharp.text.Font(bf, 10, iTextSharp.text.Font.NORMAL, new iTextSharp.text.BaseColor(0, 0, 0));//黑  
        //                ptable.SetTotalWidth(new float[] { 82, 50, 100, 90, 110, 71 });
        //                PdfPCell cell = new PdfPCell();
        //                cell.UseAscender = true;
        //                cell.HorizontalAlignment = Element.ALIGN_CENTER;//字體垂直居中
        //                cell.VerticalAlignment = Element.ALIGN_MIDDLE;//字體水平居中
        //                cell.BorderWidth = 0.1f;
        //                cell.BorderColor = new BaseColor(0, 0, 0);

        //                #region 上部分


        //                cell = new PdfPCell(new Phrase("採購單別:" + ipoStore[a].po_type, font));
        //                cell.DisableBorderSide(2);
        //                cell.DisableBorderSide(8);
        //                ptable.AddCell(cell);
        //                cell = new PdfPCell(new Phrase("交易幣別:" + "世界貨幣", font));
        //                cell.Colspan = 2;
        //                cell.DisableBorderSide(2);
        //                cell.DisableBorderSide(4);
        //                cell.DisableBorderSide(8);
        //                ptable.AddCell(cell);
        //                cell = new PdfPCell(new Phrase("匯率:" + "浮動", font));
        //                cell.DisableBorderSide(2);
        //                cell.DisableBorderSide(4);
        //                cell.DisableBorderSide(8);
        //                ptable.AddCell(cell);
        //                cell = new PdfPCell(new Phrase("運輸方式:" , font));
        //                cell.Colspan = 2;
        //                cell.DisableBorderSide(2);
        //                cell.DisableBorderSide(4);
        //                ptable.AddCell(cell);


        //                cell = new PdfPCell(new Phrase("商品是新品么?:", font));//新品
        //                cell.Colspan = 2;
        //                cell.DisableBorderSide(1);
        //                cell.DisableBorderSide(2);
        //                cell.DisableBorderSide(8);
        //                ptable.AddCell(cell);
        //                cell = new PdfPCell(new Phrase("所在層:", font));
        //                cell.DisableBorderSide(1);
        //                cell.DisableBorderSide(2);
        //                cell.DisableBorderSide(4);
        //                cell.DisableBorderSide(8);
        //                ptable.AddCell(cell);
        //                cell = new PdfPCell(new Phrase("採購單(" + ipoStore[a].po_type_desc + ")", font));
        //                cell.DisableBorderSide(1);
        //                cell.DisableBorderSide(2);
        //                cell.DisableBorderSide(4);
        //                cell.DisableBorderSide(8);
        //                ptable.AddCell(cell);
        //                cell = new PdfPCell(new Phrase("預約到貨日期:", font));
        //                cell.Colspan = 2;
        //                cell.DisableBorderSide(1);
        //                cell.DisableBorderSide(2);
        //                cell.DisableBorderSide(4);
        //                ptable.AddCell(cell);



        //                cell = new PdfPCell(new Phrase("採購單號:" + ipoStore[a].po_id, font));
        //                cell.Colspan = 2;
        //                cell.DisableBorderSide(1);
        //                cell.DisableBorderSide(2);
        //                cell.DisableBorderSide(8);
        //                ptable.AddCell(cell);
        //                cell = new PdfPCell(new Phrase("課稅別:", font));
        //                cell.DisableBorderSide(1);
        //                cell.DisableBorderSide(2);
        //                cell.DisableBorderSide(4);
        //                cell.DisableBorderSide(8);
        //                ptable.AddCell(cell);
        //                cell = new PdfPCell(new Phrase("營業稅率:", font));
        //                cell.DisableBorderSide(1);
        //                cell.DisableBorderSide(2);
        //                cell.DisableBorderSide(4);
        //                cell.DisableBorderSide(8);
        //                ptable.AddCell(cell);
        //                cell = new PdfPCell(new Phrase("價格條件:", font));
        //                cell.Colspan = 2;
        //                cell.DisableBorderSide(1);
        //                cell.DisableBorderSide(2);
        //                cell.DisableBorderSide(4);
        //                ptable.AddCell(cell);



        //                cell = new PdfPCell(new Phrase("單據日期:" + DateTime.Now.ToString("yyyy/MM/dd"), font));
        //                cell.Colspan = 2;
        //                cell.DisableBorderSide(1);
        //                cell.DisableBorderSide(2);
        //                cell.DisableBorderSide(8);
        //                ptable.AddCell(cell);
        //                cell = new PdfPCell(new Phrase("採購人員:" + ipoStore[a].buyer, font));
        //                cell.DisableBorderSide(1);
        //                cell.DisableBorderSide(2);
        //                cell.DisableBorderSide(4);
        //                cell.DisableBorderSide(8);
        //                ptable.AddCell(cell);
        //                cell = new PdfPCell(new Phrase((System.Web.HttpContext.Current.Session["caller"] as Caller).user_username, font));
        //                cell.DisableBorderSide(1);
        //                cell.DisableBorderSide(2);
        //                cell.DisableBorderSide(4);
        //                cell.DisableBorderSide(8);
        //                ptable.AddCell(cell);
        //                cell = new PdfPCell(new Phrase("廠別代號:", font));
        //                cell.DisableBorderSide(1);
        //                cell.DisableBorderSide(2);
        //                cell.DisableBorderSide(4);
        //                cell.DisableBorderSide(8);
        //                ptable.AddCell(cell);
        //                cell = new PdfPCell(new Phrase("gigade(讀取)", font));
        //                cell.DisableBorderSide(1);
        //                cell.DisableBorderSide(2);
        //                cell.DisableBorderSide(4);
        //                ptable.AddCell(cell);



        //                cell = new PdfPCell(new Phrase("廠商代號:" + ipoStore[a].vend_id, font));
        //                cell.Colspan = 2;
        //                cell.DisableBorderSide(1);
        //                cell.DisableBorderSide(2);
        //                cell.DisableBorderSide(8);
        //                ptable.AddCell(cell);
        //                cell = new PdfPCell(new Phrase("", font));
        //                cell.DisableBorderSide(1);
        //                cell.DisableBorderSide(2);
        //                cell.DisableBorderSide(4);
        //                cell.DisableBorderSide(8);
        //                ptable.AddCell(cell);
        //                cell = new PdfPCell(new Phrase("付款條件(讀取)", font));
        //                cell.DisableBorderSide(1);
        //                cell.DisableBorderSide(2);
        //                cell.DisableBorderSide(4);
        //                cell.DisableBorderSide(8);
        //                ptable.AddCell(cell);
        //                cell = new PdfPCell(new Phrase("月結N天(讀取):", font));


        //                cell.Colspan = 3;
        //                cell.DisableBorderSide(1);
        //                cell.DisableBorderSide(2);
        //                cell.DisableBorderSide(4);
        //                ptable.AddCell(cell);
        //                cell = new PdfPCell(new Phrase("廠商全名(讀取):" , font));
        //                cell.Colspan = 4;
        //                cell.DisableBorderSide(1);
        //                cell.DisableBorderSide(2);
        //                cell.DisableBorderSide(8);
        //                ptable.AddCell(cell);
        //                cell = new PdfPCell(new Phrase("備註:", font));
        //                cell.Colspan = 2;
        //                cell.DisableBorderSide(1);
        //                cell.DisableBorderSide(2);
        //                cell.DisableBorderSide(4);


        //                ptable.AddCell(cell);
        //                cell = new PdfPCell(new Phrase("廠商地址:", font));
        //                cell.Colspan = 6;
        //                cell.DisableBorderSide(1);
        //                cell.DisableBorderSide(2);


        //                ptable.AddCell(cell);
        //                cell = new PdfPCell(new Phrase(" ", font));
        //                cell.Colspan = 6;
        //                cell.DisableBorderSide(1);
        //                cell.DisableBorderSide(2);
        //                ptable.AddCell(cell);


        //                cell = new PdfPCell(new Phrase("聯絡人(讀取):", font));
        //                cell.Colspan = 2;

        //                cell.DisableBorderSide(1);
        //                cell.DisableBorderSide(2);
        //                cell.DisableBorderSide(8);
        //                ptable.AddCell(cell);
        //                cell = new PdfPCell(new Phrase("廠商電話:" , font));
        //                cell.Colspan = 2;
        //                cell.DisableBorderSide(1);
        //                cell.DisableBorderSide(2);
        //                cell.DisableBorderSide(4);
        //                cell.DisableBorderSide(8);
        //                ptable.AddCell(cell);
        //                cell = new PdfPCell(new Phrase("廠商傳真:" , font));


        //                cell.Colspan = 2;
        //                cell.DisableBorderSide(1);
        //                cell.DisableBorderSide(2);
        //                cell.DisableBorderSide(4);
        //                ptable.AddCell(cell);
        //                cell = new PdfPCell(new Phrase("送貨地址(讀取):", font));



        //                cell.Colspan = 6;
        //                cell.DisableBorderSide(1);
        //                cell.DisableBorderSide(2);
        //                ptable.AddCell(cell);
        //                cell = new PdfPCell(new Phrase(" ", font));




        //                cell.Colspan = 6;
        //                cell.DisableBorderSide(1);
        //                cell.DisableBorderSide(2);
        //                ptable.AddCell(cell);
        //                cell = new PdfPCell(new Phrase("預計送貨日期(讀取):", font));




        //                cell.Colspan = 6;
        //                cell.DisableBorderSide(1);
        //                cell.DisableBorderSide(2);
        //                ptable.AddCell(cell);
        //                cell = new PdfPCell(new Phrase("配送聯絡人(讀取):", font));
        //                cell.Colspan = 2;
        //                cell.DisableBorderSide(1);
        //                cell.DisableBorderSide(2);
        //                cell.DisableBorderSide(8);
        //                ptable.AddCell(cell);
        //                cell = new PdfPCell(new Phrase("配送電話(讀取):", font));
        //                cell.Colspan = 2;
        //                cell.DisableBorderSide(1);
        //                cell.DisableBorderSide(2);
        //                cell.DisableBorderSide(4);
        //                cell.DisableBorderSide(8);
        //                ptable.AddCell(cell);
        //                cell = new PdfPCell(new Phrase("配送傳真(讀取):", font));


        //                cell.Colspan = 2;
        //                cell.DisableBorderSide(1);
        //                cell.DisableBorderSide(2);
        //                cell.DisableBorderSide(4);
        //                ptable.AddCell(cell);
        //                cell = new PdfPCell(new Phrase("處理備註:", font));


        //                cell.Colspan = 6;
        //                cell.DisableBorderSide(1);
        //                cell.DisableBorderSide(2);
        //                ptable.AddCell(cell);
        //                cell = new PdfPCell(new Phrase("運送備註:", font));
        //                cell.Colspan = 6;
        //                cell.DisableBorderSide(1);

        //                ptable.AddCell(cell);
        //                #endregion

        //                ptable.WriteSelectedRows(0, -1, 46, 740, writer.DirectContent);//顯示的開始行,結束航(-1為所有)x坐標,y坐標
        //                PdfPTable nulltable = new PdfPTable(2);
        //                nulltable.SetWidths(new int[] { 20, 20 });
        //                nulltable.DefaultCell.DisableBorderSide(1);
        //                nulltable.DefaultCell.DisableBorderSide(2);
        //                nulltable.DefaultCell.DisableBorderSide(4);
        //                nulltable.DefaultCell.DisableBorderSide(8);
        //                nulltable.AddCell("");
        //                nulltable.AddCell("");
        //                nulltable.SpacingAfter = 292;
        //                document.Add(nulltable);
        //                ptable = new PdfPTable(6);
        //                ptable.WidthPercentage = 86;//表格寬度
        //                font = new iTextSharp.text.Font(bf, 9, iTextSharp.text.Font.NORMAL, new iTextSharp.text.BaseColor(0, 0, 0));//黑  
        //                ptable.SetTotalWidth(new float[] { 90, 130, 50, 50, 60, 120 });
        //                cell = new PdfPCell(new Phrase("此採購單商品不存在!", font));


        //                cell.Colspan = 6;

        //                ptable.AddCell(cell);
        //                cb.EndText();
        //                document.Add(ptable);
        //                document.NewPage();


        //            }
        //            #endregion

        //            foreach (int key in product_freight_set_mapping.Keys)
        //            {
        //                #region 取出運送方式
        //                string procduct_freight = "";
        //                for (int i = 0; i < parameterStore.Count; i++)
        //                {
        //                    if (key.ToString() == parameterStore[i].ParameterCode)
        //                    {
        //                        procduct_freight = parameterStore[i].parameterName;
        //                    }
        //                }
        //                #endregion

        //                #region 獲取供應商信息

        //               Vendor vendor = new Vendor();
        //               _vendorMgr = new VendorMgr(mySqlConnectionString);

        //               vendor.erp_id = ipoStore[a].vend_id;
        //               vendor = _vendorMgr.GetSingle(vendor);
        //                #endregion
        //                #region 採購單標題


        //                PdfContentByte cb = writer.DirectContent;
        //                cb.BeginText();
        //                cb.SetFontAndSize(bf, 15);
        //                cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "吉甲地好市集股份有限公司", 220, 790, 0);
        //                font = new iTextSharp.text.Font(bf, 12, iTextSharp.text.Font.NORMAL, new iTextSharp.text.BaseColor(0, 0, 0));//黑
        //                cb.SetFontAndSize(bf, 12);
        //                cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "採購單" + "-" + ipoStore[a].po_type_desc, 280, 770, 0);
        //                cb.SetFontAndSize(bf, 8);
        //                cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "公司電話:", 60, 760, 0);
        //                cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "公司傳真:", 470, 760, 0);
        //                cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "製造日期:" + DateTime.Now.ToString("yyyy/MM/dd"), 60, 750, 0);
        //                cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "頁", 510, 750, 0);
        //                cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "次", 530, 750, 0);
        //               #endregion

        //                PdfPTable ptable = new PdfPTable(6);

        //                ptable.WidthPercentage = 150;//表格寬度
        //                font = new iTextSharp.text.Font(bf, 10, iTextSharp.text.Font.NORMAL, new iTextSharp.text.BaseColor(0, 0, 0));//黑  
        //                ptable.SetTotalWidth(new float[] { 82, 50, 100, 90, 110, 71 });
        //                PdfPCell cell = new PdfPCell();
        //                cell.UseAscender = true;
        //                cell.HorizontalAlignment = Element.ALIGN_CENTER;//字體垂直居中
        //                cell.VerticalAlignment = Element.ALIGN_MIDDLE;//字體水平居中
        //                cell.BorderWidth = 0.1f;
        //                cell.BorderColor = new BaseColor(0, 0, 0);


        //                #region 上部分


        //                cell = new PdfPCell(new Phrase("採購單別:" + ipoStore[a].po_type, font));
        //                cell.DisableBorderSide(2);
        //                cell.DisableBorderSide(8);
        //                ptable.AddCell(cell);
        //                cell = new PdfPCell(new Phrase("交易幣別:" + "世界貨幣", font));
        //                cell.Colspan = 2;
        //                cell.DisableBorderSide(2);
        //                cell.DisableBorderSide(4);
        //                cell.DisableBorderSide(8);
        //                ptable.AddCell(cell);
        //                cell = new PdfPCell(new Phrase("匯率:" + "浮動", font));
        //                cell.DisableBorderSide(2);
        //                cell.DisableBorderSide(4);
        //                cell.DisableBorderSide(8);
        //                ptable.AddCell(cell);
        //                cell = new PdfPCell(new Phrase("運輸方式:" + procduct_freight, font));
        //                cell.Colspan = 2;
        //                cell.DisableBorderSide(2);
        //                cell.DisableBorderSide(4);
        //                ptable.AddCell(cell);


        //                cell = new PdfPCell(new Phrase("商品是新品么?:", font));//新品
        //                cell.Colspan = 2;
        //                cell.DisableBorderSide(1);
        //                cell.DisableBorderSide(2);
        //                cell.DisableBorderSide(8);
        //                ptable.AddCell(cell);
        //                cell = new PdfPCell(new Phrase("所在層:", font));
        //                cell.DisableBorderSide(1);
        //                cell.DisableBorderSide(2);
        //                cell.DisableBorderSide(4);
        //                cell.DisableBorderSide(8);
        //                ptable.AddCell(cell);
        //                cell = new PdfPCell(new Phrase("採購單(" + ipoStore[a].po_type_desc + ")", font));
        //                cell.DisableBorderSide(1);
        //                cell.DisableBorderSide(2);
        //                cell.DisableBorderSide(4);
        //                cell.DisableBorderSide(8);
        //                ptable.AddCell(cell);
        //                cell = new PdfPCell(new Phrase("預約到貨日期:", font));
        //                cell.Colspan = 2;
        //                cell.DisableBorderSide(1);
        //                cell.DisableBorderSide(2);
        //                cell.DisableBorderSide(4);
        //                ptable.AddCell(cell);



        //                cell = new PdfPCell(new Phrase("採購單號:" + ipoStore[a].po_id, font));
        //                cell.Colspan = 2;
        //                cell.DisableBorderSide(1);
        //                cell.DisableBorderSide(2);
        //                cell.DisableBorderSide(8);
        //                ptable.AddCell(cell);
        //                cell = new PdfPCell(new Phrase("課稅別:", font));
        //                cell.DisableBorderSide(1);
        //                cell.DisableBorderSide(2);
        //                cell.DisableBorderSide(4);
        //                cell.DisableBorderSide(8);
        //                ptable.AddCell(cell);
        //                cell = new PdfPCell(new Phrase("營業稅率:", font));
        //                cell.DisableBorderSide(1);
        //                cell.DisableBorderSide(2);
        //                cell.DisableBorderSide(4);
        //                cell.DisableBorderSide(8);
        //                ptable.AddCell(cell);
        //                cell = new PdfPCell(new Phrase("價格條件:", font));
        //                cell.Colspan = 2;
        //                cell.DisableBorderSide(1);
        //                cell.DisableBorderSide(2);
        //                cell.DisableBorderSide(4);
        //                ptable.AddCell(cell);



        //                cell = new PdfPCell(new Phrase("單據日期:" + DateTime.Now.ToString("yyyy/MM/dd"), font));
        //                cell.Colspan = 2;
        //                cell.DisableBorderSide(1);
        //                cell.DisableBorderSide(2);
        //                cell.DisableBorderSide(8);
        //                ptable.AddCell(cell);
        //                cell = new PdfPCell(new Phrase("採購人員:" + ipoStore[a].buyer, font));
        //                cell.DisableBorderSide(1);
        //                cell.DisableBorderSide(2);
        //                cell.DisableBorderSide(4);
        //                cell.DisableBorderSide(8);
        //                ptable.AddCell(cell);
        //                cell = new PdfPCell(new Phrase((System.Web.HttpContext.Current.Session["caller"] as Caller).user_username, font));
        //                cell.DisableBorderSide(1);
        //                cell.DisableBorderSide(2);
        //                cell.DisableBorderSide(4);
        //                cell.DisableBorderSide(8);
        //                ptable.AddCell(cell);
        //                cell = new PdfPCell(new Phrase("廠別代號:" , font));
        //                cell.DisableBorderSide(1);
        //                cell.DisableBorderSide(2);
        //                cell.DisableBorderSide(4);
        //                cell.DisableBorderSide(8);
        //                ptable.AddCell(cell);
        //                cell = new PdfPCell(new Phrase("gigade(讀取)", font));
        //                cell.DisableBorderSide(1);
        //                cell.DisableBorderSide(2);
        //                cell.DisableBorderSide(4);
        //                ptable.AddCell(cell);



        //                cell = new PdfPCell(new Phrase("廠商代號:" + ipoStore[a].vend_id, font));
        //                cell.Colspan = 2;
        //                cell.DisableBorderSide(1);
        //                cell.DisableBorderSide(2);
        //                cell.DisableBorderSide(8);
        //                ptable.AddCell(cell);
        //                cell = new PdfPCell(new Phrase(vendor == null ? "暫無此信息" : vendor.vendor_name_simple, font));
        //                cell.DisableBorderSide(1);
        //                cell.DisableBorderSide(2);
        //                cell.DisableBorderSide(4);
        //                cell.DisableBorderSide(8);
        //                ptable.AddCell(cell);
        //                cell = new PdfPCell(new Phrase("付款條件(讀取)", font));
        //                cell.DisableBorderSide(1);
        //                cell.DisableBorderSide(2);
        //                cell.DisableBorderSide(4);
        //                cell.DisableBorderSide(8);
        //                ptable.AddCell(cell);
        //                cell = new PdfPCell(new Phrase("月結N天(讀取):", font));


        //                cell.Colspan = 3;
        //                cell.DisableBorderSide(1);
        //                cell.DisableBorderSide(2);
        //                cell.DisableBorderSide(4);
        //                ptable.AddCell(cell);
        //                cell = new PdfPCell(new Phrase(vendor == null ? "廠商全名(讀取):暫無此信息" :"廠商全名:"+ vendor.vendor_name_full, font));
        //                cell.Colspan = 4;
        //                cell.DisableBorderSide(1);
        //                cell.DisableBorderSide(2);
        //                cell.DisableBorderSide(8);
        //                ptable.AddCell(cell);
        //                cell = new PdfPCell(new Phrase("備註:", font));
        //                cell.Colspan = 2;
        //                cell.DisableBorderSide(1);
        //                cell.DisableBorderSide(2);
        //                cell.DisableBorderSide(4);


        //                ptable.AddCell(cell);
        //                cell = new PdfPCell(new Phrase(vendor == null ? "廠商地址:暫無此信息" : "廠商地址:"+vendor.company_address, font));
        //                cell.Colspan = 6;
        //                cell.DisableBorderSide(1);
        //                cell.DisableBorderSide(2);


        //                ptable.AddCell(cell);
        //                cell = new PdfPCell(new Phrase(" ", font));
        //                cell.Colspan = 6;
        //                cell.DisableBorderSide(1);
        //                cell.DisableBorderSide(2);
        //                ptable.AddCell(cell);


        //                cell = new PdfPCell(new Phrase("聯絡人(讀取):", font));
        //                cell.Colspan = 2;

        //                cell.DisableBorderSide(1);
        //                cell.DisableBorderSide(2);
        //                cell.DisableBorderSide(8);
        //                ptable.AddCell(cell);
        //                cell = new PdfPCell(new Phrase(vendor == null?"廠商電話:暫無此信息" :"廠商電話:"+ vendor.company_phone, font));
        //                cell.Colspan = 2;
        //                cell.DisableBorderSide(1);
        //                cell.DisableBorderSide(2);
        //                cell.DisableBorderSide(4);
        //                cell.DisableBorderSide(8);
        //                ptable.AddCell(cell);
        //                cell = new PdfPCell(new Phrase(vendor == null? "廠商傳真:暫無此信息" :"廠商傳真:"+ vendor.company_fax, font));


        //                cell.Colspan = 2;
        //                cell.DisableBorderSide(1);
        //                cell.DisableBorderSide(2);
        //                cell.DisableBorderSide(4);
        //                ptable.AddCell(cell);
        //                cell = new PdfPCell(new Phrase("送貨地址(讀取):", font));



        //                cell.Colspan = 6;
        //                cell.DisableBorderSide(1);
        //                cell.DisableBorderSide(2);
        //                ptable.AddCell(cell);
        //                cell = new PdfPCell(new Phrase(" ", font));




        //                cell.Colspan = 6;
        //                cell.DisableBorderSide(1);
        //                cell.DisableBorderSide(2);
        //                ptable.AddCell(cell);
        //                cell = new PdfPCell(new Phrase("預計送貨日期(讀取):", font));




        //                cell.Colspan = 6;
        //                cell.DisableBorderSide(1);
        //                cell.DisableBorderSide(2);
        //                ptable.AddCell(cell);
        //                cell = new PdfPCell(new Phrase("配送聯絡人(讀取):", font));
        //                cell.Colspan = 2;
        //                cell.DisableBorderSide(1);
        //                cell.DisableBorderSide(2);
        //                cell.DisableBorderSide(8);
        //                ptable.AddCell(cell);
        //                cell = new PdfPCell(new Phrase("配送電話(讀取):", font));
        //                cell.Colspan = 2;
        //                cell.DisableBorderSide(1);
        //                cell.DisableBorderSide(2);
        //                cell.DisableBorderSide(4);
        //                cell.DisableBorderSide(8);
        //                ptable.AddCell(cell);
        //                cell = new PdfPCell(new Phrase("配送傳真(讀取):", font));


        //                cell.Colspan = 2;
        //                cell.DisableBorderSide(1);
        //                cell.DisableBorderSide(2);
        //                cell.DisableBorderSide(4);
        //                ptable.AddCell(cell);
        //                cell = new PdfPCell(new Phrase("處理備註:", font));


        //                cell.Colspan = 6;
        //                cell.DisableBorderSide(1);
        //                cell.DisableBorderSide(2);
        //                ptable.AddCell(cell);
        //                cell = new PdfPCell(new Phrase("運送備註:", font));
        //                cell.Colspan = 6;
        //                cell.DisableBorderSide(1);

        //                ptable.AddCell(cell);
        //                #endregion


        //                ptable.WriteSelectedRows(0, -1, 46, 740, writer.DirectContent);//顯示的開始行,結束航(-1為所有)x坐標,y坐標
        //                PdfPTable nulltable = new PdfPTable(2);
        //                nulltable.SetWidths(new int[] { 20, 20 });
        //                nulltable.DefaultCell.DisableBorderSide(1);
        //                nulltable.DefaultCell.DisableBorderSide(2);
        //                nulltable.DefaultCell.DisableBorderSide(4);
        //                nulltable.DefaultCell.DisableBorderSide(8);
        //                nulltable.AddCell("");
        //                nulltable.AddCell("");
        //                nulltable.SpacingAfter = 292;
        //                document.Add(nulltable);
        //                ptable = new PdfPTable(6);
        //                ptable.WidthPercentage = 86;//表格寬度
        //                font = new iTextSharp.text.Font(bf, 9, iTextSharp.text.Font.NORMAL, new iTextSharp.text.BaseColor(0, 0, 0));//黑  
        //                ptable.SetTotalWidth(new float[] { 90, 130, 50, 50, 60, 120 });
        //                #region 下面表格頭部

        //                cell = new PdfPCell(new Phrase("條碼", font));
        //                cell.Rowspan = 2;
        //                cell.DisableBorderSide(1);
        //                cell.DisableBorderSide(2);
        //                ptable.AddCell(cell);
        //                cell = new PdfPCell(new Phrase("品號", font));
        //                cell.DisableBorderSide(1);
        //                cell.DisableBorderSide(2);
        //                cell.DisableBorderSide(4);
        //                ptable.AddCell(cell);
        //                cell = new PdfPCell(new Phrase("採購數量", font));
        //                cell.HorizontalAlignment = Element.ALIGN_RIGHT;//.setHorizontalAlignment(Element.ALIGN_CENTER);
        //                cell.DisableBorderSide(1);
        //                cell.DisableBorderSide(2);
        //                cell.DisableBorderSide(4);
        //                ptable.AddCell(cell);
        //                cell = new PdfPCell(new Phrase("允收天數", font));
        //                cell.HorizontalAlignment = Element.ALIGN_RIGHT;
        //                cell.DisableBorderSide(1);
        //                cell.DisableBorderSide(2);
        //                cell.DisableBorderSide(4);
        //                ptable.AddCell(cell);
        //                cell = new PdfPCell(new Phrase("製造日期", font));
        //                cell.DisableBorderSide(1);
        //                cell.DisableBorderSide(2);
        //                cell.DisableBorderSide(4);
        //                ptable.AddCell(cell);
        //                cell = new PdfPCell(new Phrase("備註", font));
        //                cell.Rowspan = 3;
        //                cell.DisableBorderSide(1);
        //                cell.DisableBorderSide(4);
        //                ptable.AddCell(cell);




        //                cell = new PdfPCell(new Phrase("品名", font));
        //                cell.DisableBorderSide(1);
        //                cell.DisableBorderSide(2);
        //                cell.DisableBorderSide(4);
        //                ptable.AddCell(cell);
        //                cell = new PdfPCell(new Phrase("允收數量", font));
        //                cell.HorizontalAlignment = Element.ALIGN_RIGHT;//.setHorizontalAlignment(Element.ALIGN_CENTER);
        //                cell.DisableBorderSide(1);
        //                cell.DisableBorderSide(2);
        //                cell.DisableBorderSide(4);
        //                ptable.AddCell(cell);
        //                cell = new PdfPCell(new Phrase("允出天數", font));
        //                cell.HorizontalAlignment = Element.ALIGN_RIGHT;//.setHorizontalAlignment(Element.ALIGN_CENTER);
        //                cell.DisableBorderSide(1);
        //                cell.DisableBorderSide(2);
        //                cell.DisableBorderSide(4);
        //                ptable.AddCell(cell);
        //                cell = new PdfPCell(new Phrase("有效日期", font));
        //                cell.DisableBorderSide(1);
        //                cell.DisableBorderSide(4);
        //                cell.Rowspan = 2;
        //                ptable.AddCell(cell);



        //                cell = new PdfPCell(new Phrase("料位", font));
        //                cell.DisableBorderSide(1);
        //                ptable.AddCell(cell);
        //                cell = new PdfPCell(new Phrase("規格", font));
        //                cell.DisableBorderSide(1);
        //                cell.DisableBorderSide(4);
        //                ptable.AddCell(cell);
        //                cell = new PdfPCell(new Phrase("不允收數量", font));
        //                cell.HorizontalAlignment = Element.ALIGN_RIGHT;
        //                cell.DisableBorderSide(1);
        //                cell.DisableBorderSide(4);
        //                ptable.AddCell(cell);
        //                cell = new PdfPCell(new Phrase("有效期天數", font));
        //                cell.HorizontalAlignment = Element.ALIGN_RIGHT;//.setHorizontalAlignment(Element.ALIGN_CENTER);
        //                cell.DisableBorderSide(1);
        //                cell.DisableBorderSide(4);
        //                ptable.AddCell(cell);


        //                #endregion
        //                _ipodMgr = new IpodMgr(mySqlConnectionString);
        //                ipod = new IpodQuery();
        //                ipod.po_id = ipoStore[a].po_id;
        //                ipod.IsPage = false;
        //                ipodStore = new List<IpodQuery>();
        //                ipodStore = _ipodMgr.GetIpodList(ipod, out totalCount);


        //                List<IpodQuery> Ipodleibie = new List<IpodQuery>();
        //                Ipodleibie.AddRange(product_freight_set_mapping[key]);

        //                #region 循環讀取數據填入表格


        //                for (int i = 0; i < Ipodleibie.Count; i++)
        //                {
        //                    //string sResult = "";
        //                    //if (ipodStore[i].pod_id.ToString().Length < 4)
        //                    //{
        //                    //    for (int n = 0; n < 4 - (ipodStore[i].pod_id.ToString().Length); n++)
        //                    //    {
        //                    //        sResult += "0";
        //                    //    }

        //                    //}
        //                    cell = new PdfPCell(new Phrase(Ipodleibie[i].upc_id, font));//條碼
        //                    cell.Rowspan = 2;
        //                    cell.DisableBorderSide(1);
        //                    cell.DisableBorderSide(2);
        //                    ptable.AddCell(cell);
        //                    cell = new PdfPCell(new Phrase(Ipodleibie[i].Erp_Id.ToString(), font));//品號
        //                    cell.DisableBorderSide(1);
        //                    cell.DisableBorderSide(2);
        //                    cell.DisableBorderSide(4);
        //                    ptable.AddCell(cell);
        //                    cell = new PdfPCell(new Phrase(Ipodleibie[i].qty_ord.ToString(), font));//採購數量qty_ord
        //                    cell.HorizontalAlignment = Element.ALIGN_RIGHT;//.setHorizontalAlignment(Element.ALIGN_CENTER);
        //                    cell.DisableBorderSide(1);
        //                    cell.DisableBorderSide(2);
        //                    cell.DisableBorderSide(4);
        //                    ptable.AddCell(cell);
        //                    cell = new PdfPCell(new Phrase(Ipodleibie[i].cde_dt_var.ToString(), font));//允收天數cde_dt_var
        //                    cell.DisableBorderSide(1);
        //                    cell.DisableBorderSide(2);
        //                    cell.DisableBorderSide(4);
        //                    cell.HorizontalAlignment = Element.ALIGN_RIGHT;//.setHorizontalAlignment(Element.ALIGN_CENTER);
        //                    ptable.AddCell(cell);
        //                    cell = new PdfPCell(new Phrase("", font));//製造日期
        //                    cell.DisableBorderSide(1);
        //                    cell.DisableBorderSide(2);
        //                    cell.DisableBorderSide(4);
        //                    ptable.AddCell(cell);
        //                    cell = new PdfPCell(new Phrase("", font));//備註
        //                    cell.Rowspan = 3;
        //                    cell.DisableBorderSide(1);
        //                    cell.DisableBorderSide(4);
        //                    ptable.AddCell(cell);




        //                    cell = new PdfPCell(new Phrase(Ipodleibie[i].product_name, font));//品名
        //                    cell.DisableBorderSide(1);
        //                    cell.DisableBorderSide(2);
        //                    cell.DisableBorderSide(4);
        //                    ptable.AddCell(cell);
        //                    cell = new PdfPCell(new Phrase(Ipodleibie[i].qty_claimed.ToString(), font));//允收數量
        //                    cell.HorizontalAlignment = Element.ALIGN_RIGHT;//.setHorizontalAlignment(Element.ALIGN_CENTER);
        //                    cell.DisableBorderSide(1);
        //                    cell.DisableBorderSide(2);
        //                    cell.DisableBorderSide(4);
        //                    ptable.AddCell(cell);
        //                    cell = new PdfPCell(new Phrase(Ipodleibie[i].cde_dt_shp.ToString(), font));//允出天數
        //                    cell.HorizontalAlignment = Element.ALIGN_RIGHT;//.setHorizontalAlignment(Element.ALIGN_CENTER);
        //                    cell.DisableBorderSide(1);
        //                    cell.DisableBorderSide(2);
        //                    cell.DisableBorderSide(4);
        //                    ptable.AddCell(cell);
        //                    cell = new PdfPCell(new Phrase("", font));//有效日期
        //                    cell.DisableBorderSide(1);
        //                    cell.DisableBorderSide(4);
        //                    cell.Rowspan = 2;
        //                    ptable.AddCell(cell);



        //                    cell = new PdfPCell(new Phrase(Ipodleibie[i].loc_id, font));//料位
        //                    cell.DisableBorderSide(1);
        //                    ptable.AddCell(cell);
        //                    cell = new PdfPCell(new Phrase(Ipodleibie[i].spec, font));//規格
        //                    cell.DisableBorderSide(1);
        //                    cell.DisableBorderSide(4);
        //                    ptable.AddCell(cell);
        //                    cell = new PdfPCell(new Phrase(Ipodleibie[i].qty_damaged.ToString(), font));//不允收數量
        //                    cell.HorizontalAlignment = Element.ALIGN_RIGHT;
        //                    cell.DisableBorderSide(1);
        //                    cell.DisableBorderSide(4);
        //                    ptable.AddCell(cell);
        //                    cell = new PdfPCell(new Phrase(Ipodleibie[i].cde_dt_incr.ToString(), font));//有效期天數
        //                    cell.HorizontalAlignment = Element.ALIGN_RIGHT;
        //                    cell.DisableBorderSide(1);
        //                    cell.DisableBorderSide(4);
        //                    ptable.AddCell(cell);
        //                }
        //                #endregion

        //                //cell = new PdfPCell(new Phrase(" 數量合計:" + 5, font));
        //                //cell.Colspan = 2;

        //                //cell.DisableBorderSide(1);

        //                //cell.DisableBorderSide(8);
        //                //cell.HorizontalAlignment = Element.ALIGN_CENTER;
        //                //ptable.AddCell(cell);
        //                //cell = new PdfPCell(new Phrase(" 採購金額:", font));
        //                //cell.Colspan = 2;
        //                //cell.HorizontalAlignment = Element.ALIGN_CENTER;
        //                //cell.DisableBorderSide(1);

        //                //cell.DisableBorderSide(4);
        //                //cell.DisableBorderSide(8);
        //                //ptable.AddCell(cell);
        //                //cell = new PdfPCell(new Phrase(" 稅額:", font));
        //                //cell.Colspan = 2;
        //                //cell.HorizontalAlignment = Element.ALIGN_CENTER;
        //                //cell.DisableBorderSide(1);

        //                //cell.DisableBorderSide(4);
        //                //ptable.AddCell(cell);
        //                //cell = new PdfPCell(new Phrase(" 金額合計:", font));
        //                //cell.Colspan = 2;

        //                //cell.DisableBorderSide(1);
        //                //cell.DisableBorderSide(4);

        //                //ptable.AddCell(cell);
        //                //Sumtable.AddCell(ptable);

        //                cb.EndText();
        //                // Sumtable.SpacingAfter = 0;
        //                ptable.SpacingAfter = 250;
        //                //Sumtable.WriteSelectedRows(0, -1, 60, 740, writer.DirectContent);//顯示的開始行,結束航(-1為所有)x坐標,y坐標
        //                document.Add(ptable);
        //                document.NewPage();


        //            }






        //    }


        //        document.Close();
        //        writer.Resume();

        //        Response.Clear();
        //        Response.Charset = "gb2312";
        //        Response.ContentEncoding = System.Text.Encoding.UTF8;
        //        Response.AddHeader("Content-Disposition", "attach-ment;filename=" + filename);
        //        Response.WriteFile(newPDFName);
        //        //}
        //        #endregion


        //        //}
        //    }
        //    catch (Exception ex)
        //    {
        //        //cb.EndText();
        //        //writer.Resume();
        //        //Response.Clear();

        //    }
        //}
        public void WritePdf()
        {
            PdfHelper pdf = new PdfHelper();
            List<string> pdfList = new List<string>();
            //float[] arrColWidth_pftable = new float[] { 30,100, 80, 60, 60, 60, 60 };
            float[] arrColWidth = new float[] { 30, 100, 80, 60, 60, 60, 60 };
            int index = 0;
            string newFileName = string.Empty;
            string newName = string.Empty;
            string json = string.Empty;
            IpodQuery ipod = new IpodQuery();
            IpoQuery ipo = new IpoQuery();

            if (!string.IsNullOrEmpty(Request.Params["Poid"]))
            {
                ipo.po_id = Request.Params["Poid"];
            }
            if (!string.IsNullOrEmpty(Request.Params["Potype"]))
            {
                ipo.po_type = Request.Params["Potype"];
            }
            if (!string.IsNullOrEmpty(Request.Params["start_time"]))
            {
                ipo.start_time = Convert.ToDateTime(Request.Params["start_time"].ToString());
            }
            if (!string.IsNullOrEmpty(Request.Params["end_time"]))
            {
                ipo.end_time = Convert.ToDateTime(Request.Params["end_time"].ToString());
            }
            if (!string.IsNullOrEmpty(Request.Params["freight"]))
            {
                ipo.freight = Convert.ToInt32(Request.Params["freight"].ToString());
            }
            List<IpodQuery> ipodStore = new List<IpodQuery>();
            List<IpoQuery> ipoStore = new List<IpoQuery>();
            _ipoMgr = new IpoMgr(mySqlConnectionString);
            int totalCount = 0;
            ipo.IsPage = false;
            ipoStore = _ipoMgr.GetIpoList(ipo, out  totalCount);
            //if (!string.IsNullOrEmpty(Request.Params["freight"]))
            //{
            //    if (Request.Params["freight"].ToString() != "0")
            //    {
            //        _ipodMgr = new IpodMgr(mySqlConnectionString);
            //        List<IpoQuery> newstore = new List<IpoQuery>();
            //        foreach (IpoQuery item in ipoStore)
            //        {
            //            if (!string.IsNullOrEmpty(item.po_id))
            //            {
            //                if (_ipodMgr.GetIpodfreight(item.po_id, Convert.ToInt32(Request.Params["freight"].ToString())))
            //                {
            //                    newstore.Add(item);
            //                }
            //            }
            //        }
            //        ipoStore = newstore;
            //    }
            //}
            try
            {
                #region 採購單匯出

                BaseFont bf = BaseFont.CreateFont("C:\\WINDOWS\\Fonts\\simsun.ttc,1", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
                iTextSharp.text.Font fontChinese = new iTextSharp.text.Font(bf, 8, iTextSharp.text.Font.UNDERLINE, iTextSharp.text.BaseColor.RED);
                iTextSharp.text.Font font = new iTextSharp.text.Font(bf, 12, iTextSharp.text.Font.BOLD, new iTextSharp.text.BaseColor(0, 0, 0));//黑  
                string filename = "採購單" + DateTime.Now.ToString("yyyyMMddHHmmss");
                Document document = new Document(PageSize.A4);
                string newPDFName = Server.MapPath(excelPath) + filename;
                PdfWriter writer = PdfWriter.GetInstance(document, new FileStream(newPDFName, FileMode.Create));
                document.Open();
                //運送方式

                _paraMgr = new ParameterMgr(mySqlConnectionString);
                List<Parametersrc> parameterStore = new List<Parametersrc>();


                parameterStore = _paraMgr.GetElementType("product_freight");
                if (ipoStore.Count == 0)
                {

                }
                for (int a = 0; a < ipoStore.Count; a++)//循環單頭
                {
                    _ipodMgr = new IpodMgr(mySqlConnectionString);
                    ipod = new IpodQuery();
                    ipod.po_id = ipoStore[a].po_id;
                    ipodStore = new List<IpodQuery>();
                    ipodStore = _ipodMgr.GetIpodListExprot(ipod);
                    Dictionary<int, List<IpodQuery>> product_freight_set_mapping = new Dictionary<int, List<IpodQuery>>();
                    #region 通過運送方式把採購單分開--一張採購單,分成常溫,冷凍等採購單


                    for (int i = 0; i < ipodStore.Count; i++)//通過運送方式保存到字典里
                    {
                        ipodStore[i].spec = GetProductSpec(ipodStore[i].prod_id.ToString());//--------取值出錯了item_id-----------
                        IupcQuery upc = new IupcQuery();
                        _IiupcMgr = new IupcMgr(mySqlConnectionString);

                        upc.item_id = uint.Parse(ipodStore[i].prod_id);//--------取值出錯了item_id-----------
                        //獲取國際條碼
                        List<IupcQuery> upcInternationalStore = new List<IupcQuery>();
                        upc.upc_type_flg = "1";
                        upcInternationalStore = _IiupcMgr.GetIupcByType(upc);
                        //獲取店內條碼
                        List<IupcQuery> upcShopStore = new List<IupcQuery>();
                        upc.upc_type_flg = "3";
                        upcShopStore = _IiupcMgr.GetIupcByType(upc);
                        if (upcInternationalStore.Count > 0)
                        {
                            ipodStore[i].upc_id_international = upcInternationalStore[0].upc_id;
                        }
                        if (upcShopStore.Count > 0)
                        {
                            ipodStore[i].upc_id_shop = upcShopStore[0].upc_id;
                        }
                        int freiset = ipodStore[i].product_freight_set;
                        if (!product_freight_set_mapping.Keys.Contains(freiset))
                        {
                            List<IpodQuery> s = new List<IpodQuery>();
                            product_freight_set_mapping.Add(freiset, s);
                        }
                        product_freight_set_mapping[freiset].Add(ipodStore[i]);
                    }
                    #endregion

                    #region 針對匯出一個而無商品的pdf
                    if (ipodStore.Count == 0)
                    {

                        #region 獲取供應商信息

                        Vendor vendor = new Vendor();
                        _vendorMgr = new VendorMgr(mySqlConnectionString);

                        vendor.erp_id = ipoStore[a].vend_id;
                        vendor = _vendorMgr.GetSingle(vendor);
                        #endregion
                        #region 採購單標題

                        PdfPTable ptable = new PdfPTable(7);


                        ptable.WidthPercentage = 100;//表格寬度
                        font = new iTextSharp.text.Font(bf, 10, iTextSharp.text.Font.NORMAL, new iTextSharp.text.BaseColor(0, 0, 0));//黑  
                        ptable.SetTotalWidth(arrColWidth);
                        PdfPCell cell = new PdfPCell();

                        cell = new PdfPCell(new Phrase("", new iTextSharp.text.Font(bf, 15)));
                        cell.VerticalAlignment = Element.ALIGN_LEFT;//字體水平居左
                        cell.Colspan = 2;
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        cell.DisableBorderSide(4);
                        cell.DisableBorderSide(8);
                        ptable.AddCell(cell);
                        cell = new PdfPCell(new Phrase("    吉甲地好市集股份有限公司", new iTextSharp.text.Font(bf, 15)));
                        cell.VerticalAlignment = Element.ALIGN_CENTER;//字體水平居左
                        cell.Colspan = 5;
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        cell.DisableBorderSide(4);
                        cell.DisableBorderSide(8);
                        ptable.AddCell(cell);
                        cell = new PdfPCell(new Phrase("", new iTextSharp.text.Font(bf, 12)));
                        cell.VerticalAlignment = Element.ALIGN_LEFT;//字體水平居左
                        cell.Colspan = 3;
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        cell.DisableBorderSide(4);
                        cell.DisableBorderSide(8);
                        ptable.AddCell(cell);
                        cell = new PdfPCell(new Phrase("採購單" + "-" + ipoStore[a].po_type_desc, new iTextSharp.text.Font(bf, 12)));
                        cell.VerticalAlignment = Element.ALIGN_LEFT;//字體水平居左
                        cell.Colspan = 4;
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        cell.DisableBorderSide(4);
                        cell.DisableBorderSide(8);
                        ptable.AddCell(cell);
                        cell = new PdfPCell(new Phrase("公司電話:", new iTextSharp.text.Font(bf, 8)));
                        cell.VerticalAlignment = Element.ALIGN_LEFT;//字體水平居左
                        cell.Colspan = 6;
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        cell.DisableBorderSide(4);
                        cell.DisableBorderSide(8);
                        ptable.AddCell(cell);
                        cell = new PdfPCell(new Phrase("公司傳真:", new iTextSharp.text.Font(bf, 8)));
                        cell.VerticalAlignment = Element.ALIGN_RIGHT;//字體水平居右
                        cell.Colspan = 1;
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        cell.DisableBorderSide(4);
                        cell.DisableBorderSide(8);
                        ptable.AddCell(cell);
                        cell = new PdfPCell(new Phrase("製造日期:" + DateTime.Now.ToString("yyyy/MM/dd"), new iTextSharp.text.Font(bf, 8)));
                        cell.VerticalAlignment = Element.ALIGN_LEFT;//字體水平居左
                        cell.Colspan = 3;
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        cell.DisableBorderSide(4);
                        cell.DisableBorderSide(8);
                        ptable.AddCell(cell);

                        cell = new PdfPCell(new Phrase("", new iTextSharp.text.Font(bf, 8)));
                        cell.VerticalAlignment = Element.ALIGN_RIGHT;//字體水平居右
                        cell.Colspan = 4;
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        cell.DisableBorderSide(4);
                        cell.DisableBorderSide(8);
                        ptable.AddCell(cell);

                        cell = new PdfPCell(new Phrase("", new iTextSharp.text.Font(bf, 8)));
                        cell.VerticalAlignment = Element.ALIGN_RIGHT;//字體水平居右
                        cell.Colspan = 7;
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        cell.DisableBorderSide(4);
                        cell.DisableBorderSide(8);
                        ptable.AddCell(cell);

                        cell.UseAscender = true;
                        cell.HorizontalAlignment = Element.ALIGN_CENTER;//字體垂直居中
                        cell.VerticalAlignment = Element.ALIGN_MIDDLE;//字體水平居中
                        cell.BorderWidth = 0.1f;
                        cell.BorderColor = new BaseColor(0, 0, 0);

                        #endregion
                        #region 上部分


                        cell = new PdfPCell(new Phrase("採購單別:" + ipoStore[a].po_type, font));
                        cell.Colspan = 2;
                        cell.DisableBorderSide(2);
                        cell.DisableBorderSide(8);
                        ptable.AddCell(cell);
                        cell = new PdfPCell(new Phrase("交易幣別:" + "世界貨幣", font));
                        cell.Colspan = 1;
                        cell.DisableBorderSide(2);
                        cell.DisableBorderSide(4);
                        cell.DisableBorderSide(8);
                        ptable.AddCell(cell);
                        cell = new PdfPCell(new Phrase("匯率:" + "浮動", font));
                        cell.Colspan = 2;
                        cell.DisableBorderSide(2);
                        cell.DisableBorderSide(4);
                        cell.DisableBorderSide(8);
                        ptable.AddCell(cell);
                        cell = new PdfPCell(new Phrase("運輸方式:", font));
                        cell.Colspan = 2;
                        cell.DisableBorderSide(2);
                        cell.DisableBorderSide(4);
                        ptable.AddCell(cell);


                        cell = new PdfPCell(new Phrase("商品是新品么?:", font));//新品
                        cell.Colspan = 2;
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        cell.DisableBorderSide(8);
                        ptable.AddCell(cell);
                        cell = new PdfPCell(new Phrase("所在層:", font));
                        cell.Colspan = 1;
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        cell.DisableBorderSide(4);
                        cell.DisableBorderSide(8);
                        ptable.AddCell(cell);
                        cell = new PdfPCell(new Phrase("採購單(" + ipoStore[a].po_type_desc + ")", font));
                        cell.Colspan = 2;
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        cell.DisableBorderSide(4);
                        cell.DisableBorderSide(8);
                        ptable.AddCell(cell);
                        cell = new PdfPCell(new Phrase("預約到貨日期:", font));
                        cell.Colspan = 2;
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        cell.DisableBorderSide(4);
                        ptable.AddCell(cell);



                        cell = new PdfPCell(new Phrase("採購單號:" + ipoStore[a].po_id, font));
                        cell.Colspan = 2;
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        cell.DisableBorderSide(8);
                        ptable.AddCell(cell);
                        cell = new PdfPCell(new Phrase("課稅別:", font));
                        cell.Colspan = 1;
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        cell.DisableBorderSide(4);
                        cell.DisableBorderSide(8);
                        ptable.AddCell(cell);
                        cell = new PdfPCell(new Phrase("營業稅率:", font));
                        cell.Colspan = 2;
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        cell.DisableBorderSide(4);
                        cell.DisableBorderSide(8);
                        ptable.AddCell(cell);
                        cell = new PdfPCell(new Phrase("價格條件:", font));
                        cell.Colspan = 2;
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        cell.DisableBorderSide(4);
                        ptable.AddCell(cell);



                        cell = new PdfPCell(new Phrase("單據日期:" + DateTime.Now.ToString("yyyy/MM/dd"), font));
                        cell.Colspan = 2;
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        cell.DisableBorderSide(8);
                        ptable.AddCell(cell);
                        cell = new PdfPCell(new Phrase("採購人員:" + ipoStore[a].buyer, font));
                        cell.Colspan = 1;
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        cell.DisableBorderSide(4);
                        cell.DisableBorderSide(8);
                        ptable.AddCell(cell);
                        cell = new PdfPCell(new Phrase((System.Web.HttpContext.Current.Session["caller"] as Caller).user_username, font));
                        cell.Colspan = 2;
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        cell.DisableBorderSide(4);
                        cell.DisableBorderSide(8);
                        ptable.AddCell(cell);
                        cell = new PdfPCell(new Phrase("廠別代號:", font));
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        cell.DisableBorderSide(4);
                        cell.DisableBorderSide(8);
                        ptable.AddCell(cell);
                        cell = new PdfPCell(new Phrase("gigade(讀取)", font));
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        cell.DisableBorderSide(4);
                        ptable.AddCell(cell);



                        cell = new PdfPCell(new Phrase("廠商代號:" + ipoStore[a].vend_id, font));
                        cell.Colspan = 2;
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        cell.DisableBorderSide(8);
                        ptable.AddCell(cell);
                        cell = new PdfPCell(new Phrase("", font));
                        cell.Colspan = 1;
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        cell.DisableBorderSide(4);
                        cell.DisableBorderSide(8);
                        ptable.AddCell(cell);
                        cell = new PdfPCell(new Phrase("付款條件(讀取)", font));
                        cell.Colspan = 2;
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        cell.DisableBorderSide(4);
                        cell.DisableBorderSide(8);
                        ptable.AddCell(cell);
                        cell = new PdfPCell(new Phrase("月結N天(讀取):", font));
                        cell.Colspan = 2;
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        cell.DisableBorderSide(4);
                        ptable.AddCell(cell);

                        cell = new PdfPCell(new Phrase("廠商全名(讀取):", font));
                        cell.Colspan = 5;
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        cell.DisableBorderSide(8);
                        ptable.AddCell(cell);
                        cell = new PdfPCell(new Phrase("備註:", font));
                        cell.Colspan = 2;
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        cell.DisableBorderSide(4);


                        ptable.AddCell(cell);
                        cell = new PdfPCell(new Phrase("廠商地址:", font));
                        cell.Colspan = 7;
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);


                        ptable.AddCell(cell);
                        cell = new PdfPCell(new Phrase(" ", font));
                        cell.Colspan = 7;
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        ptable.AddCell(cell);


                        cell = new PdfPCell(new Phrase("聯絡人(讀取):", font));
                        cell.Colspan = 2;

                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        cell.DisableBorderSide(8);
                        ptable.AddCell(cell);
                        cell = new PdfPCell(new Phrase("廠商電話:", font));
                        cell.Colspan = 1;
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        cell.DisableBorderSide(4);
                        cell.DisableBorderSide(8);
                        ptable.AddCell(cell);
                        cell = new PdfPCell(new Phrase("廠商傳真:", font));
                        cell.Colspan = 4;
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        cell.DisableBorderSide(4);
                        ptable.AddCell(cell);

                        cell = new PdfPCell(new Phrase("送貨地址(讀取):", font));
                        cell.Colspan = 7;
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        ptable.AddCell(cell);

                        cell = new PdfPCell(new Phrase(" ", font));
                        cell.Colspan = 7;
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        ptable.AddCell(cell);

                        cell = new PdfPCell(new Phrase("預計送貨日期(讀取):", font));
                        cell.Colspan = 7;
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        ptable.AddCell(cell);

                        cell = new PdfPCell(new Phrase("配送聯絡人(讀取):", font));
                        cell.Colspan = 2;
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        cell.DisableBorderSide(8);
                        ptable.AddCell(cell);
                        cell = new PdfPCell(new Phrase("配送電話(讀取):", font));
                        cell.Colspan = 1;
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        cell.DisableBorderSide(4);
                        cell.DisableBorderSide(8);
                        ptable.AddCell(cell);

                        cell = new PdfPCell(new Phrase("配送傳真(讀取):", font));
                        cell.Colspan = 4;
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        cell.DisableBorderSide(4);
                        ptable.AddCell(cell);

                        cell = new PdfPCell(new Phrase("處理備註:", font));
                        cell.Colspan = 7;
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        ptable.AddCell(cell);
                        cell = new PdfPCell(new Phrase("運送備註:", font));
                        cell.Colspan = 7;
                        cell.DisableBorderSide(1);

                        ptable.AddCell(cell);
                        #endregion

                        cell = new PdfPCell(new Phrase("此採購單商品不存在!", font));
                        cell.Colspan = 7;

                        ptable.AddCell(cell);

                        newFileName = newPDFName + "_part" + index++ + "." + "pdf";
                        pdf.ExportDataTableToPDF(newFileName, ptable, "", "");
                        pdfList.Add(newFileName);

                        document.Add(ptable);
                        document.NewPage();


                    }
                    #endregion

                    foreach (int key in product_freight_set_mapping.Keys)
                    {
                        #region 取出運送方式
                        string procduct_freight = "";
                        for (int i = 0; i < parameterStore.Count; i++)
                        {
                            if (key.ToString() == parameterStore[i].ParameterCode)
                            {
                                procduct_freight = parameterStore[i].parameterName;
                            }
                        }
                        #endregion

                        #region 獲取供應商信息

                        Vendor vendor = new Vendor();
                        _vendorMgr = new VendorMgr(mySqlConnectionString);

                        vendor.erp_id = ipoStore[a].vend_id;
                        vendor = _vendorMgr.GetSingle(vendor);
                        #endregion

                        #region 採購單標題


                        PdfPTable ptable = new PdfPTable(7);


                        ptable.WidthPercentage = 100;//表格寬度
                        font = new iTextSharp.text.Font(bf, 10, iTextSharp.text.Font.NORMAL, new iTextSharp.text.BaseColor(0, 0, 0));//黑  
                        ptable.SetTotalWidth(arrColWidth);
                        PdfPCell cell = new PdfPCell();

                        cell = new PdfPCell(new Phrase("", new iTextSharp.text.Font(bf, 15)));
                        cell.VerticalAlignment = Element.ALIGN_LEFT;//字體水平居左
                        cell.Colspan = 2;
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        cell.DisableBorderSide(4);
                        cell.DisableBorderSide(8);
                        ptable.AddCell(cell);
                        cell = new PdfPCell(new Phrase("      吉甲地好市集股份有限公司", new iTextSharp.text.Font(bf, 15)));
                        cell.VerticalAlignment = Element.ALIGN_CENTER;//字體水平居左
                        cell.Colspan = 5;
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        cell.DisableBorderSide(4);
                        cell.DisableBorderSide(8);
                        ptable.AddCell(cell);
                        cell = new PdfPCell(new Phrase("", new iTextSharp.text.Font(bf, 12)));
                        cell.VerticalAlignment = Element.ALIGN_LEFT;//字體水平居左
                        cell.Colspan = 3;
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        cell.DisableBorderSide(4);
                        cell.DisableBorderSide(8);
                        ptable.AddCell(cell);
                        cell = new PdfPCell(new Phrase("    採購單" + "-" + ipoStore[a].po_type_desc, new iTextSharp.text.Font(bf, 12)));
                        cell.VerticalAlignment = Element.ALIGN_LEFT;//字體水平居左
                        cell.Colspan = 4;
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        cell.DisableBorderSide(4);
                        cell.DisableBorderSide(8);
                        ptable.AddCell(cell);
                        cell = new PdfPCell(new Phrase("公司電話:", new iTextSharp.text.Font(bf, 8)));
                        cell.VerticalAlignment = Element.ALIGN_LEFT;//字體水平居左
                        cell.Colspan = 6;
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        cell.DisableBorderSide(4);
                        cell.DisableBorderSide(8);
                        ptable.AddCell(cell);
                        cell = new PdfPCell(new Phrase("公司傳真:", new iTextSharp.text.Font(bf, 8)));
                        cell.VerticalAlignment = Element.ALIGN_RIGHT;//字體水平居右
                        cell.Colspan = 1;
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        cell.DisableBorderSide(4);
                        cell.DisableBorderSide(8);
                        ptable.AddCell(cell);
                        cell = new PdfPCell(new Phrase("製造日期:" + DateTime.Now.ToString("yyyy/MM/dd"), new iTextSharp.text.Font(bf, 8)));
                        cell.VerticalAlignment = Element.ALIGN_LEFT;//字體水平居左
                        cell.Colspan = 3;
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        cell.DisableBorderSide(4);
                        cell.DisableBorderSide(8);
                        ptable.AddCell(cell);

                        cell = new PdfPCell(new Phrase("", new iTextSharp.text.Font(bf, 8)));
                        cell.VerticalAlignment = Element.ALIGN_RIGHT;//字體水平居右
                        cell.Colspan = 4;
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        cell.DisableBorderSide(4);
                        cell.DisableBorderSide(8);
                        ptable.AddCell(cell);

                        cell = new PdfPCell(new Phrase("", new iTextSharp.text.Font(bf, 8)));
                        cell.VerticalAlignment = Element.ALIGN_RIGHT;//字體水平居右
                        cell.Colspan = 7;
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        cell.DisableBorderSide(4);
                        cell.DisableBorderSide(8);
                        ptable.AddCell(cell);

                        cell.UseAscender = true;
                        cell.HorizontalAlignment = Element.ALIGN_CENTER;//字體垂直居中
                        cell.VerticalAlignment = Element.ALIGN_MIDDLE;//字體水平居中
                        cell.BorderWidth = 0.1f;
                        cell.BorderColor = new BaseColor(0, 0, 0);
                        #endregion

                        #region 上部分


                        cell = new PdfPCell(new Phrase("採購單別:" + ipoStore[a].po_type, font));
                        cell.Colspan = 2;
                        cell.DisableBorderSide(2);
                        cell.DisableBorderSide(8);
                        ptable.AddCell(cell);
                        cell = new PdfPCell(new Phrase("交易幣別:" + "世界貨幣", font));
                        cell.Colspan = 1;
                        cell.DisableBorderSide(2);
                        cell.DisableBorderSide(4);
                        cell.DisableBorderSide(8);
                        ptable.AddCell(cell);
                        cell = new PdfPCell(new Phrase("匯率:" + "浮動", font));
                        cell.Colspan = 2;
                        cell.DisableBorderSide(2);
                        cell.DisableBorderSide(4);
                        cell.DisableBorderSide(8);
                        ptable.AddCell(cell);
                        if (procduct_freight != "常溫" && procduct_freight != "冷凍")
                        {
                            ;
                        }
                        cell = new PdfPCell(new Phrase("運輸方式:" + procduct_freight, font));
                        cell.Colspan = 2;
                        cell.DisableBorderSide(2);
                        cell.DisableBorderSide(4);
                        ptable.AddCell(cell);


                        cell = new PdfPCell(new Phrase("商品是新品么?:", font));//新品
                        cell.Colspan = 2;
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        cell.DisableBorderSide(8);
                        ptable.AddCell(cell);
                        cell = new PdfPCell(new Phrase("所在層:", font));
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        cell.DisableBorderSide(4);
                        cell.DisableBorderSide(8);
                        ptable.AddCell(cell);
                        cell = new PdfPCell(new Phrase("採購單(" + ipoStore[a].po_type_desc + ")", font));
                        cell.Colspan = 2;
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        cell.DisableBorderSide(4);
                        cell.DisableBorderSide(8);
                        ptable.AddCell(cell);
                        cell = new PdfPCell(new Phrase("預約到貨日期:", font));
                        cell.Colspan = 2;
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        cell.DisableBorderSide(4);
                        ptable.AddCell(cell);



                        cell = new PdfPCell(new Phrase("採購單號:" + ipoStore[a].po_id, font));
                        cell.Colspan = 2;
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        cell.DisableBorderSide(8);
                        ptable.AddCell(cell);
                        cell = new PdfPCell(new Phrase("課稅別:", font));
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        cell.DisableBorderSide(4);
                        cell.DisableBorderSide(8);
                        ptable.AddCell(cell);
                        cell = new PdfPCell(new Phrase("營業稅率:", font));
                        cell.Colspan = 2;
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        cell.DisableBorderSide(4);
                        cell.DisableBorderSide(8);
                        ptable.AddCell(cell);
                        cell = new PdfPCell(new Phrase("價格條件:", font));
                        cell.Colspan = 2;
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        cell.DisableBorderSide(4);
                        ptable.AddCell(cell);



                        cell = new PdfPCell(new Phrase("單據日期:" + DateTime.Now.ToString("yyyy/MM/dd"), font));
                        cell.Colspan = 2;
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        cell.DisableBorderSide(8);
                        ptable.AddCell(cell);
                        cell = new PdfPCell(new Phrase("採購人員:", font));
                        //cell = new PdfPCell(new Phrase("採購人員:" + ipoStore[a].buyer, font));
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        cell.DisableBorderSide(4);
                        cell.DisableBorderSide(8);
                        ptable.AddCell(cell);
                        cell = new PdfPCell(new Phrase((System.Web.HttpContext.Current.Session["caller"] as Caller).user_username, font));
                        cell.Colspan = 2;
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        cell.DisableBorderSide(4);
                        cell.DisableBorderSide(8);
                        ptable.AddCell(cell);
                        cell = new PdfPCell(new Phrase("廠別代號:", font));
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        cell.DisableBorderSide(4);
                        cell.DisableBorderSide(8);
                        ptable.AddCell(cell);
                        cell = new PdfPCell(new Phrase("gigade(讀取)", font));
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        cell.DisableBorderSide(4);
                        ptable.AddCell(cell);



                        cell = new PdfPCell(new Phrase("廠商代號:" + ipoStore[a].vend_id, font));
                        cell.Colspan = 2;
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        cell.DisableBorderSide(8);
                        ptable.AddCell(cell);
                        cell = new PdfPCell(new Phrase(vendor == null ? "暫無此信息" : vendor.vendor_name_simple, font));
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        cell.DisableBorderSide(4);
                        cell.DisableBorderSide(8);
                        ptable.AddCell(cell);
                        cell = new PdfPCell(new Phrase("付款條件(讀取)", font));
                        cell.Colspan = 2;
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        cell.DisableBorderSide(4);
                        cell.DisableBorderSide(8);
                        ptable.AddCell(cell);
                        cell = new PdfPCell(new Phrase("月結N天(讀取):", font));
                        cell.Colspan = 2;
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        cell.DisableBorderSide(4);
                        ptable.AddCell(cell);

                        cell = new PdfPCell(new Phrase(vendor == null ? "廠商全名(讀取):暫無此信息" : "廠商全名:" + vendor.vendor_name_full, font));
                        cell.Colspan = 5;
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        cell.DisableBorderSide(8);
                        ptable.AddCell(cell);
                        cell = new PdfPCell(new Phrase("備註:", font));
                        cell.Colspan = 2;
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        cell.DisableBorderSide(4);


                        ptable.AddCell(cell);
                        cell = new PdfPCell(new Phrase(vendor == null ? "廠商地址:暫無此信息" : "廠商地址:" + vendor.company_address, font));
                        cell.Colspan = 7;
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);


                        ptable.AddCell(cell);
                        cell = new PdfPCell(new Phrase(" ", font));
                        cell.Colspan = 7;
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        ptable.AddCell(cell);


                        cell = new PdfPCell(new Phrase("聯絡人(讀取):", font));
                        cell.Colspan = 2;

                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        cell.DisableBorderSide(8);
                        ptable.AddCell(cell);
                        cell = new PdfPCell(new Phrase(vendor == null ? "廠商電話:暫無此信息" : "廠商電話:" + vendor.company_phone, font));
                        cell.Colspan = 1;
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        cell.DisableBorderSide(4);
                        cell.DisableBorderSide(8);
                        ptable.AddCell(cell);
                        cell = new PdfPCell(new Phrase(vendor == null ? "廠商傳真:暫無此信息" : "廠商傳真:" + vendor.company_fax, font));


                        cell.Colspan = 4;
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        cell.DisableBorderSide(4);
                        ptable.AddCell(cell);

                        cell = new PdfPCell(new Phrase("送貨地址(讀取):", font));
                        cell.Colspan = 7;
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        ptable.AddCell(cell);

                        cell = new PdfPCell(new Phrase(" ", font));
                        cell.Colspan = 7;
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        ptable.AddCell(cell);

                        cell = new PdfPCell(new Phrase("預計送貨日期(讀取):", font));
                        cell.Colspan = 7;
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        ptable.AddCell(cell);
                        cell = new PdfPCell(new Phrase("配送聯絡人(讀取):", font));
                        cell.Colspan = 2;
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        cell.DisableBorderSide(8);
                        ptable.AddCell(cell);
                        cell = new PdfPCell(new Phrase("配送電話(讀取):", font));
                        cell.Colspan = 1;
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        cell.DisableBorderSide(4);
                        cell.DisableBorderSide(8);
                        ptable.AddCell(cell);
                        cell = new PdfPCell(new Phrase("配送傳真(讀取):", font));


                        cell.Colspan = 4;
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        cell.DisableBorderSide(4);
                        ptable.AddCell(cell);
                        cell = new PdfPCell(new Phrase("處理備註:", font));


                        cell.Colspan = 7;
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        ptable.AddCell(cell);
                        cell = new PdfPCell(new Phrase("運送備註:", font));
                        cell.Colspan = 7;
                        cell.DisableBorderSide(1);

                        ptable.AddCell(cell);
                        #endregion
                        #region 下面表格頭部
                        cell = new PdfPCell(new Phrase("序號", font));
                        cell.VerticalAlignment = Element.ALIGN_MIDDLE;
                        //cell.DisableBorderSide(2);
                        cell.Rowspan = 3;
                        ptable.AddCell(cell);
                        cell = new PdfPCell(new Phrase("國際條碼", font));
                        cell.DisableBorderSide(2);
                        ptable.AddCell(cell);
                        cell = new PdfPCell(new Phrase("品號", font));
                        cell.DisableBorderSide(2);
                        ptable.AddCell(cell);
                        cell = new PdfPCell(new Phrase("採購數量", font));
                        cell.DisableBorderSide(2);
                        ptable.AddCell(cell);
                        cell = new PdfPCell(new Phrase("允收天數", font));
                        cell.DisableBorderSide(2);
                        ptable.AddCell(cell);
                        cell = new PdfPCell(new Phrase("製造日期", font));
                        cell.DisableBorderSide(2);
                        ptable.AddCell(cell);
                        cell = new PdfPCell(new Phrase("備註", font));
                        cell.DisableBorderSide(2);
                        ptable.AddCell(cell);



                        cell = new PdfPCell(new Phrase("供應商店內碼", font));
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        ptable.AddCell(cell);
                        cell = new PdfPCell(new Phrase("品名", font));
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        ptable.AddCell(cell);
                        cell = new PdfPCell(new Phrase("允收數量", font));
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        ptable.AddCell(cell);
                        cell = new PdfPCell(new Phrase("允出天數", font));
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        ptable.AddCell(cell);
                        cell = new PdfPCell(new Phrase("有效日期", font));
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        ptable.AddCell(cell);
                        cell = new PdfPCell(new Phrase("", font));
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        ptable.AddCell(cell);
                        cell = new PdfPCell(new Phrase("料位", font));
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        ptable.AddCell(cell);
                        cell = new PdfPCell(new Phrase("規格", font));
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        ptable.AddCell(cell);

                        cell = new PdfPCell(new Phrase("不允收數量", font));
                        cell.DisableBorderSide(1);
                        ptable.AddCell(cell);
                        cell = new PdfPCell(new Phrase("有效期天數", font));
                        cell.DisableBorderSide(1);
                        ptable.AddCell(cell);
                        cell = new PdfPCell(new Phrase("", font));
                        cell.DisableBorderSide(1);
                        ptable.AddCell(cell);
                        cell = new PdfPCell(new Phrase("", font));
                        cell.DisableBorderSide(1);
                        ptable.AddCell(cell);

                        #endregion

                        _ipodMgr = new IpodMgr(mySqlConnectionString);
                        ipod = new IpodQuery();
                        ipod.po_id = ipoStore[a].po_id;
                        ipod.IsPage = false;
                        ipodStore = new List<IpodQuery>();
                        ipodStore = _ipodMgr.GetIpodList(ipod, out totalCount);

                        List<IpodQuery> Ipodleibie = new List<IpodQuery>();
                        Ipodleibie.AddRange(product_freight_set_mapping[key]);

                        #region 循環讀取數據填入表格
                        DataTable Ipod_dt = new DataTable();
                        Ipod_dt.Columns.Add("序號", typeof(string));
                        Ipod_dt.Columns.Add("國際條碼", typeof(string));
                        Ipod_dt.Columns.Add("品號", typeof(string));
                        Ipod_dt.Columns.Add("採購數量", typeof(string));
                        Ipod_dt.Columns.Add("允收天數", typeof(string));
                        Ipod_dt.Columns.Add("製造日期", typeof(string));
                        Ipod_dt.Columns.Add("備註", typeof(string));
                        Ipod_dt.Columns.Add("Empty_1", typeof(string));
                        Ipod_dt.Columns.Add("供應商店內碼", typeof(string));
                        Ipod_dt.Columns.Add("品名", typeof(string));
                        Ipod_dt.Columns.Add("允收數量", typeof(string));
                        Ipod_dt.Columns.Add("允出天數", typeof(string));
                        Ipod_dt.Columns.Add("有效日期", typeof(string));
                        Ipod_dt.Columns.Add("Empty_3", typeof(string));
                        Ipod_dt.Columns.Add("Empty_4", typeof(string));
                        Ipod_dt.Columns.Add("料位", typeof(string));
                        Ipod_dt.Columns.Add("規格", typeof(string));
                        Ipod_dt.Columns.Add("不允收數量", typeof(string));
                        Ipod_dt.Columns.Add("有效期天數", typeof(string));
                        Ipod_dt.Columns.Add("Empty_5", typeof(string));
                        Ipod_dt.Columns.Add("Empty_6", typeof(string));

                        for (int i = 0; i < Ipodleibie.Count; i++)
                        {
                            DataRow newRow = Ipod_dt.NewRow();
                            newRow["國際條碼"] = Ipodleibie[i].upc_id_international;
                            newRow["品號"] = Ipodleibie[i].Erp_Id.ToString();
                            newRow["採購數量"] = Ipodleibie[i].qty_ord.ToString();
                            newRow["允收天數"] = Ipodleibie[i].cde_dt_var.ToString();
                            newRow["製造日期"] = "";
                            newRow["備註"] = "";
                            newRow["Empty_1"] = (i + 1).ToString(); //序號
                            newRow["供應商店內碼"] = Ipodleibie[i].upc_id_shop;
                            newRow["品名"] = Ipodleibie[i].product_name;
                            newRow["允收數量"] = Ipodleibie[i].qty_claimed.ToString();
                            newRow["允出天數"] = Ipodleibie[i].cde_dt_shp.ToString();
                            newRow["有效日期"] = "";
                            newRow["Empty_3"] = "";
                            newRow["Empty_4"] = "";
                            newRow["料位"] = Ipodleibie[i].loc_id;
                            newRow["規格"] = Ipodleibie[i].spec;
                            newRow["不允收數量"] = Ipodleibie[i].qty_damaged.ToString();
                            newRow["有效期天數"] = Ipodleibie[i].cde_dt_incr.ToString();
                            newRow["Empty_5"] = "";
                            newRow["Empty_6"] = "";
                            Ipod_dt.Rows.Add(newRow);
                        }

                        #endregion
                        ////////
                        newFileName = newPDFName + "_part" + index++ + "." + "pdf";

                        pdf.ExportDataTableToPDF(Ipod_dt, false, newFileName, arrColWidth, ptable, "", "", 7, 7);/*第一7是列,第二個是行*/
                        pdfList.Add(newFileName);

                    }






                }
                newFileName = newPDFName + "." + "pdf";
                pdf.MergePDF(pdfList, newFileName);

                Response.Clear();
                Response.Charset = "gb2312";
                Response.ContentEncoding = System.Text.Encoding.UTF8;
                Response.AddHeader("Content-Disposition", "attach-ment;filename=" + filename + ".pdf");
                Response.WriteFile(newFileName);
                //}
                #endregion
            }
            catch (Exception ex)
            {
                //cb.EndText();
                //writer.Resume();
                //Response.Clear();

            }
        }
Пример #8
0
        public void PrepareData(List<CombinationExcel> source)
        {
            if (source != null)
            {
                source.ForEach(m => m.Validate());
                var parents = source.Where(m => m.combination.Trim() != "299" && string.IsNullOrEmpty(m.msg));

                _productMgr = new ProductMgr(strConn);
                _productItemMgr = new ProductItemMgr(strConn);
                _vendorMgr = new VendorMgr(strConn);
                _vendorBrandMgr = new VendorBrandMgr(strConn);
                _siteMgr = new SiteMgr(strConn);
                _productMigrationMgr = new ProductMigrationMgr(strConn);
                _productComboMgr = new ProductComboMgr(strConn);
                _cateMgr = new ProductCategoryMgr(strConn);
                _productCategorySetMgr = new ProductCategorySetMgr(strConn);
                _productNoticeSetMgr = new ProductNoticeSetMgr(strConn);
                _productTagSetMgr = new ProductTagSetMgr(strConn);
                _productPictureMgr = new ProductPictureMgr(strConn);
                _productStatusHistoryMgr = new ProductStatusHistoryMgr(strConn);

                foreach (var parent in parents)
                {
                    form.change(1);
                    uint product_id = uint.Parse(parent.product_id);
                    #region Product

                    ProductMigrationMap prodMigra = _productMigrationMgr.GetSingle(new ProductMigrationMap { temp_id = parent.is_exist.ToUpper().Trim().Equals("OLD") ? parent.product_id : parent.temp_id });
                    if (prodMigra != null)
                    {
                        parent.msg = "此記錄暫時編號(temp_id)已經存在;";
                        continue;
                    }

                    Product newPro = parent.is_exist.ToUpper().Trim() == "OLD" ? _productMgr.Query(new Product { Product_Id = product_id }).FirstOrDefault() : new Product();
                    if (newPro == null)
                    {
                        parent.msg = "商品不存在";
                        continue;
                    }
                    newPro.Product_Name = parent.product_name.Trim();
                    VendorBrand brand = _vendorBrandMgr.GetProductBrand(new VendorBrand { Brand_Name = parent.brand_name.Trim() });
                    if (brand == null)
                    {
                        parent.msg = "品牌不存在";
                        continue;
                    }
                    newPro.Brand_Id = brand.Brand_Id;
                    switch (parent.combination.Trim())
                    {
                        case "2":
                            newPro.Combination = 2; break;
                        case "3":
                            newPro.Combination = 3; break;
                        case "4":
                            newPro.Combination = 4; break;
                        default: break;
                    }
                    switch (parent.status.Trim().ToUpper())
                    {
                        case "SAME":
                            break;
                        case "ON":
                            newPro.Product_Status = 5; break;
                        case "OFF":
                            newPro.Product_Status = 6; break;
                        case "NEW":
                            newPro.Product_Status = 0; break;
                        default:
                            break;
                    }
                    newPro.Price_type = 1;
                    newPro.Product_Spec = 0;
                    newPro.Spec_Title_1 = string.Empty;
                    newPro.Spec_Title_2 = string.Empty;
                    newPro.Ignore_Stock = 0;// parent.ignore_stock.ToUpper().Trim() == "Y" ? 1 : 0;
                    newPro.Shortage = 0;// parent.shortage.ToUpper().Trim() == "Y" ? 1 : 0;
                    newPro.Cate_Id = parent.cate_id.Trim();
                    var vendor = _vendorMgr.GetSingle(new Vendor { vendor_id = brand.Vendor_Id });
                    if (vendor == null)
                    {
                        parent.msg = "供應商不存在";
                        continue;
                    }
                    newPro.user_id = vendor.product_manage;
                    if (!string.IsNullOrEmpty(parent.service_fee))
                    { 
                        uint bag_check_money=0;
                        uint.TryParse(parent.service_fee,out bag_check_money);
                        newPro.Bag_Check_Money = bag_check_money;
                    }
                    #endregion

                    bool result = true;
                    ArrayList sqls = new ArrayList();
                    #region PriceMaster

                    Site site = _siteMgr.Query(new Site { Site_Name = parent.site.Trim() }).FirstOrDefault();
                    if (site == null)
                    {
                        parent.msg = "價格檔站臺不存在";
                        result = false;
                        break;
                    }
                    List<PriceMaster> priceMasters = new List<PriceMaster>();
                    //首先默認加入一筆吉甲地站臺
                    PriceMaster newPriceMaster = new PriceMaster { site_id = 1, user_level = 1, same_price = 1, accumulated_bonus = 1, default_bonus_percent = 1, bonus_percent = 1 };
                    newPriceMaster.product_name = newPro.Product_Name;
                    newPriceMaster.price_status = 1;

                    var item = _productItemMgr.Query(new ProductItem { Product_Id = newPro.Product_Id }).FirstOrDefault();
                    if (item == null)
                    {
                        parent.msg = "商品細項不存在";
                        continue;
                    }
                    #region 成本

                    int cost = 0;
                    if (!string.IsNullOrEmpty(parent.cost))
                    {
                        int.TryParse(parent.cost, out cost);
                    }
                    else
                    {
                        cost = Convert.ToInt32(item.Item_Cost);
                    }
                    newPriceMaster.cost = cost;
                    #endregion

                    #region 售價

                    int price = 0;
                    if (!string.IsNullOrEmpty(parent.price))
                    {
                        int.TryParse(parent.price, out price);
                    }
                    else
                    {
                        price = Convert.ToInt32(item.Item_Money);
                    }
                    newPriceMaster.price = price;
                    #endregion

                    newPriceMaster.event_price = Convert.ToInt32(item.Event_Item_Money);
                    newPriceMaster.event_start = item.Event_Product_Start;
                    newPriceMaster.event_end = item.Event_Product_End;
                    priceMasters.Add(newPriceMaster);

                    if (site.Site_Id != 1)
                    {
                        //如果站臺不是吉甲地就把吉甲地站臺的價格狀態改為4(下架)
                        priceMasters[0].price_status = 4;
                        //再加入非吉甲地站臺
                        newPriceMaster = new PriceMaster { site_id = site.Site_Id, user_level = 1, same_price = 1, accumulated_bonus = 1, default_bonus_percent = 1, bonus_percent = 1 };
                        newPriceMaster.product_name = newPro.Product_Name;
                        newPriceMaster.price_status = 1;
                        #region 成本

                        cost = 0;
                        if (!string.IsNullOrEmpty(parent.cost))
                        {
                            int.TryParse(parent.cost, out cost);
                        }
                        else
                        {
                            cost = Convert.ToInt32(item.Item_Cost);
                        }
                        newPriceMaster.cost = cost;
                        #endregion

                        #region 售價

                        price = 0;
                        if (!string.IsNullOrEmpty(parent.price))
                        {
                            int.TryParse(parent.price, out price);
                        }
                        else
                        {
                            price = Convert.ToInt32(item.Item_Money);
                        }
                        newPriceMaster.price = price;
                        #endregion
                        newPriceMaster.event_price = Convert.ToInt32(item.Event_Item_Money);
                        newPriceMaster.event_start = item.Event_Product_Start;
                        newPriceMaster.event_end = item.Event_Product_End;
                        priceMasters.Add(newPriceMaster);
                    }

                    #region 其他站臺價格

                    var child = source.Where(m =>
                                    m.combination.Trim() == "299"
                                    && m.formula.ToUpper().Trim() == parent.temp_id.ToUpper().Trim()
                                    && string.IsNullOrEmpty(m.msg)
                                    && m.new_old.ToUpper().Trim() == "NEW"
                                    && m.formula.ToUpper().Trim().StartsWith("P"));
                    if (child != null)
                    {
                        foreach (var c in child)
                        {
                            item = _productItemMgr.Query(new ProductItem { Product_Id = uint.Parse(c.product_id) }).FirstOrDefault();
                            if (item == null)
                            {
                                c.msg = "價格檔商品細項不存在";
                                result = false;
                                break;
                            }
                            site = _siteMgr.Query(new Site { Site_Name = c.site.Trim() }).FirstOrDefault();
                            if (site == null)
                            {
                                c.msg = "站臺不存在";
                                result = false;
                                break;
                            }
                            if (priceMasters.Exists(m => m.site_id == site.Site_Id))
                            {
                                c.msg = "站臺重複";
                                result = false;
                                break;
                            }
                            newPriceMaster = new PriceMaster { user_level = 1, same_price = 1, accumulated_bonus = 1, default_bonus_percent = 1, bonus_percent = 1 };
                            newPriceMaster.product_name = c.product_name.Trim();
                            newPriceMaster.site_id = site.Site_Id;
                            newPriceMaster.price_status = 1;
                            #region 成本

                            cost = 0;
                            if (!string.IsNullOrEmpty(c.cost))
                            {
                                int.TryParse(c.cost, out cost);
                            }
                            else
                            {
                                cost = Convert.ToInt32(item.Item_Cost);
                            }
                            newPriceMaster.cost = cost;
                            #endregion

                            #region 售價

                            price = 0;
                            if (!string.IsNullOrEmpty(c.price))
                            {
                                int.TryParse(c.price, out price);
                            }
                            else
                            {
                                price = Convert.ToInt32(item.Item_Money);
                            }
                            newPriceMaster.price = price;
                            #endregion
                            newPriceMaster.event_price = Convert.ToInt32(item.Event_Item_Money);
                            newPriceMaster.event_start = item.Event_Product_Start;
                            newPriceMaster.event_end = item.Event_Product_End;
                            priceMasters.Add(newPriceMaster);

                            if (site.Site_Name.Trim().ToLower() == "chinatrust")
                            {
                                ArrayList category_set = CategorySet(c, brand.Brand_Id);
                                if (category_set == null)
                                {
                                    result = false;
                                    break;
                                }
                                else
                                {
                                    sqls.AddRange(category_set);
                                }
                            }
                        }
                        if (!result) continue;
                    }
                    #endregion

                    #endregion

                    #region ProductCombo

                    string[] strIds = parent.formula.IndexOf(",") != -1 ? parent.formula.Trim().Split(',') : new string[] { parent.formula.Trim() };
                    string[] nums = parent.number.IndexOf(",") != -1 ? parent.number.Trim().Split(',') : new string[] { parent.number.Trim() };

                    List<Product> children = new List<Product>();
                    ProductCombo tmp;
                    for (int i = 0; i < strIds.Length; i++)
                    {
                        tmp = new ProductCombo();
                        if (parent.combination.Trim() != "2")
                        {
                            tmp.Buy_Limit = parent.buylimit.Trim().ToUpper() == "Y" ? 1 : 0;
                        }
                        else
                        {
                            tmp.S_Must_Buy = int.Parse(i >= nums.Length ? nums[nums.Length - 1] : nums[i]);
                        }
                        if (parent.combination.Trim() == "3")//為3任選時 數量為G_Must_Buy
                        {
                            tmp.G_Must_Buy = int.Parse(nums[0]);
                        }
                        switch (parent.new_old.Trim().ToUpper())
                        {
                            case "NEW":
                                var map = _productMigrationMgr.GetSingle(new ProductMigrationMap { temp_id = strIds[i] });
                                if (map == null)
                                {
                                    parent.msg = "原料編號未找到對應";
                                    break;
                                }
                                tmp.Child_Id = Convert.ToInt32(map.product_id);
                                break;
                            case "OLD":
                                tmp.Child_Id = int.Parse(strIds[i]);
                                break;
                            case "BOTH":
                                if (strIds[i].ToUpper().Trim().StartsWith("P"))
                                {
                                    var tMap = _productMigrationMgr.GetSingle(new ProductMigrationMap { temp_id = strIds[i] });
                                    if (tMap == null)
                                    {
                                        parent.msg = "原料編號未找到對應";
                                        break;
                                    }
                                    tmp.Child_Id = Convert.ToInt32(tMap.product_id);
                                }
                                else
                                {
                                    tmp.Child_Id = int.Parse(strIds[i]);
                                }
                                break;
                        }
                        if (tmp.Child_Id == 0)
                        {
                            result = false;
                            break;
                        }
                        else
                        {
                            Product tmpPro = _productMgr.Query(new Product { Product_Id = Convert.ToUInt32(tmp.Child_Id) }).FirstOrDefault();
                            if (tmpPro == null)
                            {
                                parent.msg = strIds[i] + "不存在";
                                result = false;
                                break;
                            }
                            if (tmpPro.Product_Status == 0 || tmpPro.Product_Status ==1)
                            {
                                parent.msg = strIds[i] + "商品状态不為新增、申請審核";
                                result = false;
                                break;
                            }
                            if (tmpPro.Combination != 0 && tmpPro.Combination != 1)
                            {
                                parent.msg = strIds[i] + "不是單一商品";
                                result = false;
                                break;
                            }
                            switch (newPro.Product_Freight_Set)
                            {
                                case 1:
                                case 3:
                                    if (tmpPro.Product_Freight_Set != 1 && tmpPro.Product_Freight_Set != 3) 
                                    {
                                        parent.msg = strIds[i] + "运费模式与主商品不匹配";
                                        result = false;
                                    }
                                    break;
                                case 2:
                                case 4:
                                    if (tmpPro.Product_Freight_Set != 2 && tmpPro.Product_Freight_Set != 4)
                                    {
                                        parent.msg = strIds[i] + "运费模式与主商品不匹配";
                                        result = false;
                                    }
                                    break;
                                case 5:
                                case 6:
                                    if (tmpPro.Product_Freight_Set != 5 && tmpPro.Product_Freight_Set != 6)
                                    {
                                        parent.msg = strIds[i] + "运费模式与主商品不匹配";
                                        result = false;
                                    }
                                    break;
                                default:
                                    break;
                            }
                            if (!result) break;
                            children.Add(tmpPro);
                        }
                        sqls.Add(_productComboMgr.Save(tmp));
                    }
                    if (!result) continue;
                    #endregion

                    #region product_category_set
                    if (!string.IsNullOrEmpty(parent.display))
                    {
                        ArrayList category_set = CategorySet(parent, brand.Brand_Id);
                        if (category_set == null)
                            continue;
                        else
                        {
                            foreach (var set in category_set)
                            {
                                if (!sqls.Contains(set))
                                {
                                    sqls.Add(set);
                                }
                            }
                        }
                    }
                    else
                    {
                        sqls.Add(_productCategorySetMgr.SaveFromOtherPro(new ProductCategorySet { Product_Id = product_id }));
                    }
                    #endregion

                    #region product_migration_map

                    ProductMigrationMap pMap = new ProductMigrationMap();
                    if (parent.is_exist.ToUpper().Equals("OLD"))
                    {
                        pMap.temp_id = parent.product_id;
                    }
                    else if (parent.is_exist.ToUpper().Equals("NEW"))
                    {
                        pMap.temp_id = parent.temp_id;
                    }
                    sqls.Add(_productMigrationMgr.SaveNoPrid(pMap));

                    #endregion

                    #region notice tag picture

                    sqls.Add(_productNoticeSetMgr.SaveFromOtherPro(new ProductNoticeSet { product_id = product_id }));
                    sqls.Add(_productTagSetMgr.SaveFromOtherPro(new ProductTagSet { product_id = product_id }));
                    sqls.Add(_productPictureMgr.SaveFromOtherPro(new ProductPicture { product_id = Convert.ToInt32(product_id) }));
                    sqls.Add(_productStatusHistoryMgr.SaveNoProductId(new ProductStatusHistory { type = 7, product_status = Convert.ToInt32(newPro.Product_Status) }));
                    #endregion

                    string str = string.Empty;
                    if (_productMgr.ProductMigration(newPro, priceMasters, null, null, sqls, null))
                    {
                        str = "匯入成功";
                    }
                    else
                    {
                        str = "保存至數據庫失敗";
                    }
                    parent.msg = str;
                    source.FindAll(m =>
                                    m.combination.Trim() == "299"
                                    && m.formula.ToUpper().Trim() == parent.temp_id.ToUpper().Trim()
                                    && string.IsNullOrEmpty(m.msg)
                                    && m.new_old.ToUpper().Trim() == "NEW"
                                    && m.formula.ToUpper().Trim().StartsWith("P")).ForEach(m => m.msg = str);
                }

                #region 其他站臺價格

                var pChild = source.Where(m => m.combination.Trim() == "299" && m.new_old.ToUpper().Trim() == "OLD" && string.IsNullOrEmpty(m.msg));
                if (pChild != null)
                {
                    ProductItem item;
                    PriceMaster newPriceMaster;
                    Site site;
                    _priceMasterMgr = new PriceMasterMgr(strConn);
                    foreach (var c in pChild)
                    {
                        ProductMigrationMap prodMigra = _productMigrationMgr.GetSingle(new ProductMigrationMap { temp_id = c.formula.Trim() });
                        if (prodMigra == null)
                        {
                            c.msg = "原料編號對照不存在";
                            continue;
                        }
                        item = _productItemMgr.Query(new ProductItem { Product_Id = uint.Parse(c.product_id) }).FirstOrDefault();
                        if (item == null)
                        {
                            c.msg = "價格檔商品細項不存在";
                            continue;
                        }
                        site = _siteMgr.Query(new Site { Site_Name = c.site.Trim() }).FirstOrDefault();
                        if (site == null)
                        {
                            c.msg = "站臺不存在";
                            continue;
                        }
                        newPriceMaster = new PriceMaster { user_level = 1, same_price = 1, accumulated_bonus = 1, default_bonus_percent = 1, bonus_percent = 1 };
                        newPriceMaster.product_name = c.product_name.Trim();
                        newPriceMaster.product_id = prodMigra.product_id;
                        newPriceMaster.child_id = Convert.ToInt32(prodMigra.product_id);
                        newPriceMaster.site_id = site.Site_Id;
                        newPriceMaster.price_status = 1;
                        #region 成本

                        int cost = 0;
                        if (!string.IsNullOrEmpty(c.cost))
                        {
                            int.TryParse(c.cost, out cost);
                        }
                        else
                        {
                            cost = Convert.ToInt32(item.Item_Cost);
                        }
                        newPriceMaster.cost = cost;
                        #endregion

                        #region 售價

                        int price = 0;
                        if (!string.IsNullOrEmpty(c.price))
                        {
                            int.TryParse(c.price, out price);
                        }
                        else
                        {
                            price = Convert.ToInt32(item.Item_Money);
                        }
                        newPriceMaster.price = price;
                        #endregion
                        newPriceMaster.event_price = Convert.ToInt32(item.Event_Item_Money);
                        newPriceMaster.event_start = item.Event_Product_Start;
                        newPriceMaster.event_end = item.Event_Product_End;

                        ArrayList category_set = new ArrayList();
                        if (site.Site_Name.Trim().ToLower() == "chinatrust")
                        {
                            Product pro= _productMgr.Query(new Product { Product_Id = item.Product_Id }).FirstOrDefault();
                            if (pro == null)
                            {
                                c.msg = "商品不存在";
                                continue;
                            }
                            #region 更新該站臺商品的 product_category_set
                            
                            bool result = true;
                            System.Text.RegularExpressions.Regex regx = new System.Text.RegularExpressions.Regex("^[0-9]*$");
                            string[] cateArray = c.display.Split(',');
                            foreach (string strcate in cateArray)
                            {
                                if (!string.IsNullOrEmpty(strcate))
                                {
                                    if (regx.IsMatch(strcate))
                                    {
                                        ProductCategory query = _cateMgr.QueryAll(new ProductCategory { category_id = uint.Parse(strcate) }).FirstOrDefault();
                                        if (query == null || strcate.Equals("0"))
                                        {
                                            c.msg = "display:" + strcate + " 不存在;";
                                            result = false;
                                            break;
                                        }
                                        else
                                        {
                                            ProductCategorySet category = new ProductCategorySet { Brand_Id = pro.Brand_Id, Category_Id = uint.Parse(strcate), Product_Id = prodMigra.product_id };
                                            if (_productCategorySetMgr.Query(category).FirstOrDefault() == null)
                                            {
                                                category_set.Add(_productCategorySetMgr.Save(category));
                                            }
                                            else
                                            {
                                                c.msg = "display:" + strcate + " 已存在;";
                                                result = false;
                                                break;
                                            }
                                        }
                                    }
                                    else
                                    {
                                        c.msg = "display:" + strcate + " 格式不正確 ";
                                        result = false;
                                        break;
                                    }
                                }
                            }
                            if (!result) continue;
                            #endregion
                        }

                        string str = string.Empty;
                        if (_priceMasterMgr.Save(newPriceMaster, null, category_set, ref str) > 0)
                        {
                            c.msg = "匯入成功";
                        }
                        else
                        {
                            c.msg = string.IsNullOrEmpty(str) ? "保存至數據庫失敗" : str;
                        }
                    }
                }
                #endregion
            }
        }