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.Infrastructure.Common; using CY.Model; using CY.BLL.OA; using CY.BLL.Sys; using System.Text; using CY.BLL; using System.Data; namespace CY.WebForm.Pages.financial { //吴辉 //外协预付款 public partial class OutsourcePayMoney : BasePage { private EC_OrderBasicBLL _eC_OrderBasicBLL = null; private EC_OrderBasic _orderBasic = null;//当前订单 private OA_CorporateClientsBLL bll_OA_CorporateClientsBLL = null; OA_FirmAccountBLL _OA_FirmAccountBLL = null; OA_FirmAccountRecordBLL _OA_FirmAccountRecordBLL = null; OA_FirmAccountRecord firmAccountRecord = null; OA_FirmAccount firmAccount = null; string orderNo = string.Empty; /// /// 初始化构造 /// public OutsourcePayMoney() { bll_OA_CorporateClientsBLL = new OA_CorporateClientsBLL(); _OA_FirmAccountBLL = new OA_FirmAccountBLL(); firmAccountRecord = new OA_FirmAccountRecord(); _OA_FirmAccountRecordBLL = new OA_FirmAccountRecordBLL(); } /// /// 界面加载事件 /// /// /// protected void Page_Load(object sender, EventArgs e) { _eC_OrderBasicBLL = new EC_OrderBasicBLL(); btnSubmit.ServerClick += new EventHandler(btnSubmit_ServerClick); try { switch (Request["DataType"]) { case "change": Response.Write(reLoadAccountName(Request["TypeName"].ToString2())); break; default://一般情况不处理 if (IsPostBack || IsCallback) return; else { LoadOrder(); InitialData(); } return; } } catch (Exception ex) { PAGEHandleException(ex); Response.Clear(); Response.Write("-1"); } Response.End(); InitPage(); } protected void InitialData() { //科目名称 Sys_DictionaryBLL _Sys_DictionaryBLL = new Sys_DictionaryBLL(); OA_SubjectSetBLL _OA_SubjectSetBLL = new OA_SubjectSetBLL(); OA_FirmAccountBLL oA_FirmAccountBLL = new OA_FirmAccountBLL(); selSubject.DataSource = _OA_SubjectSetBLL.getAllSubject(CurrentUser.MemberId, "贷"); selSubject.DataBind(); selSubject.Items.Insert(0, new ListItem("请选择", "")); ///账户类型 selAcoountType.DataSource = _Sys_DictionaryBLL.GetDataByType("账户类型"); selAcoountType.DataBind(); //selAcoountType_SelectedIndexChanged(null, null); } protected string reLoadAccountName(string selAcoountType) { return JsonHelper.GetJsonStringByObject(_OA_FirmAccountBLL.getAllSubject(CurrentUser.MemberId, selAcoountType)); } /// /// 提交按钮点击事件 /// /// /// void btnSubmit_ServerClick(object sender, EventArgs e) { //int? orderId = MyConvert.ConvertToInt32(Request["id"]); //string receiveWay = Request["rdoReceiveWay"]; //_orderBasic = _eC_OrderBasicBLL.SelectModelById(orderId.Value); //OA_CorporateClients m_OA_CorporateClients = bll_OA_CorporateClientsBLL.SelectOutsourceByFirmIdandMemberId(_orderBasic.SellerId, CurrentUser.MemberId); //if (receiveWay == "0" && m_OA_CorporateClients != null) //{ // if (this.txtReceiveMoney.Value.ToInt32() > m_OA_CorporateClients.Prepayments) // { // JavaScript.MessageBox("预付款不足!", this, "window.location='/Pages/financial/OutsourcePayMoney.aspx?id=" + orderId + "'"); // //Response.Redirect("/Pages/financial/OrderMoneyReceive.aspx?id=" + orderId); // return; // } //} //if (!orderId.HasValue || 0 >= orderId.Value || string.IsNullOrEmpty(receiveWay)) //{ // JavaScript.MessageBox("传入参数错误!", this); // return; //} //if (null == _orderBasic) //{ // JavaScript.MessageBox("订单不存在或已删除!", this); // return; //} //bool isWin = "0".Equals(receiveWay) ? UsePrepare() : false; //JavaScript.MessageBox(isWin ? "付款成功!" : "付款失败!", this, "top.frmright.ReLoad();top.Dialog.close();"); //Request.RequestContext.RouteData.DataTokens.Add("IsWin", isWin ? "1" : ""); //if (!isWin) // InitPage(); //else // ; int? orderId = MyConvert.ConvertToInt32(Request["id"]); if (!orderId.HasValue || 0 >= orderId.Value) { return; } _orderBasic = new EC_OrderBasic(); _eC_OrderBasicBLL = new EC_OrderBasicBLL(); _orderBasic = _eC_OrderBasicBLL.SelectModelById(orderId.Value); try { firmAccount = _OA_FirmAccountBLL.getSingleSubject(Request["selAccountName"].ToInt32()); if (firmAccount.Balance < this.txtReceiveMoney.Value.ToDecimal2()) { JavaScript.MessageBox("账户余额不足", this); return; } firmAccountRecord.AccountId = Request["selAccountName"].ToInt32(); firmAccountRecord.LastUpdateTime = DateTime.Now; firmAccountRecord.Money = this.txtReceiveMoney.Value.ToDecimal2(); orderNo = _orderBasic.SellerOrderId; firmAccountRecord.OperationalMatters = "外协付款" + "(" + orderNo + ")"; firmAccountRecord.Operator = CurrentUser.ShortName; firmAccountRecord.PaymentUnit = this.spanBuyerName.InnerText; firmAccountRecord.RecordTypeId = 2;//支出 firmAccountRecord.Remark = this.txtRemark.Value; firmAccountRecord.SubjectId = this.selSubject.Value.ToInt32(); firmAccountRecord.ResidualAmount = firmAccount.Balance - this.txtReceiveMoney.Value.ToDecimal2(); firmAccount.AllExpenses = this.txtReceiveMoney.Value.ToDecimal2() + firmAccount.AllExpenses; firmAccount.Balance = firmAccount.Balance - this.txtReceiveMoney.Value.ToDecimal2(); if (_OA_FirmAccountRecordBLL.AddModel(firmAccountRecord, firmAccount)) { UsePrepare(); JavaScript.MessageBox("付款成功", this, "top.frmright.ReLoad();top.Dialog.close();"); } else JavaScript.MessageBox("添加失败", this); } catch (Exception ex) { PAGEHandleException(ex); JavaScript.MessageBox("添加失败", this); } } /// /// 加载页面数据 /// private void InitPage() { try { Sys_DictionaryBLL _Sys_DictionaryBLL = new Sys_DictionaryBLL(); //OA_SubjectSetBLL _OA_SubjectSetBLL = new OA_SubjectSetBLL(); OA_FirmAccountBLL oA_FirmAccountBLL = new OA_FirmAccountBLL(); int i = -1; //账户类型 List accountsType = _Sys_DictionaryBLL.GetDataByType("账户类型") as List; Request.RequestContext.RouteData.DataTokens.Add("accountsTypes", null == accountsType || accountsType.Count == 0 ? "[]" : JsonHelper.GetJsonStringByObject(accountsType)); List firmAccounts = oA_FirmAccountBLL.getAllSubject(CurrentUser.MemberId, "") as List; const string ACCOUNTSJSONKEY = "accounts"; if (null == firmAccounts) { Request.RequestContext.RouteData.DataTokens.Add(ACCOUNTSJSONKEY, "[]"); return; } IEnumerable> groupings = firmAccounts.GroupBy(fa => fa.AccountType); StringBuilder builder = new StringBuilder(); foreach (IGrouping groupitem in groupings) { OA_FirmAccount[] items = groupitem.ToArray(); builder.AppendFormat("{0}\"{2}\":{3}{1}", ",", "", groupitem.Key, JsonHelper.GetJsonStringByObject(items)); } builder.Append("}]"); builder.Replace(",", "[{", 0, 1); Request.RequestContext.RouteData.DataTokens.Add(ACCOUNTSJSONKEY, null == firmAccounts ? "[]" : builder.ToString()); } catch (Exception ex) { PAGEHandleException(ex); } } /// /// 加载订单 /// private void LoadOrder() { int? orderId = MyConvert.ConvertToInt32(Request["id"]); if (!orderId.HasValue || 0 >= orderId.Value) { return; } try { _orderBasic = _eC_OrderBasicBLL.SelectModelById(orderId.Value); OA_CorporateClients m_OA_CorporateClients = bll_OA_CorporateClientsBLL.SelectOutsourceByFirmIdandMemberId(_orderBasic.SellerId, CurrentUser.MemberId); //if (m_OA_CorporateClients != null) //{ // this.nowCustomMoney.InnerHtml = "¥" + (m_OA_CorporateClients.Prepayments ?? 0).ToString("0.00"); //} //else //{ // this.nowCustomMoney.InnerHtml = "¥0"; //} orderNo = _orderBasic.SellerOrderId; this.spanSellerOrderId.InnerText = _orderBasic.SellerOrderId; this.spanDocumentName.InnerText = _orderBasic.DocumentName; this.spanOrderType.InnerText = _orderBasic.OrderType.Name; this.spanOrderStateObjName.InnerText = _orderBasic.OrderStateObj.Name; this.spanBuyerName.InnerText = _orderBasic.SellerName; this.spanOrderExtendPrintNum.InnerText = _orderBasic.OrderExtend.PrintNum.ToString2(); this.spanUnitPrice.InnerText = "¥" + (_orderBasic.UnitPrice ?? 0).ToString("0.00"); this.spanSumPrice.InnerText = "¥" + (_orderBasic.SumPrice ?? 0).ToString("0.00"); this.spanTradingSingleOnlineMoney.InnerText = "¥" + (_orderBasic.TradingSingle.OnlineMoney ?? 0).ToString("0.00"); this.spanTradingSingleLineMoney.InnerText = "¥" + (_orderBasic.TradingSingle.LineMoney ?? 0).ToString("0.00"); this.spanUnPayedMoney.InnerText = "¥" + (_orderBasic.UnPayedMoney).ToString("0.00"); this.txtUnPayedMoney.Value = (_orderBasic.UnPayedMoney).ToString("0.00"); } catch (Exception ex) { PAGEHandleException(ex); JavaScript.MessageBox("订单不存在!", this); } } /// /// 使用预付款(付款、收款) /// /// private bool UsePrepare() { decimal? money = MyConvert.ConvertToDecimal(txtReceiveMoney.Value); int operatTypeId = 3; string subject = "订单付款"; switch (Request["outsourceType"]) { case "1": operatTypeId = 2; subject = "外协付款"; break; default: break; } return _eC_OrderBasicBLL.ReceiveMoney(_orderBasic.SellerId, _orderBasic.BuyerId, _orderBasic.Keyid.Value, money.Value, operatTypeId, subject, CurrentUser.ShortName); } //protected void selAcoountType_SelectedIndexChanged(object sender, EventArgs e) //{ // _OA_FirmAccountBLL = new OA_FirmAccountBLL(); // DataTable dt = _OA_FirmAccountBLL.getAllAountName(CurrentUser.MemberId, selAcoountType.SelectedItem.Text.ToString()); //} } }