/** * PrintAwbOrder.aspx.cs * * 功 能: 打印送货单 * 类 名: PrintAwbOrder * * Ver 变更日期 负责人 变更内容 * ─────────────────────────────────── * V0.01 2013-5-17 17:54 吴崎均 初版 * * * */ using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using CY.BLL.EC; using CY.BLL; using CY.Model; using CY.Infrastructure.Common; using System.Text; using CY.BLL.Sys; using System.Transactions; namespace CY.WebForm.Pages.business { /// /// 打印送货单 /// public partial class PrintAwbOrder : BasePage { EC_OrderBasicBLL _eC_OrderBasicBLL = null; OA_CorporateClientsBLL _oA_CorporateClientsBLL = null; EC_MemberBasicBLL _eC_MemberBasicBLL = null; OA_StaffBLL oA_StaffBLL = null; OA_DeliverPlanBLL _OA_DeliverPlanBLL = null; OA_DeliverPlanBLL oA_DeliverPlanBLL = null; /// /// 初始化构造 /// public PrintAwbOrder() { _eC_OrderBasicBLL = new EC_OrderBasicBLL(); _oA_CorporateClientsBLL = new OA_CorporateClientsBLL(); _eC_MemberBasicBLL = new EC_MemberBasicBLL(); oA_StaffBLL = new OA_StaffBLL(); _OA_DeliverPlanBLL = new OA_DeliverPlanBLL(); oA_DeliverPlanBLL = new OA_DeliverPlanBLL(); } /// /// 界面加载事件 /// /// /// protected void Page_Load(object sender, EventArgs e) { int shifouDelivery = MyConvert.ConvertToInt(Request["shifouDelivery"]).Value; int orderId = Request["orderId"].ToString().ToInt32().Value; Guid buyerid = MyConvert.ConvertToGuid(Request["buyerid"]); if (string.IsNullOrEmpty(Request["ids"]) || Guid.Empty.Equals(buyerid)) { Response.Clear(); Response.Write(""); Response.End(); return; } else ; string buyerNmae = string.Empty; string buyerPhone = string.Empty; string address = string.Empty; string prepayments = "0.00"; string Remark = ""; List eC_AcceptWayByOrders = null; OA_CorporateClients oA_CorporateClients = null; OA_CustomerCommunications oA_CustomerCommunications = null; EC_MemberExtend eC_MemberExtend = null; OA_CorporateClients oA_CorporateClientsBiddingcompany = null; try { eC_AcceptWayByOrders = _eC_OrderBasicBLL.SelectOrderAddress(Request["ids"].Trim()) as List; oA_CorporateClients = _oA_CorporateClientsBLL.SelectModelByFirmIdandMemberId(CurrentUser.MemberId, buyerid); oA_CorporateClientsBiddingcompany = _oA_CorporateClientsBLL.SelectBiddingcompanyByFirmId(CurrentUser.MemberId).Where(x=>x.Keyid1 == oA_CorporateClients.Biddingcompany).FirstOrDefault(); if (oA_CorporateClientsBiddingcompany != null) { this.spnD.InnerText = oA_CorporateClientsBiddingcompany.CompanyName; } OA_Staff oA_Staff = oA_StaffBLL.GetModelByKeyid(oA_CorporateClients.BusinessManagerId); if (oA_Staff != null) { this.spnB.InnerText = oA_Staff.Name; } this.spnC.InnerText = CurrentUser.TrueName; if (null == oA_CorporateClients) { EC_MemberExtend buyerMemberExtend = _eC_MemberBasicBLL.GetMemberExtendByMemberId(buyerid); buyerNmae = buyerMemberExtend.Name; buyerPhone = buyerMemberExtend.PhoneNum; address = buyerMemberExtend.DetailedAddress; } else { oA_CustomerCommunications = _oA_CorporateClientsBLL.GetModel_CustomerCommunications(oA_CorporateClients.Keyid); buyerNmae = oA_CorporateClients.CompanyName; buyerPhone = oA_CustomerCommunications.CompanyPhone; address = oA_CustomerCommunications.DetailedAddress; prepayments = (oA_CorporateClients.Prepayments.HasValue ? oA_CorporateClients.Prepayments.Value : 0).ToString("F2"); } buyerNmae = string.IsNullOrEmpty(buyerNmae) ? string.Empty : buyerNmae; buyerPhone = string.IsNullOrEmpty(buyerPhone) ? string.Empty : buyerPhone; address = string.IsNullOrEmpty(address) ? string.Empty : address; prepayments = string.IsNullOrEmpty(prepayments) ? string.Empty : prepayments; eC_MemberExtend = _eC_MemberBasicBLL.GetMemberExtendByMemberId(CurrentUser.MemberId); //address = GetAddress(eC_AcceptWayByOrders, address); //if (string.IsNullOrEmpty(address)) //{ // Response.Clear(); // Response.Write(string.Format("", 1 == eC_AcceptWayByOrders.Count ? "没有收货地址" : "要合并的订单收货地址必须一致")); // Response.End(); //} string accepterAddress = string.Empty; string accepterPhone = string.Empty; EC_AcceptWayByOrderBLL _AcceptWayByOrderBLL = new EC_AcceptWayByOrderBLL(); EC_AcceptWayByOrder model = _AcceptWayByOrderBLL.GetModelByTargetId(orderId); EC_AwbInfo m_EC_AwbInfo = _eC_OrderBasicBLL.SelectAwbInfoById(orderId); if (model != null) { accepterAddress = model.AccepterAddress; accepterPhone = model.AccepterPhone; } if (!string.IsNullOrEmpty(accepterAddress)) { address = accepterAddress; } if (!string.IsNullOrEmpty(accepterPhone)) { buyerPhone = accepterPhone; } if (m_EC_AwbInfo != null) { Remark = m_EC_AwbInfo.Remark; } this.spnRemark.InnerHtml = Remark; StringBuilder builder = new StringBuilder(); builder.Append("{"); builder.Append("BuyerName:'"); builder.Append(buyerNmae); builder.Append("',"); builder.Append("BuyerPhone:'"); builder.Append(buyerPhone); builder.Append("',"); builder.Append("BuyerAddress:'"); builder.Append(address); builder.Append("',"); builder.Append("BuyerPrepayments:'"); builder.Append(prepayments); builder.Append("',"); builder.Append("SellerName:'"); builder.Append(eC_MemberExtend.Name); builder.Append("',"); builder.Append("SellerAddress:'"); builder.Append(eC_MemberExtend.DetailedAddress); builder.Append("',"); builder.Append("SellerPhone:'"); builder.Append(eC_MemberExtend.PhoneNum); builder.Append("',"); builder.Append("SellerShortName:'"); builder.Append(CurrentUser.ShortName); builder.Append("'}"); txtOtherInfo.Value = builder.ToString(); EC_OrderBasic eC_OrderBasic = _eC_OrderBasicBLL.SelectModelById(orderId); if (!eC_OrderBasic.DeliveryOrderId.HasValue || eC_OrderBasic.DeliveryOrderId.Equals(Guid.Empty)) { string ssss = DateTime.Now.ToString("yyyyMMdd"); string SellerOrderId = ssss+ 1.ToString("000"); string maxSellerOrderId = oA_DeliverPlanBLL.GetModelByformid(CurrentUser.MemberId).Where(x=>x.SellerOrderId.Contains(ssss)).Max(x=>x.SellerOrderId); if (!string.IsNullOrWhiteSpace(maxSellerOrderId)) { string aaaaaaaaaaaa = maxSellerOrderId.Substring(maxSellerOrderId.Length - 3, 3); SellerOrderId = ssss + (aaaaaaaaaaaa.ToInt32().Value+1).ToString("000"); } this.SellerOrderId.InnerText = SellerOrderId; using (TransactionScope scope = new TransactionScope()) { OA_DeliverPlan oA_DeliverPlan = new OA_DeliverPlan(); oA_DeliverPlan.Lianxiren = model.Accepter; oA_DeliverPlan.Keyid = Guid.NewGuid(); oA_DeliverPlan.FirmId = CurrentUser.MemberId; oA_DeliverPlan.DeliverTime = eC_OrderBasic.DeliveryTime; oA_DeliverPlan.BuyerId = eC_OrderBasic.BuyerId; oA_DeliverPlan.DeliveredTime = null; oA_DeliverPlan.Zhuyishixiang = ""; oA_DeliverPlan.Gongzuokaoping = ""; oA_DeliverPlan.CarId = 0; oA_DeliverPlan.DriverId = 0; oA_DeliverPlan.Transferstatus = 1; oA_DeliverPlan.TransfersTime = null; oA_DeliverPlan.Sort = 1; oA_DeliverPlan.Creater = CurrentUser.TrueMemberId; oA_DeliverPlan.CreateTime = DateTime.Now; oA_DeliverPlan.Updater = CurrentUser.TrueMemberId; oA_DeliverPlan.LastUpdateTime = DateTime.Now; oA_DeliverPlan.wentifankui = ""; oA_DeliverPlan.SellerOrderId = SellerOrderId; oA_DeliverPlan.Dianhua = model.AccepterPhone; oA_DeliverPlan.Dizhi = model.AccepterAddress; oA_DeliverPlan.Remark = ""; oA_DeliverPlan.BusinessManagerId = oA_CorporateClients.BusinessManagerId??0; oA_DeliverPlan.Biddingcompany = oA_CorporateClients.Biddingcompany??0; oA_DeliverPlan.shifouDelivery = shifouDelivery; _OA_DeliverPlanBLL.InsertModel(oA_DeliverPlan); string[] orderids = Request["ids"].Split(','); foreach (string oid in orderids) { _eC_OrderBasicBLL.UpdateDeliveryOrderId(oid.ToInt32().Value, oA_DeliverPlan.Keyid); } scope.Complete(); } } else { OA_DeliverPlan oA_DeliverPlan = _OA_DeliverPlanBLL.GetModelByKeyid(eC_OrderBasic.DeliveryOrderId,null,null); this.SellerOrderId.InnerText = oA_DeliverPlan.SellerOrderId; oA_DeliverPlan.Dianhua = model.AccepterPhone; oA_DeliverPlan.Dizhi = model.AccepterAddress; oA_DeliverPlan.Lianxiren = model.Accepter; oA_DeliverPlan.Remark = ""; oA_DeliverPlan.BusinessManagerId = oA_CorporateClients.BusinessManagerId ?? 0; oA_DeliverPlan.Biddingcompany = oA_CorporateClients.Biddingcompany ?? 0; //oA_DeliverPlan.shifouDelivery = shifouDelivery; oA_DeliverPlan.DeliverTime = eC_OrderBasic.DeliveryTime; _OA_DeliverPlanBLL.UpdateModel(oA_DeliverPlan); } } catch (Exception ex) { PAGEHandleException(ex); Response.Clear(); Response.Write(""); Response.End(); } } /// /// 获取订单送货地址 /// /// 订单收货地址 /// 默认收货地址 private static string GetAddress(List eC_AcceptWayByOrders, string defaultAddress) { if (null == eC_AcceptWayByOrders || 0 == eC_AcceptWayByOrders.Count) return null; Sys_DictionaryBLL _sys_DictionaryBLL = new Sys_DictionaryBLL(); List sys_Dictionaries = _sys_DictionaryBLL.GetDataByType("收货方式") as List; Dictionary typs = new Dictionary(); sys_Dictionaries.Find(delegate(Sys_Dictionary sys_Dictionary) { typs.Add(sys_Dictionary.Keyid.Value, sys_Dictionary.Name); return false; }); string address = string.Empty; eC_AcceptWayByOrders.Find(delegate(EC_AcceptWayByOrder tempAcceptWay) { switch (typs[tempAcceptWay.AcceptTypeId.Value]) { case "自提": case "代发货运": default: break; case "送货上门": case "指定货运公司": if (null == address) return true; else ;//地址不相同时直接跳出 //地址为空字符时或者地址与收货地址相同时地址为收货地址,否则地址不相同(为空) address = 0 == address.Length || (!string.IsNullOrEmpty(tempAcceptWay.AccepterAddress) && address.Equals(tempAcceptWay.AccepterAddress)) ? tempAcceptWay.AccepterAddress : null; break; } return false; }); if (null == address)//地址完全不一致 { return null; } else if (string.Empty.Equals(address)) //都是自提或是代发货运时采用默认地址 { return defaultAddress; } else { return address;//地址一致时采用一致的地址 } } } }