using BLL; using System; namespace FineUIPro.Web.ProjectData { public partial class ProjectUnitSave : PageBase { #region 定义项 /// /// 定义项 /// public string ProjectUnitId { get { return (string)ViewState["ProjectUnitId"]; } set { ViewState["ProjectUnitId"] = value; } } public string ProjectId { get { return (string)ViewState["ProjectId"]; } set { ViewState["ProjectId"] = value; } } public string UnitId { get { return (string)ViewState["UnitId"]; } set { ViewState["UnitId"] = value; } } #endregion /// /// 加载页面 /// /// /// protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { this.btnClose.OnClientClick = ActiveWindow.GetHideReference(); BLL.ConstValue.InitConstValueDropDownList(this.drpUnitType, ConstValue.Group_ProjectUnitType, true); BasicDataService.InitBasicDataProjectUnitDropDownList(this.drpIdcardType, "ZHENGJIAN_TYPE", true); this.drpIdcardType.SelectedValue = "SHENFEN_ZHENGJIAN"; this.ckIsSynchro.Checked = false; this.ProjectUnitId = Request.QueryString["ProjectUnitId"]; if (!String.IsNullOrEmpty(this.ProjectUnitId)) { var projectUnit = BLL.ProjectUnitService.GetProjectUnitById(this.ProjectUnitId); if (projectUnit != null) { var project = BLL.ProjectService.GetProjectByProjectId(projectUnit.ProjectId); if (project != null) { this.ProjectId = projectUnit.ProjectId; this.lbProjectName.Text = project.ProjectName; } var unit = BLL.UnitService.GetUnitByUnitId(projectUnit.UnitId); if (unit != null) { this.UnitId = projectUnit.UnitId; this.lbUnitName.Text = unit.UnitName; this.txtCollCropCode.Text = unit.CollCropCode; this.txtLinkName.Text = unit.LinkName; if (!string.IsNullOrEmpty(unit.IdcardType)) { this.drpIdcardType.SelectedValue = unit.IdcardType; } this.txtIdcardNumber.Text = unit.IdcardNumber; this.txtLinkMobile.Text = unit.LinkMobile; if (!string.IsNullOrEmpty(unit.IsChina)) { this.rblIsChina.SelectedValue = unit.IsChina; } if (!string.IsNullOrEmpty(unit.CollCropStatus)) { this.rblCollCropStatus.SelectedValue = unit.CollCropStatus; } } this.txtInTime.Text = string.Format("{0:yyyy-MM-dd}", projectUnit.InTime); this.txtOutTime.Text = string.Format("{0:yyyy-MM-dd}", projectUnit.OutTime); if (!string.IsNullOrEmpty(projectUnit.UnitType)) { this.drpUnitType.SelectedValue = projectUnit.UnitType; } if (projectUnit.PlanCostA.HasValue) { this.nbPlanCostA.Text = projectUnit.PlanCostA.ToString(); } if (projectUnit.PlanCostB.HasValue) { this.nbPlanCostB.Text = projectUnit.PlanCostB.ToString(); } this.txtContractRange.Text = projectUnit.ContractRange; if (projectUnit.IsSynchro == true) { this.ckIsSynchro.Checked = true; } if (projectUnit.IsOutSideUnit == true) { this.ckIsOutSideUnit.Checked = true; } } this.BindGrid(); } } } /// /// 保存数据 /// /// /// protected void btnSave_Click(object sender, EventArgs e) { var newProjectUnit = BLL.ProjectUnitService.GetProjectUnitById(this.ProjectUnitId); if (newProjectUnit != null) { newProjectUnit.InTime = Funs.GetNewDateTime(this.txtInTime.Text.Trim()); newProjectUnit.OutTime = Funs.GetNewDateTime(this.txtOutTime.Text.Trim()); if (this.drpUnitType.SelectedValue != BLL.Const._Null) { newProjectUnit.UnitType = this.drpUnitType.SelectedValue; } newProjectUnit.PlanCostA = Funs.GetNewDecimalOrZero(this.nbPlanCostA.Text.Trim()); newProjectUnit.PlanCostB = Funs.GetNewDecimalOrZero(this.nbPlanCostB.Text.Trim()); newProjectUnit.ContractRange = this.txtContractRange.Text.Trim(); if (this.ckIsSynchro.Checked) { newProjectUnit.IsSynchro = true; } else { newProjectUnit.IsSynchro = false; } if (this.ckIsOutSideUnit.Checked) { newProjectUnit.IsOutSideUnit = true; } else { newProjectUnit.IsOutSideUnit = null; } BLL.ProjectUnitService.UpdateProjectUnit(newProjectUnit); Model.Base_Unit unit = BLL.UnitService.GetUnitByUnitId(newProjectUnit.UnitId); if (unit != null) { unit.IsChina = this.rblIsChina.SelectedValue; unit.CollCropCode = this.txtCollCropCode.Text.Trim(); unit.LinkName = this.txtLinkName.Text.Trim(); if (this.drpIdcardType.SelectedValue != BLL.Const._Null) { unit.IdcardType = this.drpIdcardType.SelectedValue; } unit.IdcardNumber = this.txtIdcardNumber.Text.Trim(); unit.LinkMobile = this.txtLinkMobile.Text.Trim(); unit.CollCropStatus = this.rblCollCropStatus.SelectedValue; BLL.UnitService.UpdateUnit(unit); } BLL.LogService.AddSys_Log(this.CurrUser, null, newProjectUnit.ProjectUnitId, BLL.Const.ProjectUnitMenuId, BLL.Const.BtnModify); ShowNotify("保存数据成功!", MessageBoxIcon.Success); // 2. 关闭本窗体,然后回发父窗体 PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference()); } } /// /// /// private void BindGrid() { this.Grid1.DataSource = ProjectUnitService.GetProjectUnitItemList(this.ProjectId, this.UnitId); this.Grid1.PageIndex = 0; this.Grid1.DataBind(); } protected void btnMenuEdit_Click(object sender, EventArgs e) { this.EditData(); } protected void Grid1_RowDoubleClick(object sender, GridRowClickEventArgs e) { this.EditData(); } private void EditData() { if (Grid1.SelectedRowIndexArray.Length == 0) { Alert.ShowInParent("请至少选择一条记录!", MessageBoxIcon.Warning); return; } reSetTable(true); var trainTypeItem = ProjectUnitService.GetProjectUnitItemById(Grid1.SelectedRowID); if (trainTypeItem != null) { this.txtContractNum.Text = trainTypeItem.ContractNum.ToString(); this.txtTotalMoney.Text = trainTypeItem.TotalMoney.ToString(); this.txtHSEMoney.Text = trainTypeItem.HSEMoney.ToString(); this.hdProjectUnitItemId.Text = trainTypeItem.ProjectUnitItemId; } this.BindGrid(); } protected void btnMenuDelete_Click(object sender, EventArgs e) { if (Grid1.SelectedRowIndexArray.Length > 0) { foreach (int rowIndex in Grid1.SelectedRowIndexArray) { string rowID = Grid1.DataKeys[rowIndex][0].ToString(); BLL.ProjectUnitService.DeleteProjectUnitItemById(rowID); } } this.BindGrid(); this.reSetTable(false); this.ShowNotify("删除数据成功!", MessageBoxIcon.Success); } protected void btnAdd_Click(object sender, EventArgs e) { reSetTable(true); } protected void btnItemSave_Click(object sender, EventArgs e) { if (!string.IsNullOrEmpty(this.ProjectId) && !string.IsNullOrEmpty(this.UnitId)) { Model.Project_ProjectUnitItem newItem = new Model.Project_ProjectUnitItem() { ProjectId = this.ProjectId, UnitId = this.UnitId, ContractNum = this.txtContractNum.Text.Trim(), TotalMoney = Funs.GetNewDecimalOrZero(this.txtTotalMoney.Text.Trim()), HSEMoney = Funs.GetNewDecimalOrZero(this.txtHSEMoney.Text.Trim()), }; var getItem = ProjectUnitService.GetProjectUnitItemById(this.hdProjectUnitItemId.Text); if (getItem != null) { newItem.ProjectUnitItemId = getItem.ProjectUnitItemId; ProjectUnitService.UpdateProjectUnitItem(newItem); } else { newItem.CompileDate = DateTime.Now; newItem.CompileManId = this.CurrUser.PersonId; ProjectUnitService.AddProjectUnitItem(newItem); } reSetTable(false); this.ShowNotify("保存成功!", MessageBoxIcon.Success); this.BindGrid(); } else { this.ShowNotify("请重新选择单位!", MessageBoxIcon.Warning); return; } } /// /// 重置 /// private void reSetTable(bool isShow) { this.txtContractNum.Focus(); this.tr0.Hidden = !isShow; this.txtContractNum.Text = string.Empty; this.txtTotalMoney.Text = string.Empty; this.txtHSEMoney.Text = string.Empty; this.hdProjectUnitItemId.Text = string.Empty; } } }