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; using System.Transactions; namespace CY.WebForm.Pages.financial { //吴辉 //外协预付款 public partial class BaozhengjinIncome : BasePage { private EC_OrderBasicBLL _eC_OrderBasicBLL = 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; OA_BaozhengjinBLL oA_BaozhengjinBLL = null; string orderNo = string.Empty; decimal? AllMoney = 0; decimal? ReceiveMoney = 0; /// /// 初始化构造 /// public BaozhengjinIncome() { bll_OA_CorporateClientsBLL = new OA_CorporateClientsBLL(); _OA_FirmAccountBLL = new OA_FirmAccountBLL(); firmAccountRecord = new OA_FirmAccountRecord(); _OA_FirmAccountRecordBLL = new OA_FirmAccountRecordBLL(); oA_BaozhengjinBLL = new OA_BaozhengjinBLL(); } /// /// 界面加载事件 /// /// /// 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) { //_orderBasic = new EC_OrderBasic(); _eC_OrderBasicBLL = new EC_OrderBasicBLL(); //_orderBasic = _eC_OrderBasicBLL.SelectModelById(orderId.Value); //string orderno = ""; //string sellerName = ""; if(string.IsNullOrEmpty(Request["selAccountName"])) { JavaScript.MessageBox("请选择账户", this); return; } firmAccount = _OA_FirmAccountBLL.getSingleSubject(Request["selAccountName"].ToInt32()); var ssss = false; var id = this.Keyid.Value.ToInt32().Value; var fukuanshenqing = oA_BaozhengjinBLL.GetModelByKeyid(id); if (fukuanshenqing.TuikuanStatus == 2 ) { JavaScript.MessageBox("已经退款,无法重复退款!", this); return; } using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required, new TransactionOptions { IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted, Timeout = TransactionManager.MaximumTimeout } )) { try { fukuanshenqing.TuikuanStatus = 2; fukuanshenqing.TuikuanTime = DateTime.Now; fukuanshenqing.Updater = CurrentUser.ShortName; fukuanshenqing.LastUpdateTime = DateTime.Now; ssss = oA_BaozhengjinBLL.UpdateModel(fukuanshenqing); if(this.txtMoney.Text.ToDecimal2() > 0) { firmAccount = _OA_FirmAccountBLL.getSingleSubject(Request["selAccountName"].ToInt32()); OA_FirmAccountRecord firmAccountRecord = new OA_FirmAccountRecord() ; firmAccountRecord.AccountId = Request["selAccountName"].ToInt32(); firmAccountRecord.LastUpdateTime = DateTime.Now; firmAccountRecord.Money = txtMoney.Text.ToDecimal2(); firmAccountRecord.OperationalMatters = txtOperationalMatters.Value; firmAccountRecord.Operator = CurrentUser.ShortName; firmAccountRecord.PaymentUnit = txtPaymentUnit.Text; firmAccountRecord.RecordTypeId = 1;//收入 firmAccountRecord.Remark = ""; firmAccountRecord.SubjectId = selSubject.Value.ToInt32(); firmAccountRecord.ResidualAmount = firmAccount.Balance + txtMoney.Text.ToDecimal2(); firmAccountRecord.Department = ""; firmAccount.AllIncome = txtMoney.Text.ToDecimal2() + firmAccount.AllIncome; firmAccount.Balance = firmAccount.Balance + txtMoney.Text.ToDecimal2(); ssss = _OA_FirmAccountRecordBLL.AddModel(firmAccountRecord, firmAccount); } if (ssss) { scope.Complete(); JavaScript.MessageBox("付款成功", this, "top.frmright.ReLoad();top.Dialog.close();"); } else JavaScript.MessageBox("添加失败", this); } catch (Exception ex) { PAGEHandleException(ex); JavaScript.MessageBox("添加失败", this); } finally { scope.Dispose(); } } } /// /// 加载页面数据 /// 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() { var id = Request["id"]; var fukuanshenqing = oA_BaozhengjinBLL.GetModelByKeyid(id.ToInt32().Value); if (fukuanshenqing != null) { this.Keyid.Value = id; this.txtMoney.Text = fukuanshenqing.Fukuanmoney.Value.ToString("0.00"); this.txtPaymentUnit.Text = fukuanshenqing.Shoukuandanwei; this.txtOperationalMatters.Value = fukuanshenqing.remark; } } } }