/// <summary> /// 將文件內容存儲到數據庫 /// </summary> /// <param name="all"></param> /// <param name="pdfFile"></param> /// <param name="importType"></param> /// <param name="chkRecord"></param> /// <param name="totalCount"></param> /// <returns></returns> public int Import2DB(List<OrdersImport> all, string pdfFile, string importType, string chkRecord, int siteId, ref int totalCount) { orderImportMgr = new OrderImportMgr(MySqlConnStr, CurChannel.channel_id); int successCount = 0; try { List<OrdersImport> chks = orderImportMgr.SplitChkData(chkRecord).FindAll(m => m.chlitpdno != "0");//移除廠商商品編號為0的 if (chks != null && all != null && all.Count > 0) { #region 篩選出選中數據資訊 //所有選中商品 var result = from h in chks join o in all on new { h.dmtshxuid, h.chlitpdno } equals new { o.dmtshxuid, o.chlitpdno } into cs from c in cs.DefaultIfEmpty() select c; #endregion //所有訂單編號 List<string> master = chks.GroupBy(m => m.dmtshxuid).Select(m => m.Key).ToList(); totalCount = master == null ? 0 : master.Count; //外站物流業者 channelShippingMgr = new ChannelShippingMgr(MySqlConnStr); List<ChannelShipping> shippings = channelShippingMgr.QueryByChannelId(new ChannelShipping { channel_id = CurChannel.channel_id }); foreach (var om in master) { //單個訂單下所有商品 var product = (from p in result where p.dmtshxuid == om select p).ToList(); all.FindAll(m => m.dmtshxuid == om && product.Exists(n => n.chlitpdno == m.chlitpdno)).ForEach(m => m.IsSel = true); #region 訂單物流業者 ChannelShipping cShipping = null; if (shippings != null) { //查詢該訂單物流業者 取貨方式 cShipping = shippings.Where(m => m.shipco.Trim().ToLower() == product.FirstOrDefault().shipco.Trim().ToLower()).FirstOrDefault(); } if (shippings == null || cShipping == null) { all.FindAll(m => m.dmtshxuid == om && m.IsSel).ForEach(m => m.Msg = Resource.CoreMessage.GetResource("DELIVERY_MAP_NOT_EXISTS")); continue; } #endregion #region 生成OrderSlave List<OrderSlave> slaves = orderImportMgr.GetSlave(product, all); //訂單內商品有問題(商品對照不存在,商品不存在,商品庫存不足),跳過處理下筆訂單 if (slaves == null || slaves.Count == 0) { continue; } #endregion #region OrderMaster OrderMaster newMaster = new OrderMaster(); #region 其他信息 newMaster.Order_Status = 2; //newMaster.Order_Id = uint.Parse(orderImportMgr.NextOrderId()); channelMgr = new ChannelMgr(MySqlConnStr); newMaster.User_Id = Convert.ToUInt32(channelMgr.GetUserIdByChannelId(CurChannel.channel_id)); //備註 if (!string.IsNullOrEmpty(product.FirstOrDefault().xrem)) { newMaster.Note_Order = "購買備註:" + product.FirstOrDefault().xrem; } if (!string.IsNullOrEmpty(product.FirstOrDefault().shipxrem)) { newMaster.Note_Order = string.IsNullOrEmpty(newMaster.Note_Order) ? "配送備註:" + product.FirstOrDefault().shipxrem : newMaster.Note_Order + ",配送備註:" + product.FirstOrDefault().shipxrem; } string name = (System.Web.HttpContext.Current.Session["caller"] as Caller).user_username; newMaster.Note_Admin = name + " 於" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "建立"; if (!string.IsNullOrEmpty(product.FirstOrDefault().orddat)) { newMaster.Order_Createdate = Convert.ToUInt32(CommonFunction.GetPHPTime(product.FirstOrDefault().orddat)); } else { newMaster.Order_Createdate = Convert.ToUInt32(CommonFunction.GetPHPTime()); } newMaster.Order_Date_Pay = Convert.ToUInt32(CommonFunction.GetPHPTime()); newMaster.Import_Time = DateTime.Now; newMaster.Channel = Convert.ToUInt32(CurChannel.channel_id); newMaster.Channel_Order_Id = product.FirstOrDefault().dmtshxuid; if (!string.IsNullOrEmpty(product.FirstOrDefault().agpesadrzip)) { newMaster.Order_Zip = Convert.ToUInt32(product.FirstOrDefault().agpesadrzip); } #endregion #region 发票状态 if (CurChannel.receipt_to != 2) { newMaster.Invoice_Status = 2; } #endregion #region 物流方式 newMaster.Delivery_Store = Convert.ToUInt32(cShipping.shipping_carrior); newMaster.Retrieve_Mode = Convert.ToUInt32(cShipping.retrieve_mode); #endregion #region 運費 var freight = product.Where(m => m.dsr.Contains("物流服務費")).FirstOrDefault(); if (freight != null && !string.IsNullOrEmpty(freight.sumup)) { if (freight.chlitpdno == "6727_13743")//若廠商商品編號為"6727_13743"是低溫運費 { newMaster.Order_Freight_Low = uint.Parse(freight.sumup); } else//若廠商商品編號為"6727_13742"是常溫運費 { newMaster.Order_Freight_Normal = uint.Parse(freight.sumup); } } #endregion #region 訂單價格 product.Where(m => !m.dsr.Contains("物流服務費")).ToList().ForEach(m => newMaster.Order_Product_Subtotal += uint.Parse(string.IsNullOrEmpty(m.sumup) ? "0" : m.sumup)); product.ForEach(m => newMaster.Order_Amount += uint.Parse(string.IsNullOrEmpty(m.sumup) ? "0" : m.sumup)); #endregion #region 支付方式 //若是外站類型為”合作外站”的,匯入訂單時的 payment = 15 newMaster.Order_Payment = 15; //switch (product.FirstOrDefault().Payment) //{ // case "信用卡一次": // newMaster.Order_Payment = 1; // break; // case "7-11貨到付款": // newMaster.Order_Payment = 15; // break; // default: // newMaster.Order_Payment = 1; // break; //} #endregion #region 訂購人信息 newMaster.Order_Name = product.FirstOrDefault().ordpesnm; newMaster.Order_Mobile = product.FirstOrDefault().ordpesnacttel.Replace("'", "");//去掉電話中的單引號 if (string.IsNullOrEmpty(newMaster.Order_Mobile)) { newMaster.Order_Mobile = product.FirstOrDefault().agpesacttel.Replace("'", "");//去掉電話中的單引號 } newMaster.Order_Address = product.FirstOrDefault().agpesadr;//order_address與delivery_address相同 #endregion #region 發貨信息 newMaster.Delivery_Name = product.FirstOrDefault().agpesnm; newMaster.Delivery_Mobile = product.FirstOrDefault().agpesacttel.Replace("'", "");//去掉電話中的單引號 newMaster.Delivery_Phone = product.FirstOrDefault().agpestel1.Replace("'", "");//去掉電話中的單引號 if (!string.IsNullOrEmpty(product.FirstOrDefault().agpesadrzip)) { newMaster.Delivery_Zip = uint.Parse(product.FirstOrDefault().agpesadrzip); } newMaster.Delivery_Address = product.FirstOrDefault().agpesadr; #endregion #endregion #region ChannelOrder List<ChannelOrder> cOrder = new List<ChannelOrder>(); ChannelOrder channelOrder; foreach (var slave in slaves) { foreach (var detail in slave.Details) { detail.Site_Id = siteId;//add xw 2014/02/03 //ChannelOrder channelOrder = new ChannelOrder { Channel_Id = CurChannel.channel_id, Order_Id = newMaster.Channel_Order_Id.ToString() }; var p = product.Where(m => m.chlitpdno == detail.Channel_Detail_Id).FirstOrDefault(); if (p != null) { //if (importType == "2") //{ // //channelOrder.Store_Dispatch_File = pdfFile; //} channelOrder.Dispatch_Seq = p.shipno; channelOrder.Channel_Detail_Id = detail.Channel_Detail_Id; if (!string.IsNullOrEmpty(p.orddat)) { channelOrder.Createtime = Convert.ToDateTime(p.orddat); } channelOrder.Ordertime = channelOrder.Createtime; if (!string.IsNullOrEmpty(p.prndldat)) { channelOrder.Latest_Deliver_Date = Convert.ToDateTime(p.prndldat); } cOrder.Add(channelOrder); } } } #endregion #region 寫入數據庫 if (orderImportMgr.Save2DB(newMaster, slaves, cOrder, all)) { all.FindAll(m => m.dmtshxuid == om && m.IsSel).ForEach(m => m.Msg = Resource.CoreMessage.GetResource("IMPORT_SUCCESS")); successCount++; } #endregion } } } catch (Exception ex) { throw new Exception("OrderImportPayEasy-->Import2DB-->" + ex.Message, ex); } return successCount; }
public HttpResponseBase SaveChannelShipping() { chsMgr = new ChannelShippingMgr(connectString); string json = string.Empty; try { if (!string.IsNullOrEmpty(Request.Form["InsertValues"]) && !string.IsNullOrEmpty(Request.Form["channel_id"])) { string[] Values = Request.Form["InsertValues"].ToString().Split(';'); for (int n = 0; n < Values.Length - 1; n++) { string[] Val = Values[n].Split(','); if (!string.IsNullOrEmpty(Val[1].ToString())) chs.shipping_carrior = Int32.Parse(Val[1].ToString()); if (!string.IsNullOrEmpty(Val[2].ToString())) chs.n_threshold = Int32.Parse(Val[2].ToString()); if (!string.IsNullOrEmpty(Val[3].ToString())) chs.l_threshold = Int32.Parse(Val[3].ToString()); if (!string.IsNullOrEmpty(Val[4].ToString())) chs.n_fee = Int32.Parse(Val[4].ToString()); if (!string.IsNullOrEmpty(Val[5].ToString())) chs.l_fee = Int32.Parse(Val[5].ToString()); if (!string.IsNullOrEmpty(Val[6].ToString())) chs.n_return_fee = Int32.Parse(Val[6].ToString()); if (!string.IsNullOrEmpty(Val[7].ToString())) chs.l_return_fee = Int32.Parse(Val[7].ToString()); if (!string.IsNullOrEmpty(Val[10].ToString())) chs.shipco = Val[10].ToString(); if (!string.IsNullOrEmpty(Val[9].ToString())) chs.retrieve_mode = Int32.Parse(Val[9].ToString()); chs.createdate = DateTime.Now; chs.updatedate = DateTime.Now; chs.channel_id = Int32.Parse(Request.Form["channel_id"].ToString()); List<ChannelShipping> result = chsMgr.Query(chs); if (!string.IsNullOrEmpty(Val[0].ToString()) /*&& !string.IsNullOrEmpty(Val[1].ToString())*/) { int shippingCarrior = Int32.Parse(Val[0].ToString()); //int shippingType = Int32.Parse(Val[1]); string shipco_content = Val[8].ToString(); chs.updatedate = DateTime.Now; if (Val[0].ToString() != Val[1].ToString() || Val[10].ToString() != Val[8].ToString())//判斷是否對主鍵進行了修改 { List<ChannelShipping> resultEdit = chsMgr.Query(chs); //若修改就去比對數據庫 if (resultEdit.Count > 0) //修改重複 { json = "{success:true,msg:\"" + Resources.Channel.RECORD_REPEAT + "。\"}"; this.Response.Clear(); this.Response.Write(json); this.Response.End(); return this.Response; } } chsMgr.Edit(chs, shippingCarrior, shipco_content); } else { if (result.Count > 0) { json = "{success:true,msg:\"" + Resources.Channel.RECORD_REPEAT + "。\"}"; this.Response.Clear(); this.Response.Write(json); this.Response.End(); return this.Response; } chsMgr.Save(chs); } } json = "{success:true,msg:\"" + Resources.Channel.SUCCESS + "。\"}"; } else { json = "{success:true,msg:\"" + Resources.Channel.FAILED + "\"}"; } } 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:true,msg:\"" + Resources.Channel.FAILED + "\"}"; } this.Response.Clear(); this.Response.Write(json); this.Response.End(); return this.Response; }
public HttpResponseBase SaveChannel() { zMgr = new ZipMgr(connectString); chMgr = new ChannelMgr(connectString); uMgr = new UsersMgr(connectString); string json = string.Empty; bool result = false; string channel_id = Request.Form["channel_id"] ?? string.Empty; try { if (!string.IsNullOrEmpty(Request.Form["channel_status"])) { ch.channel_status = Int32.Parse(Request.Form["channel_status"].ToString()); } if (!string.IsNullOrEmpty(Request.Form["channel_type"])) { ch.channel_type = Int32.Parse(Request.Form["channel_type"].ToString()); } if (!string.IsNullOrEmpty(Request.Form["channel_name_full"])) { ch.channel_name_full = Request.Form["channel_name_full"].ToString(); u.user_name = Request.Form["channel_name_full"].ToString(); List<Channel> channel = chMgr.QueryC(" and channel_name_full='" + Request.Form["channel_name_full"] + "'"); if (channel != null && channel.Count > 0 && channel.Where(m => m.channel_id == int.Parse(string.IsNullOrEmpty(channel_id) ? "0" : channel_id)).Count() == 0) { json = "{success:true,msg:\""+Resources.Channel.CHANNEL_HAS_EXIST+"。\",channelId:\"" + channel_id + "\"}"; this.Response.Clear(); this.Response.Write(json); this.Response.End(); return this.Response; } } if (!string.IsNullOrEmpty(Request.Form["channel_name_simple"])) { ch.channel_name_simple = Request.Form["channel_name_simple"].ToString(); } if (!string.IsNullOrEmpty(Request.Form["channel_invoice"])) { ch.channel_invoice = Request.Form["channel_invoice"].ToString(); u.user_password = Request.Form["channel_invoice"].ToString(); } if (!string.IsNullOrEmpty(Request.Form["channel_email"])) { ch.channel_email = Request.Form["channel_email"].ToString(); } else { ch.channel_email = ""; } if (!string.IsNullOrEmpty(Request.Form["company_cphonenum"])) { ch.company_phone = Request.Form["company_cphone"].ToString() +Request.Form["company_cphonenum"].ToString(); } else { ch.company_phone = ""; } if (!string.IsNullOrEmpty(Request.Form["company_cfaxnum"])) { ch.company_fax = Request.Form["company_cfax"].ToString() +Request.Form["company_cfaxnum"].ToString(); } else { ch.company_fax = ""; } if (!string.IsNullOrEmpty(Request.Form["company_zip"])) { ch.company_zip = Int32.Parse(Request.Form["company_zip"].ToString()); } else { ch.company_zip = 0; } if (!string.IsNullOrEmpty(Request.Form["company_address"])) { ch.company_address = Request.Form["company_address"].ToString(); } else { ch.company_address = ""; } if (!string.IsNullOrEmpty(Request.Form["invoice_title"])) { ch.invoice_title = Request.Form["invoice_title"].ToString(); } if (!string.IsNullOrEmpty(Request.Form["invoice_zip"])) { ch.invoice_zip = Int32.Parse(Request.Form["invoice_zip"].ToString()); } if (!string.IsNullOrEmpty(Request.Form["invoice_address"])) { ch.invoice_address = Request.Form["invoice_address"].ToString(); } if (!string.IsNullOrEmpty(Request.Form["contract_createdate"])) { ch.contract_createdate = DateTime.Parse(Request.Form["contract_createdate"].ToString()); } else { ch.contract_createdate = DateTime.MinValue; } if (!string.IsNullOrEmpty(Request.Form["contract_start"])) { ch.contract_start = DateTime.Parse(Request.Form["contract_start"].ToString()); } else { ch.contract_start = DateTime.MinValue; } if (!string.IsNullOrEmpty(Request.Form["contract_end"])) { ch.contract_end = DateTime.Parse(Request.Form["contract_end"].ToString()); } else { ch.contract_end = DateTime.MinValue; } if (!string.IsNullOrEmpty(Request.Form["annaul_fee"])) { ch.annaul_fee = Decimal.Parse(Request.Form["annaul_fee"].ToString()); } else { ch.annaul_fee = 0; } if (!string.IsNullOrEmpty(Request.Form["renew_fee"])) { ch.renew_fee = Decimal.Parse(Request.Form["renew_fee"].ToString()); } else { ch.renew_fee = 0; } if (!string.IsNullOrEmpty(Request.Form["model_in"])) { ch.model_in = Request.Form["model_in"].ToString(); } else { ch.model_in = "1"; } if (!string.IsNullOrEmpty(Request.Form["notify_sms"])) { ch.notify_sms = Int32.Parse(Request.Form["notify_sms"].ToString()); } else { ch.notify_sms = 0; } //add by xiangwang0413w 2014/06/26 增加 ERP客戶代號 if (!string.IsNullOrEmpty(Request.Form["erp_id"])) { ch.erp_id = Request.Form["erp_id"]; } DataTable dtUsers = uMgr.Query(Request.Form["manager_Email"].ToString()); if (dtUsers.Rows.Count > 0)//會員信箱已存在 { DataTable dtUserId = chMgr.QueryUser(dtUsers.Rows[0]["user_id"].ToString()); if (string.IsNullOrEmpty(channel_id))//新增 { if (dtUserId.Rows.Count > 0)//是否被外站使用 { json = "{success:true,msg:\""+Resources.Channel.MAIL_WAS_USED+"。\",channelId:\"" + channel_id + "\"}"; this.Response.Clear(); this.Response.Write(json); this.Response.End(); return this.Response; } else { ch.user_id = Int32.Parse(dtUsers.Rows[0]["user_id"].ToString()); channel_id = chMgr.Save(ch).ToString(); result = Int32.Parse(channel_id) > 0; } } else { //修改 if (dtUserId.Rows.Count > 0) { if (dtUserId.Rows[0]["channel_id"].ToString() != channel_id) { json = "{success:true,msg:\"" + Resources.Channel.MAIL_WAS_USED + "。\",channelId:\"" + channel_id + "\"}"; this.Response.Clear(); this.Response.Write(json); this.Response.End(); return this.Response; } else { ch.user_id = Int32.Parse(dtUsers.Rows[0]["user_id"].ToString()); } } else { ch.user_id = Int32.Parse(dtUsers.Rows[0]["user_id"].ToString()); } ch.channel_id = Int32.Parse(channel_id); result = chMgr.Edit(ch) > 0; } } else { //會員信箱不存在 u.user_email = Request.Form["manager_Email"].ToString(); u.user_name = Request.Form["channel_name_full"].ToString(); BLL.gigade.Common.HashEncrypt hash = new BLL.gigade.Common.HashEncrypt(); u.user_password = hash.SHA256Encrypt(Request.Form["invoice_title"].ToString()); u.user_mobile = "0227833183"; u.user_phone = "0227833183"; u.user_zip = 115; u.user_address = Resources.Channel.USER_ADDRESS; u.user_status = 1; u.user_reg_date = (int)BLL.gigade.Common.CommonFunction.GetPHPTime(); u.user_updatedate = (int)BLL.gigade.Common.CommonFunction.GetPHPTime(); u.user_birthday_year = 1900; u.user_birthday_month = 01; u.user_birthday_day = 01; if (uMgr.SelSaveID(u) > 0) { ch.user_id = Convert.ToInt32(u.user_id); } if (string.IsNullOrEmpty(channel_id)) { channel_id=chMgr.Save(ch).ToString(); /** *如果外站類型是gigade,則將參數表中type=deliver_store(即所有物流方式)全部插入channel_shipping表中 ***/ if (ch.channel_type == 2) { paraMgr = new ParameterMgr(connectString); chsMgr = new ChannelShippingMgr(connectString); List<Parametersrc> Deliver_result = paraMgr.QueryUsed(new Parametersrc { ParameterType = "deliver_store", Used = 1 }); foreach (Parametersrc item in Deliver_result) { chs.channel_id = int.Parse(channel_id); chs.shipping_carrior = int.Parse(item.ParameterCode); chs.shipco = item.parameterName; chsMgr.Save(chs); } } /* end by zhongyu0304w at 2013/10/10 */ result = Int32.Parse(channel_id) > 0; } else { ch.channel_id = int.Parse(channel_id); result = chMgr.Edit(ch) > 0; } } if (result) { json = "{success:true,msg:\""+Resources.Channel.SUCCESS+"。\",channelId:\"" + channel_id + "\"}"; } else { json = "{success:true,msg:\""+Resources.Channel.FAILED+"\",channelId:\"" + channel_id + "\"}"; } } 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:true,msg:\"" + Resources.Channel.FAILED + "\",channelId:\"" + channel_id + "\"}"; } this.Response.Clear(); this.Response.Write(json); this.Response.End(); return this.Response; }
public string QueryShipping() { chsMgr = new ChannelShippingMgr(connectString); string json = string.Empty; try { if (!string.IsNullOrEmpty(Request.QueryString["channel_id"])) { json = chsMgr.Query(Request.QueryString["channel_id"].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); json = "[]"; } return json; }
public HttpResponseBase DeleteShipping() { chsMgr = new ChannelShippingMgr(connectString); string json = string.Empty; int num = 0; int channelid = 0; int shippingcarrior = 0; //int shippingtype = 0; try { if (!string.IsNullOrEmpty(Request.Form["channel_id"]) && !string.IsNullOrEmpty(Request.Form["shippingcarrior"]) /*&& !string.IsNullOrEmpty(Request.Form["shippingtype"])*/) { channelid = Int32.Parse(Request.Form["channel_id"].ToString()); shippingcarrior = Int32.Parse(Request.Form["shippingcarrior"].ToString()); //shippingtype = Int32.Parse(Request.Form["shippingtype"].ToString()); } num = chsMgr.Delete(channelid, shippingcarrior); if (num > 0) { json = "{success:true,msg:\"\",channelId:" + num.ToString() + "}"; } else { json = "{success:true,msg:\"\"}"; } } catch (Exception ex) { Log4NetCustom.LogMessage logMessage = new Log4NetCustom.LogMessage(); logMessage.Content = string.Format("TargetSite:{0},Source:{1},Message:{2}", ex.TargetSite.Name, ex.Source, ex.Message); logMessage.MethodName = System.Reflection.MethodBase.GetCurrentMethod().Name; log.Error(logMessage); json = "{success:true,msg:\"" + Resources.Channel.FAILED + "\"}"; } this.Response.Clear(); this.Response.Write(json); this.Response.End(); return this.Response; }
public string GetStore() { string storeType = Request.Form["storeType"] ?? "0"; string channelId = Request.Form["channel_id"] ?? "0"; string resultStr = ""; ParameterMgr paraMgr = new ParameterMgr(connectionString); ChannelShippingMgr shipMgr = new ChannelShippingMgr(connectionString); //switch (storeType) //{ // case "1": resultStr = shipMgr.QueryCarry(channelId); break; // case "2": resultStr = paraMgr.Query("Deliver_Store", 1); break; // default: // break; //} resultStr = shipMgr.QueryCarry(channelId); return resultStr; }