using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data; using System.Data.SqlClient; using BLL; using Newtonsoft.Json.Linq; namespace FineUIPro.Web.JDGL.Check { public partial class QuantityCompletion : PageBase { protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { GetButtonPower(); BindGrid(); } } #region 获取按钮权限 /// /// 获取按钮权限 /// /// /// private void GetButtonPower() { if (Request.Params["value"] == BLL.Const._Null) { return; } var buttonList = BLL.CommonService.GetAllButtonList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, BLL.Const.QuantityCompletionMenuId); if (buttonList.Count() > 0) { if (buttonList.Contains(BLL.Const.BtnSave)) { this.btnMenuModify.Hidden = false; this.btnMenuDel.Hidden = false; } } } #endregion protected void btnMenuModify_Click(object sender, EventArgs e) { if (Grid1.SelectedRowIndexArray.Length == 0) { Alert.ShowInTop("请至少选择一条记录", MessageBoxIcon.Warning); return; } PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("QuantityCompletionEdit.aspx?QuantityCompletionId={0}", Grid1.SelectedRowID, "编辑 - "))); } /// /// 生成对应月份记录 /// private void GetQuantityCompletion() { if (!string.IsNullOrEmpty(this.txtMonths.Text.Trim())) { DateTime months = Convert.ToDateTime(this.txtMonths.Text.Trim() + "-01"); Model.SGGLDB db = Funs.DB; var quantityLists = from x in db.JDGL_QuantityList where x.ProjectId == this.CurrUser.LoginProjectId select x; var quantityCompletions = from x in db.JDGL_QuantityCompletion where x.ProjectId == this.CurrUser.LoginProjectId && x.Months == months select x; foreach (var item in quantityLists) { var quantityCompletion = quantityCompletions.FirstOrDefault(x => x.QuantityListId == item.QuantityListId); if (quantityCompletion == null) { Model.JDGL_QuantityCompletion newQuantityCompletion = new Model.JDGL_QuantityCompletion(); newQuantityCompletion.QuantityCompletionId = SQLHelper.GetNewID(); newQuantityCompletion.ProjectId = this.CurrUser.LoginProjectId; newQuantityCompletion.QuantityListId = item.QuantityListId; newQuantityCompletion.Months = months; db.JDGL_QuantityCompletion.InsertOnSubmit(newQuantityCompletion); db.SubmitChanges(); } } } } /// /// 加载Grid /// private void BindGrid() { //GetQuantityCompletion(); string strSql = @"select * from dbo.View_JDGL_QuantityCompletion qc where qc.ProjectId=@ProjectId order by qc.SortIndex, qc.Name"; List listStr = new List(); listStr.Add(new SqlParameter("@ProjectId", this.CurrUser.LoginProjectId)); SqlParameter[] parameter = listStr.ToArray(); DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter); Grid1.RecordCount = tb.Rows.Count; //tb = GetFilteredTable(Grid1.FilteredData, tb); var table = this.GetPagedDataTable(Grid1, tb); Grid1.DataSource = table; Grid1.DataBind(); } #region 月份选择事件 /// /// 月份选择事件 /// /// /// protected void txtMonths_TextChanged(object sender, EventArgs e) { BindGrid(); } #endregion #region 保存按钮 /// /// 保存按钮 /// /// /// protected void btnSave_Click(object sender, EventArgs e) { if (this.Grid1.Rows.Count > 0) { JArray mergedData = Grid1.GetMergedData(); foreach (JObject mergedRow in mergedData) { JObject values = mergedRow.Value("values"); int i = mergedRow.Value("index"); Model.JDGL_QuantityCompletion quantityCompletion = BLL.QuantityCompletionService.GetQuantityCompletionById(this.Grid1.Rows[i].RowID); if (quantityCompletion != null) { if (!string.IsNullOrEmpty(values.Value("PlanNum"))) { quantityCompletion.PlanNum = Convert.ToDecimal(values.Value("PlanNum")); } if (!string.IsNullOrEmpty(values.Value("RealNum"))) { quantityCompletion.RealNum = Convert.ToDecimal(values.Value("RealNum")); } quantityCompletion.CompileMan = this.CurrUser.UserId; quantityCompletion.CompileDate = DateTime.Now; BLL.QuantityCompletionService.UpdateQuantityCompletion(quantityCompletion); } } Alert.ShowInTop("保存成功!", MessageBoxIcon.Success); } else { Alert.ShowInTop("请至少选择一条记录!", MessageBoxIcon.Warning); return; } } #endregion protected void btnMenuDel_Click(object sender, EventArgs e) { if (Grid1.SelectedRowIndexArray.Length > 0) { foreach (int rowIndex in Grid1.SelectedRowIndexArray) { string rowID = Grid1.DataKeys[rowIndex][1].ToString(); BLL.QuantityCompletionService.DeleteQuantityCompletionById(rowID); } BindGrid(); ShowNotify("删除数据成功!", MessageBoxIcon.Success); } } #region 导入 /// /// 导入按钮 /// /// /// protected void btnImport_Click(object sender, EventArgs e) { PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("QuantityCompletionIn.aspx?ProjectId={0}", this.CurrUser.LoginProjectId, "导入 - "))); } /// /// 关闭导入弹出窗口 /// /// /// protected void Window1_Close(object sender, WindowCloseEventArgs e) { BindGrid(); } #endregion } }