SGGL_SHJ/SGGL/FineUIPro.Web/CQMS/Models/QualityModelEdit.aspx.cs

219 lines
8.7 KiB
C#

using BLL;
using System;
using System.Data;
using System.Web;
namespace FineUIPro.Web.CQMS.Models
{
public partial class QualityModelEdit : PageBase
{
#region
/// <summary>
/// 页面加载
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
string id = Request.Params["QualityModelId"];
string year = DateTime.Now.Year.ToString();
if (!string.IsNullOrEmpty(Request.Params["type"]))
{
this.btnSave.Hidden = true;
}
CompanyModelKindService.InitCompanyModelKindDownList(this.drpCompanyModelKindId, true);
this.drpCompanyModelKindId.SelectedValue = BLL.Const._Null;
//CompanyModelService.InitModelTypeDownList(this.drpModelType, true);
Funs.FineUIPleaseSelect(this.drpModelType);
if (!string.IsNullOrEmpty(id))
{
Model.Model_QualityModel QualityModel = BLL.QualityModelService.GetQualityModelById(id);
if (QualityModel != null)
{
this.hdId.Text = id;
Model.Base_CompanyModel companyModel = BLL.CompanyModelService.GetCompanyModelById(QualityModel.CompanyModelId);
if (!string.IsNullOrEmpty(companyModel.CompanyModelKindId))
{
this.drpCompanyModelKindId.SelectedValue = companyModel.CompanyModelKindId;
this.drpModelType.Items.Clear();
CompanyModelService.InitModelTypeDownList(this.drpModelType, this.drpCompanyModelKindId.SelectedValue, true);
}
if (!string.IsNullOrEmpty(QualityModel.CompanyModelId))
{
this.drpModelType.SelectedValue = QualityModel.CompanyModelId;
}
if (!string.IsNullOrEmpty(QualityModel.Evaluate))
{
this.rblEvaluate.SelectedValue = QualityModel.Evaluate;
}
this.txtRemark.Text = QualityModel.Remark;
BindCGrid();
BindGrid();
}
}
}
}
#endregion
#region
/// <summary>
/// 附件上传
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnAttach_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(this.hdId.Text)) //新增记录
{
this.hdId.Text = SQLHelper.GetNewID(typeof(Model.Model_QualityModel));
}
if (!string.IsNullOrEmpty(Request.Params["type"]))
{
PageContext.RegisterStartupScript(WindowAtt.GetShowReference(String.Format("~/AttachFile/webuploader.aspx?type=-1&toKeyId={0}&path=FileUpload/CQMS/Models&menuId={1}", this.hdId.Text, BLL.Const.QualityModelMenuId)));
}
else
{
PageContext.RegisterStartupScript(WindowAtt.GetShowReference(String.Format("~/AttachFile/webuploader.aspx?type=0&toKeyId={0}&path=FileUpload/CQMS/Models&menuId={1}", this.hdId.Text, BLL.Const.QualityModelMenuId)));
}
}
#endregion
#region
/// <summary>
/// 保存按钮
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnSave_Click(object sender, EventArgs e)
{
if (this.drpCompanyModelKindId.SelectedValue == BLL.Const._Null)
{
ShowNotify("请选择样板类别!", MessageBoxIcon.Warning);
return;
}
if (this.drpModelType.SelectedValue == BLL.Const._Null)
{
ShowNotify("请选择样板类型!", MessageBoxIcon.Warning);
return;
}
if (this.rblEvaluate.SelectedValue == BLL.Const._Null)
{
ShowNotify("请选择项目实物评价!", MessageBoxIcon.Warning);
return;
}
string id = Request.Params["QualityModelId"];
Model.Model_QualityModel newQualityModel = new Model.Model_QualityModel();
newQualityModel.ProjectId = this.CurrUser.LoginProjectId;
newQualityModel.CompanyModelId = this.drpModelType.SelectedValue;
newQualityModel.Evaluate = this.rblEvaluate.SelectedValue;
newQualityModel.Remark = this.txtRemark.Text.Trim();
if (!string.IsNullOrEmpty(id))
{
newQualityModel.QualityModelId = id;
BLL.QualityModelService.UpdateQualityModel(newQualityModel);
}
else
{
if (!string.IsNullOrEmpty(this.hdId.Text))
{
newQualityModel.QualityModelId = this.hdId.Text.Trim();
}
else
{
newQualityModel.QualityModelId = SQLHelper.GetNewID(typeof(Model.Model_QualityModel));
this.hdId.Text = newQualityModel.QualityModelId;
}
newQualityModel.CompileMan = this.CurrUser.PersonId;
newQualityModel.CompileDate = DateTime.Now;
BLL.QualityModelService.AddQualityModel(newQualityModel);
}
ShowNotify("保存成功!", MessageBoxIcon.Success);
PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference());
}
#endregion
#region
/// <summary>
/// 关闭弹出窗口
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void WindowAtt_Close(object sender, WindowCloseEventArgs e)
{
BindGrid();
}
/// <summary>
/// 数据绑定
/// </summary>
public void BindGrid()
{
string strSql = @"select * from AttachFile where ToKeyId='" + this.hdId.Text + "'";
DataTable tb = SQLHelper.GetDataTableRunText(strSql, null);
Grid1.RecordCount = tb.Rows.Count;
var table = this.GetPagedDataTable(Grid1, tb);
Grid1.DataSource = table;
Grid1.DataBind();
}
/// <summary>
/// 数据绑定
/// </summary>
public void BindCGrid()
{
if (this.drpModelType.SelectedValue != BLL.Const._Null && this.drpCompanyModelKindId.SelectedValue != BLL.Const._Null)
{
string strSql = @"select * from AttachFile where ToKeyId='" + this.drpModelType.SelectedValue + "'";
DataTable tb = SQLHelper.GetDataTableRunText(strSql, null);
GridC.RecordCount = tb.Rows.Count;
var table = this.GetPagedDataTable(GridC, tb);
GridC.DataSource = table;
GridC.DataBind();
}
else
{
GridC.DataSource = null;
GridC.DataBind();
}
}
/// <summary>
/// 获取图片(放于Img中)
/// </summary>
/// <param name="registrationId"></param>
/// <returns></returns>
protected string ConvertImageUrlByImage(object CompanyModelId)
{
string url = string.Empty;
if (CompanyModelId != null)
{
var attachFile = BLL.AttachFileService.GetAttachFileByToKeyId(CompanyModelId.ToString());
if (attachFile != null)
{
url = HttpUtility.HtmlDecode(BLL.UploadAttachmentService.ShowImage("../../", attachFile.AttachUrl));
}
}
return url;
}
#endregion
protected void drpModelType_SelectedIndexChanged(object sender, EventArgs e)
{
BindCGrid();
}
protected void drpCompanyModelKindId_SelectedIndexChanged(object sender, EventArgs e)
{
this.drpModelType.Items.Clear();
if (this.drpCompanyModelKindId.SelectedValue != BLL.Const._Null)
{
CompanyModelService.InitModelTypeDownList(this.drpModelType, this.drpCompanyModelKindId.SelectedValue, false);
}
Funs.FineUIPleaseSelect(this.drpModelType);
this.drpModelType.SelectedValue = BLL.Const._Null;
BindCGrid();
}
}
}