SGGL_SHJ/SGGL/FineUIPro.Web/BaseInfo/CompanyModelEdit.aspx.cs

171 lines
6.7 KiB
C#

using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BLL;
namespace FineUIPro.Web.BaseInfo
{
public partial class CompanyModelEdit : 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["CompanyModelId"];
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;
if (!string.IsNullOrEmpty(id))
{
Model.Base_CompanyModel CompanyModel = BLL.CompanyModelService.GetCompanyModelById(id);
if (CompanyModel != null)
{
this.hdId.Text = id;
if (!string.IsNullOrEmpty(CompanyModel.CompanyModelKindId))
{
this.drpCompanyModelKindId.SelectedValue = CompanyModel.CompanyModelKindId;
}
this.txtModelType.Text = CompanyModel.ModelType;
this.txtRemark.Text = CompanyModel.Remark;
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.Base_CompanyModel));
}
if (!string.IsNullOrEmpty(Request.Params["type"]))
{
PageContext.RegisterStartupScript(WindowAtt.GetShowReference(String.Format("~/AttachFile/webuploader.aspx?type=-1&toKeyId={0}&path=FileUpload/Base/CompanyModel&menuId={1}", this.hdId.Text, BLL.Const.CompanyModelMenuId)));
}
else
{
PageContext.RegisterStartupScript(WindowAtt.GetShowReference(String.Format("~/AttachFile/webuploader.aspx?type=0&toKeyId={0}&path=FileUpload/Base/CompanyModel&menuId={1}", this.hdId.Text, BLL.Const.CompanyModelMenuId)));
}
}
#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;
}
string id = Request.Params["CompanyModelId"];
Model.Base_CompanyModel newCompanyModel = new Model.Base_CompanyModel();
newCompanyModel.CompanyModelKindId = this.drpCompanyModelKindId.SelectedValue;
newCompanyModel.ModelType = this.txtModelType.Text.Trim();
newCompanyModel.Remark = this.txtRemark.Text.Trim();
if (!string.IsNullOrEmpty(id))
{
newCompanyModel.CompanyModelId = id;
BLL.CompanyModelService.UpdateCompanyModel(newCompanyModel);
}
else
{
if (!string.IsNullOrEmpty(this.hdId.Text))
{
newCompanyModel.CompanyModelId = this.hdId.Text.Trim();
}
else
{
newCompanyModel.CompanyModelId = SQLHelper.GetNewID(typeof(Model.Base_CompanyModel));
this.hdId.Text = newCompanyModel.CompanyModelId;
}
BLL.CompanyModelService.AddCompanyModel(newCompanyModel);
var projects = from x in Funs.DB.Base_Project select x;
foreach (var item in projects)
{
Model.Model_QualityModel newQualityModel = new Model.Model_QualityModel();
newQualityModel.ProjectId = item.ProjectId;
newQualityModel.CompanyModelId = newCompanyModel.CompanyModelId;
newQualityModel.Remark = this.txtRemark.Text.Trim();
newQualityModel.QualityModelId = SQLHelper.GetNewID();
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>
/// 获取图片(放于Img中)
/// </summary>
/// <param name="registrationId"></param>
/// <returns></returns>
protected string ConvertImageUrlByImage(object CompanyModelId)
{
string url = string.Empty;
if (CompanyModelId != null)
{
var attachFile = BLL.AttachFileService.GetAttachFile(CompanyModelId.ToString(), BLL.Const.CompanyModelMenuId);
if (attachFile != null)
{
url = HttpUtility.HtmlDecode(BLL.UploadAttachmentService.ShowImage("../", attachFile.AttachUrl));
}
}
return url;
}
#endregion
}
}