using BLL; using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; namespace FineUIPro.Web.Customization.ZJ.HSSE.CostGoods { public partial class ExpenseEdit : PageBase { #region 定义项 /// /// 主键 /// private string ExpenseId { get { return (string)ViewState["ExpenseId"]; } set { ViewState["ExpenseId"] = value; } } /// /// 项目主键 /// public string ProjectId { get { return (string)ViewState["ProjectId"]; } set { ViewState["ProjectId"] = value; } } #endregion #region 加载 /// /// 加载页面 /// /// /// protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { this.ProjectId = this.CurrUser.LoginProjectId; this.btnClose.OnClientClick = ActiveWindow.GetHideReference(); this.hdProjectA1.Text = "0"; this.hdProjectA2.Text = "0"; this.hdProjectA3.Text = "0"; this.hdProjectA4.Text = "0"; this.hdProjectA5.Text = "0"; this.hdProjectA6.Text = "0"; this.hdProjectB1.Text = "0"; this.hdProjectB2.Text = "0"; this.hdProjectB3.Text = "0"; this.InitDropDownList(); this.ExpenseId = Request.Params["ExpenseId"]; if (!string.IsNullOrEmpty(this.ExpenseId)) { Model.CostGoods_Expense expense = BLL.ExpenseService.GetExpenseById(this.ExpenseId); if (expense != null) { this.ProjectId = expense.ProjectId; if (this.ProjectId != this.CurrUser.LoginProjectId) { this.InitDropDownList(); } if (expense.Months != null) { //this.txtMonths.Text = string.Format("{0:yyyy-MM}", expense.Months); this.drpYear.SelectedValue = Convert.ToString(expense.Months.Value.Year); this.drpMonths.SelectedValue = Convert.ToString(expense.Months.Value.Month); } this.txtExpenseCode.Text = CodeRecordsService.ReturnCodeByDataId(this.ExpenseId); if (!string.IsNullOrEmpty(expense.UnitId)) { this.drpUnitId.SelectedValue = expense.UnitId; } if (expense.ReportDate != null) { this.txtReportDate.Text = string.Format("{0:yyyy-MM-dd}", expense.ReportDate); } //this.txtCompileMan.Text = expense.CompileMan; //if (expense.CompileDate != null) //{ // this.txtCompileDate.Text = string.Format("{0:yyyy-MM-dd}", expense.CompileDate); //} //this.txtCheckMan.Text = expense.CheckMan; //if (expense.CheckDate != null) //{ // this.txtCheckDate.Text = string.Format("{0:yyyy-MM-dd}", expense.CheckDate); //} //this.txtApproveMan.Text = expense.ApproveMan; //if (expense.ApproveDate != null) //{ // this.txtApproveDate.Text = string.Format("{0:yyyy-MM-dd}", expense.ApproveDate); //} decimal totalA = 0, totalB = 0, totalProjectA = 0, totalProjectB = 0; Model.Base_Project project = BLL.ProjectService.GetProjectByProjectId(this.ProjectId); List projectDetails = BLL.ExpenseDetailService.GetCostDetailsByUnitId(expense.UnitId, project != null ? Convert.ToDateTime(project.StartDate) : Convert.ToDateTime("2000-01-01"), Convert.ToDateTime(expense.Months)); List details = BLL.ExpenseDetailService.GetExpenseDetailsByExpenseId(this.ExpenseId); var a = ((from x in projectDetails where x.CostType == "AB" select x.CostMoney ?? 0)?.Sum()??0).ToString(); hdProjectAB.Text = a; Model.CostGoods_ExpenseDetail ab = details.FirstOrDefault(x => x.CostType == "AB"); if (ab != null) { this.nbAB.Text = (ab.CostMoney ?? 0).ToString(); this.nbProjectAB.Text = ((from x in projectDetails where x.CostType == "AB" select x.CostMoney ?? 0)?.Sum() + ab.CostMoney ?? 0).ToString(); } } } else { this.drpYear.SelectedValue = Convert.ToString(DateTime.Now.Year); this.drpMonths.SelectedValue = Convert.ToString(DateTime.Now.Month); //this.txtMonths.Text = DateTime.Now.ToString("yyyy-MM"); //this.txtCompileMan.Text = this.CurrUser.UserName; this.txtReportDate.Text = string.Format("{0:yyyy-MM-dd}", DateTime.Now); //this.txtCompileDate.Text = string.Format("{0:yyyy-MM-dd}", DateTime.Now); ////自动生成编码 this.txtExpenseCode.Text = BLL.CodeRecordsService.ReturnCodeByMenuIdProjectId(BLL.Const.ProjectExpenseMenuId, this.ProjectId, this.CurrUser.UnitId); } } } #endregion /// /// 初始化下拉框 /// private void InitDropDownList() { BLL.UnitService.InitUnitDropDownList(this.drpUnitId, this.ProjectId, true); BLL.ConstValue.InitConstValueDropDownList(this.drpYear, BLL.ConstValue.Group_0008, true); BLL.ConstValue.InitConstValueDropDownList(this.drpMonths, BLL.ConstValue.Group_0009, true); } #region 保存 /// /// 保存按钮 /// /// /// protected void btnSave_Click(object sender, EventArgs e) { if (this.drpYear.SelectedValue == BLL.Const._Null || this.drpMonths.SelectedValue == BLL.Const._Null) { Alert.ShowInTop("请选择月份", MessageBoxIcon.Warning); return; } this.SaveData(BLL.Const.BtnSave); PageContext.RegisterStartupScript(ActiveWindow.GetHideRefreshReference()); } /// /// 保存数据 /// /// private void SaveData(string type) { Model.CostGoods_Expense expense = new Model.CostGoods_Expense { ProjectId = this.ProjectId }; //if (!string.IsNullOrEmpty(this.txtMonths.Text)) //{ // expense.Months = Funs.GetNewDateTime(this.txtMonths.Text + "-01"); //} if (this.drpYear.SelectedValue != BLL.Const._Null && this.drpMonths.SelectedValue != BLL.Const._Null) { expense.Months = Funs.GetNewDateTime(this.drpYear.SelectedValue + "-" + this.drpMonths.SelectedValue); } expense.ExpenseCode = this.txtExpenseCode.Text.Trim(); if (this.drpUnitId.SelectedValue != BLL.Const._Null) { expense.UnitId = this.drpUnitId.SelectedValue; } expense.ReportDate = Funs.GetNewDateTime(this.txtReportDate.Text.Trim()); //expense.CheckMan = this.txtCheckMan.Text; //expense.CheckDate = Funs.GetNewDateTime(this.txtCheckDate.Text.Trim()); //expense.ApproveMan = this.txtApproveMan.Text; //expense.ApproveDate = Funs.GetNewDateTime(this.txtApproveDate.Text.Trim()); ////单据状态 expense.States = BLL.Const.State_2; if (!string.IsNullOrEmpty(this.ExpenseId)) { expense.CompileDate = DateTime.Now; expense.CompileMan = this.CurrUser.UserName; expense.ExpenseId = this.ExpenseId; BLL.ExpenseService.UpdateExpense(expense); BLL.LogService.AddSys_Log(this.CurrUser, expense.ExpenseCode, expense.ExpenseId, BLL.Const.ProjectExpenseMenuId, BLL.Const.BtnModify); BLL.ExpenseDetailService.DeleteCostDetailByExpenseId(this.ExpenseId); } else { this.ExpenseId = SQLHelper.GetNewID(typeof(Model.CostGoods_Expense)); expense.ExpenseId = this.ExpenseId; expense.CompileMan = this.CurrUser.UserName; expense.CompileDate = DateTime.Now; BLL.ExpenseService.AddExpense(expense); BLL.LogService.AddSys_Log(this.CurrUser, expense.ExpenseCode, expense.ExpenseId, BLL.Const.ProjectExpenseMenuId, BLL.Const.BtnAdd); } //保存费用明细 BLL.ExpenseDetailService.AddCostDetail(expense.ExpenseId, "AB", Funs.GetNewDecimalOrZero(this.nbAB.Text), ""); } #endregion #region 附件上传 /// /// 上传附件 /// /// /// protected void btnAttachUrl_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(this.ExpenseId)) { SaveData(BLL.Const.BtnSave); } PageContext.RegisterStartupScript(WindowAtt.GetShowReference(String.Format("~/AttachFile/webuploader.aspx?toKeyId={0}&path=FileUpload/ExpenseAttachUrl&menuId={1}", ExpenseId, BLL.Const.ProjectExpenseMenuId))); } #endregion #region 输入框变化事件 /// /// 输入框变化事件 /// /// /// protected void nbA1_TextChanged(object sender, EventArgs e) { if (this.drpUnitId.SelectedValue != BLL.Const._Null) { this.nbProjectA1.Text = (Funs.GetNewDecimalOrZero(this.hdProjectA1.Text) + Funs.GetNewDecimalOrZero(this.nbA1.Text)).ToString(); this.nbA.Text = (Funs.GetNewDecimalOrZero(this.nbA1.Text) + Funs.GetNewDecimalOrZero(this.nbA2.Text) + Funs.GetNewDecimalOrZero(this.nbA3.Text) + Funs.GetNewDecimalOrZero(this.nbA4.Text) + Funs.GetNewDecimalOrZero(this.nbA5.Text) + Funs.GetNewDecimalOrZero(this.nbA6.Text)).ToString(); this.nbProjectA.Text = (Funs.GetNewDecimalOrZero(this.nbProjectA1.Text) + Funs.GetNewDecimalOrZero(this.nbProjectA2.Text) + Funs.GetNewDecimalOrZero(this.nbProjectA3.Text) + Funs.GetNewDecimalOrZero(this.nbProjectA4.Text) + Funs.GetNewDecimalOrZero(this.nbProjectA5.Text) + Funs.GetNewDecimalOrZero(this.nbProjectA6.Text)).ToString(); this.nbAB.Text = (Funs.GetNewDecimalOrZero(this.nbA.Text) + Funs.GetNewDecimalOrZero(this.nbB.Text)).ToString(); this.nbProjectAB.Text = (Funs.GetNewDecimalOrZero(this.nbProjectA.Text) + Funs.GetNewDecimalOrZero(this.nbProjectB.Text)).ToString(); } else { this.nbA1.Text = string.Empty; Alert.ShowInTop("请先选择填报单位!", MessageBoxIcon.Warning); return; } } /// /// 输入框变化事件 /// /// /// protected void nbA2_TextChanged(object sender, EventArgs e) { if (this.drpUnitId.SelectedValue != BLL.Const._Null) { this.nbProjectA2.Text = (Funs.GetNewDecimalOrZero(this.hdProjectA2.Text) + Funs.GetNewDecimalOrZero(this.nbA2.Text)).ToString(); this.nbA.Text = (Funs.GetNewDecimalOrZero(this.nbA1.Text) + Funs.GetNewDecimalOrZero(this.nbA2.Text) + Funs.GetNewDecimalOrZero(this.nbA3.Text) + Funs.GetNewDecimalOrZero(this.nbA4.Text) + Funs.GetNewDecimalOrZero(this.nbA5.Text) + Funs.GetNewDecimalOrZero(this.nbA6.Text)).ToString(); this.nbProjectA.Text = (Funs.GetNewDecimalOrZero(this.nbProjectA1.Text) + Funs.GetNewDecimalOrZero(this.nbProjectA2.Text) + Funs.GetNewDecimalOrZero(this.nbProjectA3.Text) + Funs.GetNewDecimalOrZero(this.nbProjectA4.Text) + Funs.GetNewDecimalOrZero(this.nbProjectA5.Text) + Funs.GetNewDecimalOrZero(this.nbProjectA6.Text)).ToString(); this.nbAB.Text = (Funs.GetNewDecimalOrZero(this.nbA.Text) + Funs.GetNewDecimalOrZero(this.nbB.Text)).ToString(); this.nbProjectAB.Text = (Funs.GetNewDecimalOrZero(this.nbProjectA.Text) + Funs.GetNewDecimalOrZero(this.nbProjectB.Text)).ToString(); } else { this.nbA2.Text = string.Empty; Alert.ShowInTop("请先选择填报单位!", MessageBoxIcon.Warning); return; } } /// /// 输入框变化事件 /// /// /// protected void nbA3_TextChanged(object sender, EventArgs e) { if (this.drpUnitId.SelectedValue != BLL.Const._Null) { this.nbProjectA3.Text = (Funs.GetNewDecimalOrZero(this.hdProjectA3.Text) + Funs.GetNewDecimalOrZero(this.nbA3.Text)).ToString(); this.nbA.Text = (Funs.GetNewDecimalOrZero(this.nbA1.Text) + Funs.GetNewDecimalOrZero(this.nbA2.Text) + Funs.GetNewDecimalOrZero(this.nbA3.Text) + Funs.GetNewDecimalOrZero(this.nbA4.Text) + Funs.GetNewDecimalOrZero(this.nbA5.Text) + Funs.GetNewDecimalOrZero(this.nbA6.Text)).ToString(); this.nbProjectA.Text = (Funs.GetNewDecimalOrZero(this.nbProjectA1.Text) + Funs.GetNewDecimalOrZero(this.nbProjectA2.Text) + Funs.GetNewDecimalOrZero(this.nbProjectA3.Text) + Funs.GetNewDecimalOrZero(this.nbProjectA4.Text) + Funs.GetNewDecimalOrZero(this.nbProjectA5.Text) + Funs.GetNewDecimalOrZero(this.nbProjectA6.Text)).ToString(); this.nbAB.Text = (Funs.GetNewDecimalOrZero(this.nbA.Text) + Funs.GetNewDecimalOrZero(this.nbB.Text)).ToString(); this.nbProjectAB.Text = (Funs.GetNewDecimalOrZero(this.nbProjectA.Text) + Funs.GetNewDecimalOrZero(this.nbProjectB.Text)).ToString(); } else { this.nbA3.Text = string.Empty; Alert.ShowInTop("请先选择填报单位!", MessageBoxIcon.Warning); return; } } /// /// 输入框变化事件 /// /// /// protected void nbA4_TextChanged(object sender, EventArgs e) { if (this.drpUnitId.SelectedValue != BLL.Const._Null) { this.nbProjectA4.Text = (Funs.GetNewDecimalOrZero(this.hdProjectA4.Text) + Funs.GetNewDecimalOrZero(this.nbA4.Text)).ToString(); this.nbA.Text = (Funs.GetNewDecimalOrZero(this.nbA1.Text) + Funs.GetNewDecimalOrZero(this.nbA2.Text) + Funs.GetNewDecimalOrZero(this.nbA3.Text) + Funs.GetNewDecimalOrZero(this.nbA4.Text) + Funs.GetNewDecimalOrZero(this.nbA5.Text) + Funs.GetNewDecimalOrZero(this.nbA6.Text)).ToString(); this.nbProjectA.Text = (Funs.GetNewDecimalOrZero(this.nbProjectA1.Text) + Funs.GetNewDecimalOrZero(this.nbProjectA2.Text) + Funs.GetNewDecimalOrZero(this.nbProjectA3.Text) + Funs.GetNewDecimalOrZero(this.nbProjectA4.Text) + Funs.GetNewDecimalOrZero(this.nbProjectA5.Text) + Funs.GetNewDecimalOrZero(this.nbProjectA6.Text)).ToString(); this.nbAB.Text = (Funs.GetNewDecimalOrZero(this.nbA.Text) + Funs.GetNewDecimalOrZero(this.nbB.Text)).ToString(); this.nbProjectAB.Text = (Funs.GetNewDecimalOrZero(this.nbProjectA.Text) + Funs.GetNewDecimalOrZero(this.nbProjectB.Text)).ToString(); } else { this.nbA4.Text = string.Empty; Alert.ShowInTop("请先选择填报单位!", MessageBoxIcon.Warning); return; } } /// /// 输入框变化事件 /// /// /// protected void nbA5_TextChanged(object sender, EventArgs e) { if (this.drpUnitId.SelectedValue != BLL.Const._Null) { this.nbProjectA5.Text = (Funs.GetNewDecimalOrZero(this.hdProjectA5.Text) + Funs.GetNewDecimalOrZero(this.nbA5.Text)).ToString(); this.nbA.Text = (Funs.GetNewDecimalOrZero(this.nbA1.Text) + Funs.GetNewDecimalOrZero(this.nbA2.Text) + Funs.GetNewDecimalOrZero(this.nbA3.Text) + Funs.GetNewDecimalOrZero(this.nbA4.Text) + Funs.GetNewDecimalOrZero(this.nbA5.Text) + Funs.GetNewDecimalOrZero(this.nbA6.Text)).ToString(); this.nbProjectA.Text = (Funs.GetNewDecimalOrZero(this.nbProjectA1.Text) + Funs.GetNewDecimalOrZero(this.nbProjectA2.Text) + Funs.GetNewDecimalOrZero(this.nbProjectA3.Text) + Funs.GetNewDecimalOrZero(this.nbProjectA4.Text) + Funs.GetNewDecimalOrZero(this.nbProjectA5.Text) + Funs.GetNewDecimalOrZero(this.nbProjectA6.Text)).ToString(); this.nbAB.Text = (Funs.GetNewDecimalOrZero(this.nbA.Text) + Funs.GetNewDecimalOrZero(this.nbB.Text)).ToString(); this.nbProjectAB.Text = (Funs.GetNewDecimalOrZero(this.nbProjectA.Text) + Funs.GetNewDecimalOrZero(this.nbProjectB.Text)).ToString(); } else { this.nbA5.Text = string.Empty; Alert.ShowInTop("请先选择填报单位!", MessageBoxIcon.Warning); return; } } /// /// 输入框变化事件 /// /// /// protected void nbA6_TextChanged(object sender, EventArgs e) { if (this.drpUnitId.SelectedValue != BLL.Const._Null) { this.nbProjectA6.Text = (Funs.GetNewDecimalOrZero(this.hdProjectA6.Text) + Funs.GetNewDecimalOrZero(this.nbA6.Text)).ToString(); this.nbA.Text = (Funs.GetNewDecimalOrZero(this.nbA1.Text) + Funs.GetNewDecimalOrZero(this.nbA2.Text) + Funs.GetNewDecimalOrZero(this.nbA3.Text) + Funs.GetNewDecimalOrZero(this.nbA4.Text) + Funs.GetNewDecimalOrZero(this.nbA5.Text) + Funs.GetNewDecimalOrZero(this.nbA6.Text)).ToString(); this.nbProjectA.Text = (Funs.GetNewDecimalOrZero(this.nbProjectA1.Text) + Funs.GetNewDecimalOrZero(this.nbProjectA2.Text) + Funs.GetNewDecimalOrZero(this.nbProjectA3.Text) + Funs.GetNewDecimalOrZero(this.nbProjectA4.Text) + Funs.GetNewDecimalOrZero(this.nbProjectA5.Text) + Funs.GetNewDecimalOrZero(this.nbProjectA6.Text)).ToString(); this.nbAB.Text = (Funs.GetNewDecimalOrZero(this.nbA.Text) + Funs.GetNewDecimalOrZero(this.nbB.Text)).ToString(); this.nbProjectAB.Text = (Funs.GetNewDecimalOrZero(this.nbProjectA.Text) + Funs.GetNewDecimalOrZero(this.nbProjectB.Text)).ToString(); } else { this.nbA6.Text = string.Empty; Alert.ShowInTop("请先选择填报单位!", MessageBoxIcon.Warning); return; } } /// /// 输入框变化事件 /// /// /// protected void nbB1_TextChanged(object sender, EventArgs e) { if (this.drpUnitId.SelectedValue != BLL.Const._Null) { this.nbProjectB1.Text = (Funs.GetNewDecimalOrZero(this.hdProjectB1.Text) + Funs.GetNewDecimalOrZero(this.nbB1.Text)).ToString(); this.nbB.Text = (Funs.GetNewDecimalOrZero(this.nbB1.Text) + Funs.GetNewDecimalOrZero(this.nbB2.Text) + Funs.GetNewDecimalOrZero(this.nbB3.Text)).ToString(); this.nbProjectB.Text = (Funs.GetNewDecimalOrZero(this.nbProjectB1.Text) + Funs.GetNewDecimalOrZero(this.nbProjectB2.Text) + Funs.GetNewDecimalOrZero(this.nbProjectB3.Text)).ToString(); this.nbAB.Text = (Funs.GetNewDecimalOrZero(this.nbA.Text) + Funs.GetNewDecimalOrZero(this.nbB.Text)).ToString(); this.nbProjectAB.Text = (Funs.GetNewDecimalOrZero(this.nbProjectA.Text) + Funs.GetNewDecimalOrZero(this.nbProjectB.Text)).ToString(); } else { this.nbB1.Text = string.Empty; Alert.ShowInTop("请先选择填报单位!", MessageBoxIcon.Warning); return; } } /// /// 输入框变化事件 /// /// /// protected void nbB2_TextChanged(object sender, EventArgs e) { if (this.drpUnitId.SelectedValue != BLL.Const._Null) { this.nbProjectB2.Text = (Funs.GetNewDecimalOrZero(this.hdProjectB2.Text) + Funs.GetNewDecimalOrZero(this.nbB2.Text)).ToString(); this.nbB.Text = (Funs.GetNewDecimalOrZero(this.nbB1.Text) + Funs.GetNewDecimalOrZero(this.nbB2.Text) + Funs.GetNewDecimalOrZero(this.nbB3.Text)).ToString(); this.nbProjectB.Text = (Funs.GetNewDecimalOrZero(this.nbProjectB1.Text) + Funs.GetNewDecimalOrZero(this.nbProjectB2.Text) + Funs.GetNewDecimalOrZero(this.nbProjectB3.Text)).ToString(); this.nbAB.Text = (Funs.GetNewDecimalOrZero(this.nbA.Text) + Funs.GetNewDecimalOrZero(this.nbB.Text)).ToString(); this.nbProjectAB.Text = (Funs.GetNewDecimalOrZero(this.nbProjectA.Text) + Funs.GetNewDecimalOrZero(this.nbProjectB.Text)).ToString(); } else { this.nbB2.Text = string.Empty; Alert.ShowInTop("请先选择填报单位!", MessageBoxIcon.Warning); return; } } /// /// 输入框变化事件 /// /// /// protected void nbB3_TextChanged(object sender, EventArgs e) { if (this.drpUnitId.SelectedValue != BLL.Const._Null) { this.nbProjectB3.Text = (Funs.GetNewDecimalOrZero(this.hdProjectB3.Text) + Funs.GetNewDecimalOrZero(this.nbB3.Text)).ToString(); this.nbB.Text = (Funs.GetNewDecimalOrZero(this.nbB1.Text) + Funs.GetNewDecimalOrZero(this.nbB2.Text) + Funs.GetNewDecimalOrZero(this.nbB3.Text)).ToString(); this.nbProjectB.Text = (Funs.GetNewDecimalOrZero(this.nbProjectB1.Text) + Funs.GetNewDecimalOrZero(this.nbProjectB2.Text) + Funs.GetNewDecimalOrZero(this.nbProjectB3.Text)).ToString(); this.nbAB.Text = (Funs.GetNewDecimalOrZero(this.nbA.Text) + Funs.GetNewDecimalOrZero(this.nbB.Text)).ToString(); this.nbProjectAB.Text = (Funs.GetNewDecimalOrZero(this.nbProjectA.Text) + Funs.GetNewDecimalOrZero(this.nbProjectB.Text)).ToString(); } else { this.nbB3.Text = string.Empty; Alert.ShowInTop("请先选择填报单位!", MessageBoxIcon.Warning); return; } } protected void nbAB_TextChanged(object sender, EventArgs e) { if (this.drpUnitId.SelectedValue != BLL.Const._Null) { this.nbProjectAB.Text = (Funs.GetNewDecimalOrZero(this.hdProjectAB.Text) + Funs.GetNewDecimalOrZero(this.nbAB.Text)).ToString(); } else { this.nbAB.Text = string.Empty; Alert.ShowInTop("请先选择填报单位!", MessageBoxIcon.Warning); return; } } #endregion #region 单位变化事件 /// /// 单位变化事件 /// /// /// protected void drpUnitId_SelectedIndexChanged(object sender, EventArgs e) { if (this.drpUnitId.SelectedValue != BLL.Const._Null) { Model.Base_Project project = BLL.ProjectService.GetProjectByProjectId(this.ProjectId); List projectDetails = BLL.ExpenseDetailService.GetCostDetailsByUnitId(this.drpUnitId.SelectedValue, project != null ? Convert.ToDateTime(project.StartDate) : Convert.ToDateTime("2000-01-01"), Convert.ToDateTime(this.drpYear.SelectedValue + "-" + this.drpMonths.SelectedValue + "-01")); this.nbProjectAB.Text = (from x in projectDetails where x.CostType == "AB" select x.CostMoney ?? 0).Sum().ToString(); this.hdProjectAB.Text = (from x in projectDetails where x.CostType == "AB" select x.CostMoney ?? 0).Sum().ToString(); } else { this.hdProjectAB.Text = "0"; } } #endregion } }