using BLL; using Newtonsoft.Json.Linq; using System; using System.Collections.Generic; using System.Linq; using System.Web.UI.WebControls; namespace FineUIPro.Web.ZHGL.Information { public partial class ActionWorkLedgerAdd : PageBase { #region 定义变量 public string ActionWorkLedgerId { get { return (string)ViewState["ActionWorkLedgerId"]; } set { ViewState["ActionWorkLedgerId"] = value; } } /// /// 定义集合 /// private static List items = new List(); #endregion #region 加载页面 protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { this.GetButtonPower(); items.Clear(); this.ddlUnitId.DataTextField = "UnitName"; this.ddlUnitId.DataValueField = "UnitId"; this.ddlUnitId.DataSource = BLL.UnitService.GetThisUnitDropDownList(); this.ddlUnitId.DataBind(); this.ddlYearId.DataTextField = "ConstText"; ddlYearId.DataValueField = "ConstValue"; ddlYearId.DataSource = BLL.ConstValue.drpConstItemList(ConstValue.Group_0008); ddlYearId.DataBind(); this.ddlQuarter.DataTextField = "ConstText"; ddlQuarter.DataValueField = "ConstValue"; ddlQuarter.DataSource = BLL.ConstValue.drpConstItemList(ConstValue.Group_0011); ddlQuarter.DataBind(); this.ddlUnitId.Readonly = true; string unitId = Request.Params["UnitId"]; string year = Request.QueryString["Year"]; string quarter = Request.QueryString["Quarter"]; this.ActionWorkLedgerId = Request.Params["ActionWorkLedgerId"]; if (!string.IsNullOrEmpty(this.ActionWorkLedgerId)) { items = BLL.ActionWorkLedgerItemService.GetActionWorkLedgerItemList(this.ActionWorkLedgerId); this.Grid1.DataSource = items; this.Grid1.DataBind(); var ActionWorkLedger = BLL.ActionWorkLedgerService.GetActionWorkLedgerById(this.ActionWorkLedgerId); if (ActionWorkLedger != null) { this.btnCopy.Hidden = true; this.btnSave.Hidden = true; this.btnSubmit.Hidden = true; if (ActionWorkLedger.HandleState == BLL.Const.HandleState_4) { this.btnUpdata.Hidden = false; } else { if (ActionWorkLedger.HandleMan == this.CurrUser.UserId) { this.btnSave.Hidden = false; this.btnSubmit.Hidden = false; } } if (ActionWorkLedger.UpState == BLL.Const.UpState_3) //已上报 { this.btnSave.Hidden = true; this.btnUpdata.Hidden = true; } if (!string.IsNullOrEmpty(ActionWorkLedger.UnitId)) { this.ddlUnitId.SelectedValue = ActionWorkLedger.UnitId; } if (ActionWorkLedger.YearId.HasValue) { this.ddlYearId.SelectedValue = ActionWorkLedger.YearId.ToString(); } if (ActionWorkLedger.Quarter.HasValue) { this.ddlQuarter.SelectedValue = ActionWorkLedger.Quarter.ToString(); } if (ActionWorkLedger.ReportDate != null) { this.dpkCompileDate.Text = string.Format("{0:yyyy-MM-dd}", ActionWorkLedger.ReportDate); } } } else { //this.btnCopy.Hidden = false; this.ddlUnitId.SelectedValue = unitId; this.dpkCompileDate.Text = string.Format("{0:yyyy-MM-dd}", DateTime.Now); this.ddlYearId.SelectedValue = year; this.ddlQuarter.SelectedValue = quarter; ////获取项目报告集合 //List projectItems = (from x in Funs.DB.InformationProject_ActionWorkLedger // join y in Funs.DB.InformationProject_ActionWorkLedgerItem // on x.ActionWorkLedgerId equals y.ActionWorkLedgerId // where x.YearId.ToString() == year && x.Quarter.ToString() == quarter && x.States == BLL.Const.State_2 // select y).Distinct().ToList(); //if (projectItems.Count > 0) //{ // int i = 0; // foreach (var projectItem in projectItems) // { // i += 10; // Model.Information_ActionWorkLedgerItem item = new Model.Information_ActionWorkLedgerItem // { // ActionWorkLedgerItemId = SQLHelper.GetNewID(typeof(Model.Information_ActionWorkLedgerItem)), // SortIndex = i // }; // Model.Base_Project project = (from x in Funs.DB.Base_Project // join y in Funs.DB.InformationProject_ActionWorkLedger // on x.ProjectId equals y.ProjectId // join z in Funs.DB.InformationProject_ActionWorkLedgerItem // on y.ActionWorkLedgerId equals z.ActionWorkLedgerId // where z.ActionWorkLedgerItemId == projectItem.ActionWorkLedgerItemId // select x).FirstOrDefault(); // if (project != null) // { // item.IndustryType = project.ProjectName; // } // item.TotalConductCount = projectItem.TotalConductCount; // item.TotalPeopleCount = projectItem.TotalPeopleCount; // item.TotalInvestment = projectItem.TotalInvestment; // item.HQConductCount = projectItem.HQConductCount; // item.HQPeopleCount = projectItem.HQPeopleCount; // item.HQInvestment = projectItem.HQInvestment; // item.BasicConductCount = projectItem.BasicConductCount; // item.BasicPeopleCount = projectItem.BasicPeopleCount; // item.BasicInvestment = projectItem.BasicInvestment; // item.ComprehensivePractice = projectItem.ComprehensivePractice; // item.CPScene = projectItem.CPScene; // item.CPDesktop = projectItem.CPDesktop; // item.SpecialDrill = projectItem.SpecialDrill; // item.SDScene = projectItem.SDScene; // item.SDDesktop = projectItem.SDDesktop; // items.Add(item); // } //} //else //{ // for (int i = 0; i < 100; i++) // { // i += 10; // Model.Information_ActionWorkLedgerItem newItem = new Model.Information_ActionWorkLedgerItem // { // ActionWorkLedgerItemId = SQLHelper.GetNewID(typeof(Model.Information_ActionWorkLedgerItem)), // SortIndex = i // }; // items.Add(newItem); // } //} Grid1.DataSource = items; Grid1.DataBind(); } } } #endregion #region 保存、提交、上报 /// /// 保存按钮 /// /// /// protected void btnSave_Click(object sender, EventArgs e) { Save("add"); } /// /// 上报按钮 /// /// /// protected void btnUpdata_Click(object sender, EventArgs e) { Save("updata"); } /// /// 提交按钮 /// /// /// protected void btnSubmit_Click(object sender, EventArgs e) { Save("submit"); } /// /// 保存数据 /// /// private void Save(string type) { if (this.ddlUnitId.SelectedValue == BLL.Const._Null) { ShowNotify("请选择单位!", MessageBoxIcon.Warning); return; } var drill = BLL.ActionWorkLedgerService.GetActionWorkLedgerByUnitIdDate(this.ddlUnitId.SelectedValue, Funs.GetNewIntOrZero(this.ddlYearId.SelectedValue), Funs.GetNewIntOrZero(this.ddlQuarter.SelectedValue), this.ActionWorkLedgerId); if (drill != null) { ShowNotify("本单位本季度报表已存在,不能重复编制", MessageBoxIcon.Warning); return; } var ActionWorkLedger = new Model.Information_ActionWorkLedger(); if (this.ddlUnitId.SelectedValue != BLL.Const._Null) { ActionWorkLedger.UnitId = this.ddlUnitId.SelectedValue; } if (!string.IsNullOrEmpty(this.dpkCompileDate.Text.Trim())) { ActionWorkLedger.ReportDate = Convert.ToDateTime(this.dpkCompileDate.Text.Trim()); } ActionWorkLedger.YearId = Funs.GetNewIntOrZero(this.ddlYearId.SelectedValue); ActionWorkLedger.Quarter = Funs.GetNewIntOrZero(this.ddlQuarter.SelectedValue); if (string.IsNullOrEmpty(this.ActionWorkLedgerId)) { this.ActionWorkLedgerId = SQLHelper.GetNewID(typeof(Model.Information_ActionWorkLedger)); ActionWorkLedger.ActionWorkLedgerId = this.ActionWorkLedgerId; ActionWorkLedger.CompileMan = this.CurrUser.UserName; ActionWorkLedger.UpState = BLL.Const.UpState_2; ActionWorkLedger.HandleMan = this.CurrUser.UserId; ActionWorkLedger.HandleState = BLL.Const.HandleState_1; BLL.ActionWorkLedgerService.AddActionWorkLedger(ActionWorkLedger); BLL.LogService.AddSys_Log(this.CurrUser, ActionWorkLedger.YearId.ToString() + "-" + ActionWorkLedger.Quarter.ToString(), ActionWorkLedger.ActionWorkLedgerId, BLL.Const.ActionWorkLedgerMenuId, BLL.Const.BtnAdd); } else { Model.Information_ActionWorkLedger oldReport = BLL.ActionWorkLedgerService.GetActionWorkLedgerById(this.ActionWorkLedgerId); if (oldReport != null) { ActionWorkLedger.HandleMan = oldReport.HandleMan; ActionWorkLedger.HandleState = oldReport.HandleState; } ActionWorkLedger.ActionWorkLedgerId = this.ActionWorkLedgerId; ActionWorkLedger.UpState = BLL.Const.UpState_2; BLL.ActionWorkLedgerService.UpdateActionWorkLedger(ActionWorkLedger); BLL.LogService.AddSys_Log(this.CurrUser, ActionWorkLedger.YearId.ToString() + "-" + ActionWorkLedger.Quarter.ToString(), ActionWorkLedger.ActionWorkLedgerId, BLL.Const.ActionWorkLedgerMenuId, BLL.Const.BtnModify); BLL.ActionWorkLedgerItemService.DeleteActionWorkLedgerItemList(ActionWorkLedger.ActionWorkLedgerId); } GetItems(ActionWorkLedger.ActionWorkLedgerId); foreach (var item in items) { BLL.ActionWorkLedgerItemService.AddActionWorkLedgerItem(item); } if (type == "updata") //保存并上报 { if (ActionWorkLedger.UpState == BLL.Const.UpState_2) { string code = CNCECHSSEWebService.UpActionWorkLedger(ActionWorkLedger.ActionWorkLedgerId, this.CurrUser); if (code == "1") { ShowNotify("同步成功!", MessageBoxIcon.Success); PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference()); return; } else { Alert.ShowInParent("同步异常,请退出后重试!", MessageBoxIcon.Error); } } else { ShowNotify("当前单据状态不能同步!", MessageBoxIcon.Warning); return; } } if (type == "submit") { PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("ReportSubmit.aspx?Type=ActionWorkLedger&Id={0}", ActionWorkLedger.ActionWorkLedgerId, "编辑 - "))); } else { PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference()); } } /// /// 获取明细值 /// /// private void GetItems(string ActionWorkLedgerId) { items.Clear(); foreach (JObject mergedRow in Grid1.GetMergedData()) { JObject values = mergedRow.Value("values"); Model.Information_ActionWorkLedgerItem item = new Model.Information_ActionWorkLedgerItem(); if (values["ActionWorkLedgerItemId"].ToString() != "") { item.ActionWorkLedgerItemId = values.Value("ActionWorkLedgerItemId"); } item.ActionWorkLedgerId = ActionWorkLedgerId; item.SortIndex = Funs.GetNewInt(values.Value("SortIndex")); if (values["Focus"].ToString() != "") { item.Focus = values.Value("Focus"); } if (values["SpecialTask"].ToString() != "") { item.SpecialTask = values.Value("SpecialTask"); } if (values["WorkPoints"].ToString() != "") { item.WorkPoints = values.Value("WorkPoints"); } if (values["FillingRequirements"].ToString() != "") { item.FillingRequirements = values.Value("FillingRequirements"); } if (values["CompletionDeadline"].ToString() != "") { item.CompletionDeadline = values.Value("CompletionDeadline"); } if (values["ImplementationStatus"].ToString() != "") { item.ImplementationStatus = values.Value("ImplementationStatus"); } items.Add(item); } } #endregion #region 关闭办理流程窗口 /// /// 关闭办理流程窗口 /// /// /// protected void Window1_Close(object sender, WindowCloseEventArgs e) { Model.Information_ActionWorkLedger report = BLL.ActionWorkLedgerService.GetActionWorkLedgerById(this.ActionWorkLedgerId); if (report.HandleMan == this.CurrUser.UserId) { this.btnSave.Hidden = false; this.btnSubmit.Hidden = false; } else { this.btnSave.Hidden = true; this.btnSubmit.Hidden = true; } } #endregion #region Grid行事件 protected void Grid1_RowCommand(object sender, GridCommandEventArgs e) { string rowID = Grid1.DataKeys[e.RowIndex][0].ToString(); GetItems(string.Empty); if (e.CommandName == "Add") { Model.Information_ActionWorkLedgerItem oldItem = items.FirstOrDefault(x => x.ActionWorkLedgerItemId == rowID); Model.Information_ActionWorkLedgerItem newItem = new Model.Information_ActionWorkLedgerItem { ActionWorkLedgerItemId = SQLHelper.GetNewID(typeof(Model.Information_ActionWorkLedgerItem)) }; if (oldItem != null) { newItem.SortIndex = oldItem.SortIndex + 1; } else { newItem.SortIndex = 0; } items.Add(newItem); items = items.OrderBy(x => x.SortIndex).ToList(); Grid1.DataSource = items; Grid1.DataBind(); } if (e.CommandName == "Delete") { if (Grid1.Rows.Count == 1) { ShowNotify("只有一条数据,无法删除", MessageBoxIcon.Warning); return; } foreach (var item in items) { if (item.ActionWorkLedgerItemId == rowID) { items.Remove(item); break; } } Grid1.DataSource = items; Grid1.DataBind(); ShowNotify("删除数据成功!", MessageBoxIcon.Success); } } #endregion #region 获取按钮权限 /// /// 获取按钮权限 /// /// /// private void GetButtonPower() { var buttonList = BLL.CommonService.GetAllButtonList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, BLL.Const.ActionWorkLedgerMenuId); if (buttonList.Count() > 0) { if (buttonList.Contains(BLL.Const.BtnSave)) { this.btnSave.Hidden = false; this.btnCopy.Hidden = false; } //if (buttonList.Contains(BLL.Const.BtnSaveUp)) //{ // this.btnUpdata.Hidden = false; //} if (buttonList.Contains(BLL.Const.BtnSubmit)) { this.btnSubmit.Hidden = false; } } } #endregion #region 复制上个季度数据 /// /// 复制上个季度的数据 /// /// /// protected void btnCopy_Click(object sender, EventArgs e) { int lastYear = 0, lastQuarter = 0; int year = Convert.ToInt32(this.ddlYearId.SelectedValue); int quarter = Convert.ToInt32(this.ddlQuarter.SelectedValue); if (quarter == 1) { lastYear = year - 1; lastQuarter = 4; } else { lastYear = year; lastQuarter = quarter - 1; } Model.Information_ActionWorkLedger ActionWorkLedger = BLL.ActionWorkLedgerService.GetActionWorkLedgerByUnitIdAndYearAndQuarters(this.ddlUnitId.SelectedValue, lastYear, lastQuarter); if (ActionWorkLedger != null) { Model.Information_ActionWorkLedger newActionWorkLedger = new Model.Information_ActionWorkLedger(); this.ActionWorkLedgerId = SQLHelper.GetNewID(typeof(Model.Information_ActionWorkLedger)); newActionWorkLedger.ActionWorkLedgerId = this.ActionWorkLedgerId; newActionWorkLedger.UnitId = this.ddlUnitId.SelectedValue; newActionWorkLedger.ReportDate = DateTime.Now; newActionWorkLedger.Quarter = Funs.GetNewIntOrZero(this.ddlQuarter.SelectedValue); newActionWorkLedger.YearId = Funs.GetNewIntOrZero(this.ddlYearId.SelectedValue); newActionWorkLedger.CompileMan = this.CurrUser.UserName; newActionWorkLedger.UpState = BLL.Const.UpState_2; newActionWorkLedger.HandleState = BLL.Const.HandleState_1; newActionWorkLedger.HandleMan = this.CurrUser.UserId; BLL.ActionWorkLedgerService.AddActionWorkLedger(newActionWorkLedger); items = BLL.ActionWorkLedgerItemService.GetActionWorkLedgerItemList(ActionWorkLedger.ActionWorkLedgerId); if (items.Count > 0) { foreach (var item in items) { Model.Information_ActionWorkLedgerItem newItem = new Model.Information_ActionWorkLedgerItem { ActionWorkLedgerItemId = SQLHelper.GetNewID(typeof(Model.Information_ActionWorkLedgerItem)), ActionWorkLedgerId = this.ActionWorkLedgerId, SortIndex = item.SortIndex }; BLL.ActionWorkLedgerItemService.AddActionWorkLedgerItem(newItem); } } GetValues(newActionWorkLedger.ActionWorkLedgerId); } } /// /// 获取数据 /// private void GetValues(string ActionWorkLedgerId) { var report = BLL.ActionWorkLedgerService.GetActionWorkLedgerById(ActionWorkLedgerId); if (report != null) { if (!string.IsNullOrEmpty(report.UnitId)) { this.ddlUnitId.SelectedValue = report.UnitId; } if (report.YearId.HasValue) { this.ddlYearId.SelectedValue = report.YearId.ToString(); } if (report.Quarter.HasValue) { this.ddlQuarter.SelectedValue = report.Quarter.ToString(); } if (report.ReportDate != null) { this.dpkCompileDate.Text = string.Format("{0:yyyy-MM-dd}", report.ReportDate); } items = BLL.ActionWorkLedgerItemService.GetActionWorkLedgerItemList(ActionWorkLedgerId); this.Grid1.DataSource = items; this.Grid1.DataBind(); } } #endregion } }