using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CY.BLL.Sys;
using CY.BLL;
using CY.Model;
using CY.Infrastructure.Common;
using CY.WebForm.Pages.common;
using CY.BLL.EC;
using CY.Model.Inquiry;
using CY.Infrastructure.Query;
using System.Configuration;
namespace CY.WebForm.Pages.business
{
public partial class AgOutsourcSingleAllEdit : BasePage
{
OA_CorporateClientsBLL bll_OA_CorporateClientsBLL = null;
Sys_DictionaryBLL bll_Sys_DictionaryBLL = null;
EC_OrderBLL bll_EC_OrderBLL = null;
OA_StaffBLL bll_OA_StaffBLL = null;
public Guid targetid = Guid.Empty;
public static string Keyid;
public static bool IsFiles = false;
public string strUploadFileURL
{
get
{
return ConfigurationManager.AppSettings["UploadFileURL"];
}
}
public AgOutsourcSingleAllEdit()
{
bll_OA_CorporateClientsBLL = new OA_CorporateClientsBLL();
bll_Sys_DictionaryBLL = new Sys_DictionaryBLL();
bll_EC_OrderBLL = new EC_OrderBLL();
bll_OA_StaffBLL = new OA_StaffBLL();
}
///
/// 页面加载事件
///
///
///
protected void Page_Load(object sender, EventArgs e)
{
try
{
switch (Request["Target"])
{
case "ToUpSetData":
Page_Load_Default();
LoadOrderInfo();
return;
default:
Page_Load_Default();
return;
}
}
catch (Exception ex)
{
PAGEHandleException(ex);
Response.Clear();
Response.Write("-1");
}
Response.End();
}
private void LoadOrderInfo()
{
if (IsPostBack || IsCallback)
return;
targetid = CurrentUser.MemberId;
this.txtDeliveryTime.Value = DateTime.Now.AddDays(15).ToString("yyyy-MM-dd");
EC_OrderBasicBLL _eC_OrderBasicBLL = new EC_OrderBasicBLL();
string orderIdStr = Request["orderid"];
//Keyid = Request["orderid"];
if (string.IsNullOrEmpty(orderIdStr) || "0".Equals(orderIdStr))
return;
else
;
if (string.IsNullOrEmpty(orderIdStr))
{
JavaScript.MessageBox("未传递参数!", this);
return;
}
int? orderid = MyConvert.ConvertToInt32(orderIdStr);
if (!orderid.HasValue)
{
JavaScript.MessageBox("未传递参数!", this);
return;
}
EC_OrderPrintParameterBLL _eC_OrderPrintParameterBLL = new EC_OrderPrintParameterBLL();
EC_OrderPrintParameter _eC_OrderPrintParameter = _eC_OrderPrintParameterBLL.GetModel(orderid.Value);
InquiryCommonModel _inquiryCommonModel = null;
if (null == _eC_OrderPrintParameter)
{
_inquiryCommonModel = new InquiryCommonModel();
}
else
{
_inquiryCommonModel = SerializationHelper.DeSerialize(typeof(InquiryCommonModel), _eC_OrderPrintParameter.PrintParameter) as InquiryCommonModel;
}
this.txtAfterWorksDemand.InnerText = _inquiryCommonModel.AfterWorksDemand;
this.txtPrintDemand.InnerText = _inquiryCommonModel.PrintDemand;
EC_OrderBasic _eC_OrderBasic = _eC_OrderBasicBLL.SelectModelById(orderid.Value);
this.spanOrderNum.InnerText = _eC_OrderBasic.SellerOrderId;
this.spanOrderType.InnerText = _eC_OrderBasic.OrderType.Name;
this.spanOrderTitle.InnerText = _eC_OrderBasic.DocumentName;
this.spanOrderDeliveryTime.InnerText = _eC_OrderBasic.DeliveryTime == null ? "" : _eC_OrderBasic.DeliveryTime.Value.ToString("yyyy-MM-dd HH:mm");
this.spanOrderCustormName.InnerText = _eC_OrderBasic.BuyerName;
this.spanOrderCustormLevel.InnerText = _eC_OrderBasic.OrderExtend.CustomerLevel.Name;
this.spanOrderCustormPeople.InnerText = _eC_OrderBasic.OrderExtend.Contacts;
this.spanOrderCustormPhone.InnerText = _eC_OrderBasic.OrderExtend.ContactPhone;
this.spanOrderBusinessManage.InnerText = _eC_OrderBasic.OrderExtend.BusinessManager.Name;
this.spanOrderCustormManage.InnerText = _eC_OrderBasic.OrderExtend.CustomerManager.Name;
this.spanVerifyWay.InnerText = _eC_OrderBasic.OrderExtend.ProofreadWay.Name;
this.spanExigencyDegree.InnerText = _eC_OrderBasic.OrderExtend.ExigencyCase.Name;
this.spanUnitPrice.InnerText = (_eC_OrderBasic.UnitPrice ?? 0).ToString("0.00");
this.spanSumPrice.InnerText = (_eC_OrderBasic.SumPrice ??0).ToString("0.00");
this.spanSurplusPrintNum.InnerText = _eC_OrderBasic.OrderExtend.SurplusPrintNum.ToString2();
//this.spanSpecialOprator.InnerText = CurrentUser.ShortName;
this.selBusinessManager.Value = _eC_OrderBasic.Creater;
this.spanSpecialTime.InnerText = DateTime.Now.ToString("yyyy-MM-dd HH:mm");
this.txtRemark.Value = _eC_OrderBasic.Remark.ToString2();
Pagination pa = new Pagination();
pa.PageSize = 500;
pa.PageIndex = 1;
var ss = bll_OA_CorporateClientsBLL.SelectModelPage(pa, CurrentUser.MemberId, "");
this.selOutFirm.DataSource = ss;
this.selOutFirm.DataTextField = "OutVendorName";
this.selOutFirm.DataValueField = "FirmId";
this.selOutFirm.DataBind();
this.selOutFirm.Items.Insert(0, new ListItem("请选择", ""));
var aaa = ss.FirstOrDefault(x => x.OutVendorName == "其他");
if (aaa != null)
{
this.selOutFirm.SelectedValue = aaa.FirmId.ToString();
}
selOutFirm_SelectedIndexChanged(null, null);
}
///
/// 默认执行方法
///
private void Page_Load_Default()
{
btnSave.ServerClick += new EventHandler(btnSave_ServerClick);
if (!IsPostBack && !IsCallback)
{
this.selExigencyDegree.DataSource = bll_Sys_DictionaryBLL.GetDataByType("OA_紧急程度");
this.selExigencyDegree.DataBind();
this.selExigencyDegree.Items.Add(new ListItem("请选择", ""));
this.selExigencyDegree.Value = "0";
this.selBusinessManager.DataSource = bll_OA_StaffBLL.SelectListByFirmId(CurrentUser.MemberId, true, false);
this.selBusinessManager.DataTextField = "Name";
this.selBusinessManager.DataValueField = "Name";
this.selBusinessManager.DataBind();
//this.selBusinessManager.Items.Insert(0, new ListItem("全部", ""));
}
}
///
/// 保存点击事件
///
///
///
void btnSave_ServerClick(object sender, EventArgs e)
{
if (SaveOrder())
{
//操作成功
JavaScript.RefreshDIVOpener(this);
}
else
{
//操作失败
JavaScript.MessageBox("操作失败!", this);
}
}
///
/// 保存订单
///
private bool SaveOrder()
{
EC_OrderBasicBLL _eC_OrderBasicBLL = new EC_OrderBasicBLL();
string orderIdStr = Request["orderid"];
if (string.IsNullOrEmpty(orderIdStr) || "0".Equals(orderIdStr))
return false;
if (string.IsNullOrEmpty(orderIdStr))
{
JavaScript.MessageBox("未传递参数!", this);
return false;
}
if (string.IsNullOrEmpty(this.selOutFirm.SelectedValue))
{
JavaScript.MessageBox("未选择外协厂商!", this);
return false;
}
int? orderid = MyConvert.ConvertToInt32(orderIdStr);
if (!orderid.HasValue)
{
JavaScript.MessageBox("未传递参数!", this);
return false;
}
OA_CorporateClients m_OA_CorporateClients_Out = bll_OA_CorporateClientsBLL.SelectModelByFirmIdandMemberId(this.selOutFirm.SelectedValue.ToGuid2(),CurrentUser.MemberId);
OA_CustomerCommunications m_OA_CustomerCommunications_Out = bll_OA_CorporateClientsBLL.GetModel_CustomerCommunications(m_OA_CorporateClients_Out.Keyid);
EC_OrderBasic _eC_OrderBasic = _eC_OrderBasicBLL.SelectModelById(orderid.Value);
EC_OrderExtend OrderExtend = new EC_OrderExtend();
EC_OrderBasic m_EC_OrderBasicNew = new EC_OrderBasic();
m_EC_OrderBasicNew.SellerId = this.selOutFirm.SelectedValue.ToGuid2();
m_EC_OrderBasicNew.BuyerId = CurrentUser.MemberId;
m_EC_OrderBasicNew.BuyerName = CurrentUser.Name;
m_EC_OrderBasicNew.Creater = this.selBusinessManager.Value;// CurrentUser.ShortName;
m_EC_OrderBasicNew.Operator = CurrentUser.ShortName;
m_EC_OrderBasicNew.DeliveryTime = this.txtDeliveryTime.Value.ToDateTime2();
m_EC_OrderBasicNew.DocumentName = _eC_OrderBasic.DocumentName;
m_EC_OrderBasicNew.OrderTypeId = 2;
m_EC_OrderBasicNew.PrintTypeId = _eC_OrderBasic.PrintTypeId;
m_EC_OrderBasicNew.Remark = this.txtRemark.Value.ToString2();
m_EC_OrderBasicNew.SellerName = m_OA_CorporateClients_Out.OutVendorName;
m_EC_OrderBasicNew.SumPrice = this.txtAllMoney.Value.ToDecimal2();
if (m_OA_CorporateClients_Out.Keyid != m_OA_CorporateClients_Out.FirmId)
{
m_EC_OrderBasicNew.OutId = orderid;
}
else
{
m_EC_OrderBasicNew.OutId = 0;
}
OrderExtend.BusinessManagerId = 0;
OrderExtend.ContactPhone = m_OA_CustomerCommunications_Out.CompanyPhone;
OrderExtend.Contacts = m_OA_CustomerCommunications_Out.BusinessManagers;
OrderExtend.CustomerLevelId = m_OA_CorporateClients_Out.DegreeImportanId ?? 0;
OrderExtend.CustomerManagerId = 0;
OrderExtend.ExigencyCaseId = this.selExigencyDegree.Value.ToInt32();
OrderExtend.FileId = 0;
OrderExtend.InvoiceId = 0;
OrderExtend.Operate = CurrentUser.ShortName;
OrderExtend.PrintNum = _eC_OrderBasic.OrderExtend.SurplusPrintNum;
OrderExtend.ProofreadFileId = 0;
OrderExtend.ProofreadWayId = 0;
OrderExtend.ProofreadState = 0;
OrderExtend.Remark = "";
OrderExtend.SurplusPrintNum = _eC_OrderBasic.OrderExtend.SurplusPrintNum;
EC_AcceptWayByOrder m_EC_AcceptWayByOrder = new EC_AcceptWayByOrder();
PayAbout.FillOrder(m_EC_OrderBasicNew, m_EC_AcceptWayByOrder);
m_EC_OrderBasicNew.OrderExtend = OrderExtend;
EC_OrderOperate m_EC_OrderOperate = new EC_OrderOperate();
m_EC_OrderOperate.LastUpdateTime = DateTime.Now;
m_EC_OrderOperate.OperateType = 3;
m_EC_OrderOperate.Operator = CurrentUser.ShortName;
m_EC_OrderOperate.OrderId = orderid;
m_EC_OrderOperate.Remark = "";
InquiryCommonModel m_InquiryCommonModel = new InquiryCommonModel();
m_InquiryCommonModel.PrintDemand = this.txtPrintDemand.Value;
m_InquiryCommonModel.PrintTypeId = _eC_OrderBasic.PrintTypeId.Value;
m_InquiryCommonModel.PrintTypeName = _eC_OrderBasic.PrintType.PrintName;
m_InquiryCommonModel.AfterWorksDemand = this.txtAfterWorksDemand.Value;
EC_OrderPrintParameter m_EC_OrderPrintParameter = new EC_OrderPrintParameter()//订单印刷参数
{
PrintParameter = SerializationHelper.Serialize(m_InquiryCommonModel)
};
//return bll_EC_OrderBLL.OutOrder(m_EC_OrderBasicNew, m_EC_AcceptWayByOrder, m_EC_OrderPrintParameter, m_EC_OrderOperate, 4, orderIdStr);
bool isWin = false;
isWin = bll_EC_OrderBLL.OutOrder(m_EC_OrderBasicNew, m_EC_AcceptWayByOrder, m_EC_OrderPrintParameter, m_EC_OrderOperate, 4, orderIdStr);
if (!isWin)
{
return false;
}
if (this.cbkIsAllRecovery.Visible == true)
{
if (this.cbkIsAllRecovery.Checked == true)
{
LF_OrderFile lfModel = new LF_OrderFile();
LF_OrderFileBLL lF_OrderFileBLL = new LF_OrderFileBLL();
EC_OrderBasic OrderModel = new EC_OrderBasic();
lfModel = lF_OrderFileBLL.GetModel(Convert.ToInt32(m_EC_OrderBasicNew.Keyid));
if (lfModel == null)
{
return false;
}
if (m_EC_OrderBasicNew.OutId > 0)
{
OrderModel = _eC_OrderBasicBLL.SelectModelById(Convert.ToInt32(_eC_OrderBasic.OutId));
lfModel.OrderId = Convert.ToInt32(_eC_OrderBasic.Keyid);
}
isWin = lF_OrderFileBLL.InserModel(lfModel);
if (!isWin)
{
return false;
}
}
}
if (IsFiles)
{
OA_OrderWorkListRelation OrderWorkListRelationModel = new OA_OrderWorkListRelation();
OrderWorkListRelationModel = bll_EC_OrderBLL.GetModelById(Convert.ToInt32(Request["orderid"]));
if (OrderWorkListRelationModel != null)
{
Keyid = OrderWorkListRelationModel.RelationTargetId.ToString();
}
string script = "";
this.ClientScript.RegisterStartupScript(this.Page.GetType(), "key", script);
}
return true;
}
protected void selOutFirm_SelectedIndexChanged(object sender, EventArgs e)
{
if(selOutFirm.SelectedValue != "")
{
OA_CorporateClients oA_CorporateClientsModel = new OA_CorporateClients();
oA_CorporateClientsModel = bll_OA_CorporateClientsBLL.GetModelByMemberIdAndName(CurrentUser.MemberId, selOutFirm.SelectedItem.Text.ToString());
if (oA_CorporateClientsModel.Keyid != oA_CorporateClientsModel.FirmId)
{
trFile.Visible = true;
LF_OrderFile lfModel = new LF_OrderFile();
LF_OrderFileBLL lF_OrderFileBLL = new LF_OrderFileBLL();
lfModel = lF_OrderFileBLL.GetModel(Convert.ToInt32(Request["orderid"]));
if (lfModel == null)
{
cbkIsAllRecovery.Visible = false;
IsFiles = true;
}
else
{
cbkIsAllRecovery.Visible = true;
IsFiles = false;
}
}
else
{
trFile.Visible = false;
IsFiles = false;
}
}
else
{
trFile.Visible = false;
IsFiles = false;
}
string script = "";
this.ClientScript.RegisterStartupScript(this.Page.GetType(), "key", script);
}
}
}