using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using CY.Model; using CY.Infrastructure.Common; using CY.BLL.OA; using CY.BLL.Sys; using CY.BLL; using System.Transactions; namespace CY.WebForm.Pages.financial { public partial class WaixieExpenses : BasePage { Sys_DictionaryBLL _Sys_DictionaryBLL = null; OA_SubjectSetBLL _OA_SubjectSetBLL = null; OA_FirmAccountBLL _OA_FirmAccountBLL = null; OA_FirmAccountRecordBLL _OA_FirmAccountRecordBLL = null; OA_FirmAccountRecord firmAccountRecord = null; OA_FirmAccount firmAccount = null; OA_FukuanshenqingBLL _fukuanshenqingBLL = null; OA_SuppliersBLL oA_SuppliersBLL = null; public WaixieExpenses() { firmAccount = new OA_FirmAccount(); _Sys_DictionaryBLL = new Sys_DictionaryBLL(); _OA_FirmAccountBLL = new OA_FirmAccountBLL(); _OA_FirmAccountRecordBLL = new OA_FirmAccountRecordBLL(); _OA_SubjectSetBLL = new OA_SubjectSetBLL(); firmAccountRecord = new OA_FirmAccountRecord(); _fukuanshenqingBLL = new OA_FukuanshenqingBLL(); oA_SuppliersBLL = new OA_SuppliersBLL(); } protected void Page_Load(object sender, EventArgs e) { try { switch (Request["DataType"]) { case "change": Response.Write(reLoadAccountName(Request["TypeName"].ToString2())); break; default://一般情况不处理 if (IsPostBack || IsCallback) return; else { InitialData(); } return; } } catch (Exception ex) { PAGEHandleException(ex); Response.Clear(); Response.Write("-1"); } Response.End(); } protected void InitialData() { //科目名称 selSubject.DataSource = _OA_SubjectSetBLL.getAllSubject(CurrentUser.MemberId, "贷"); selSubject.DataBind(); selSubject.Items.Insert(0, new ListItem("请选择", "")); ///账户类型 selAcoountType.DataSource = _Sys_DictionaryBLL.GetDataByType("账户类型"); selAcoountType.DataBind(); var id = Request["id"]; var fukuanshenqing = _fukuanshenqingBLL.GetModelByKeyid(id.ToInt32().Value); if (fukuanshenqing != null) { if (!string.IsNullOrWhiteSpace(fukuanshenqing.Huming)) { this.txtPaymentUnit.Value = fukuanshenqing.Huming; } else { this.txtPaymentUnit.Value = fukuanshenqing.SupplierName; this.txtSupplierId.Value = fukuanshenqing.SupplierId.ToString(); } this.Keyid.Value = id; this.txtYouwufapiao.Value = fukuanshenqing.YouwufapiaoName; this.txtFukuanmoney.Value = String.Format("{0:F2}", fukuanshenqing.Fukuanmoney); this.txtYishoumoney.Value = String.Format("{0:F2}", fukuanshenqing.Yishoumoney); this.txtMoney.Value = String.Format("{0:F2}", (fukuanshenqing.Fukuanmoney - fukuanshenqing.Yishoumoney)); } } protected string reLoadAccountName(string selAcoountType) { return JsonHelper.GetJsonStringByObject(_OA_FirmAccountBLL.getAllSubject(CurrentUser.MemberId, selAcoountType)); } protected void btn_Submit_Click(object sender, EventArgs e) { var id = this.Keyid.Value.ToInt32().Value; var money = this.txtMoney.Value.ToDecimal2().Value; var Youwufapiao = Request["rdoReceiveQuannbu"]; var fukuanshenqing = _fukuanshenqingBLL.GetModelByKeyid(id); if (fukuanshenqing.FukuanStatus == 2 && money>0) { JavaScript.MessageBox("该申请已经付款结束!", this); return; } if (money>(fukuanshenqing.Fukuanmoney - fukuanshenqing.Yishoumoney)) { JavaScript.MessageBox("操作金额大于剩余应付金额!", this); return; } if (fukuanshenqing.Youwufapiao == 2 && Youwufapiao == "1") { JavaScript.MessageBox("已经保存为有发票,无法修改为无发票!", this); return; } using (var scope = new TransactionScope(TransactionScopeOption.Required, new TransactionOptions { IsolationLevel = IsolationLevel.ReadCommitted, Timeout = TransactionManager.MaximumTimeout } )) { try { var yishoumoney = fukuanshenqing.Yishoumoney.HasValue ? fukuanshenqing.Yishoumoney.Value : 0; if (money >= (fukuanshenqing.Fukuanmoney - fukuanshenqing.Yishoumoney)) { fukuanshenqing.FukuanStatus = 2; } fukuanshenqing.Yishoumoney = yishoumoney + money; fukuanshenqing.Updater = CurrentUser.ShortName; fukuanshenqing.LastUpdateTime = DateTime.Now; fukuanshenqing.Youwufapiao = Youwufapiao.ToInt32(); var sddd = _fukuanshenqingBLL.UpdateModel(fukuanshenqing); if (money > 0) { firmAccount = _OA_FirmAccountBLL.getSingleSubject(Request["selAccountName"].ToInt32()); firmAccountRecord.AccountId = Request["selAccountName"].ToInt32(); firmAccountRecord.LastUpdateTime = DateTime.Now; firmAccountRecord.Money = this.txtMoney.Value.ToDecimal2(); firmAccountRecord.OperationalMatters = this.txtOperationalMatters.Value; firmAccountRecord.Operator = CurrentUser.ShortName; firmAccountRecord.PaymentUnit = this.txtPaymentUnit.Value; firmAccountRecord.RecordTypeId = 2;//支出 firmAccountRecord.Remark = this.txtRemark.Value; firmAccountRecord.SubjectId = this.selSubject.Value.ToInt32(); firmAccountRecord.ResidualAmount = firmAccount.Balance - this.txtMoney.Value.ToDecimal2(); firmAccountRecord.Department = this.txtDepartment.Value; firmAccount.AllExpenses = this.txtMoney.Value.ToDecimal2() + firmAccount.AllExpenses; firmAccount.Balance = firmAccount.Balance - this.txtMoney.Value.ToDecimal2(); sddd = _OA_FirmAccountRecordBLL.AddModel(firmAccountRecord, firmAccount); } if (sddd) { scope.Complete(); JavaScript.MessageBox("付款成功", this, true, true); } else JavaScript.MessageBox("付款失败", this); } catch (Exception ex) { PAGEHandleException(ex); JavaScript.MessageBox("付款失败", this); } finally { // 释放资源 scope.Dispose(); } } } } }