using BLL; using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; namespace FineUIPro.Web.BaseInfo { public partial class CompanytemplateEdit : PageBase { #region /// /// 主键 /// public string TemplateId { get { return (string)ViewState["TemplateId"]; } set { ViewState["TemplateId"] = value; } } #endregion protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { this.btnClose.OnClientClick = ActiveWindow.GetHideReference(); ////权限按钮方法 this.GetButtonPower(); this.TemplateId = Request.Params["TemplateId"]; if (!string.IsNullOrEmpty(this.TemplateId)) { Model.Base_CompanyTemplate model = BLL.Base_CompanytemplateService.GetBase_CompanyTemplateById(this.TemplateId); if (model != null) { this.txtCode.Text = model.Code; this.txtName.Text = model.Name; this.txtRemarks.Text = model.Remarks; } } } } /// /// 保存按钮 /// /// /// protected void btnSave_Click(object sender, EventArgs e) { if (Save()) { PageContext.RegisterStartupScript(ActiveWindow.GetHideRefreshReference()); } } private bool Save() { bool result=true; var q = BLL.Base_CompanytemplateService.GetBase_CompanyTemplateByCode(this.txtCode.Text); if (q != null && q.TemplateId != this.TemplateId) { ShowNotify("文件编号不能重复", MessageBoxIcon.Warning); result = false; return result; } Model.Base_CompanyTemplate table = new Model.Base_CompanyTemplate(); table.Code = this.txtCode.Text; table.Name = this.txtName.Text; table.FilePath = "FileUpload/Companytemplate/" + txtCode.Text + ".doc"; table.Remarks = this.txtRemarks.Text; if (!File.Exists(Funs.RootPath + table.FilePath)) { string rootPath = Funs.RootPath; string filepath = table.FilePath; string path = rootPath + filepath; DirectoryInfo pathInfo = new DirectoryInfo(path); string newPath = pathInfo.Parent.FullName; if (!Directory.Exists(newPath)) { Directory.CreateDirectory(newPath); } var stream = File.Create(path); stream.Close(); } if (string.IsNullOrEmpty(this.TemplateId)) { table.TemplateId = SQLHelper.GetNewID(typeof(Model.Base_CompanyTemplate)); TemplateId = table.TemplateId; BLL.Base_CompanytemplateService.AddBase_CompanyTemplate(table); } else { table.TemplateId = this.TemplateId; BLL.Base_CompanytemplateService.UpdateBase_CompanyTemplate(table); } return result; } #region 获取按钮权限 /// /// 获取按钮权限 /// /// /// private void GetButtonPower() { var buttonList = BLL.CommonService.GetAllButtonList(this.CurrUser.LoginProjectId, this.CurrUser.PersonId, BLL.Const.CompanyTemplateMenuId); if (buttonList.Count() > 0) { if (buttonList.Contains(BLL.Const.BtnSave)) { this.btnSave.Hidden = false; } } } #endregion protected void btnEditWord_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(TemplateId)) { Save(); } Model.Base_CompanyTemplate table = BLL.Base_CompanytemplateService.GetBase_CompanyTemplateById(TemplateId); if (!File.Exists(Funs.RootPath + table.FilePath)) { string rootPath = Funs.RootPath; string filepath = table.FilePath; string path = rootPath + filepath; DirectoryInfo pathInfo = new DirectoryInfo(path); string newPath = pathInfo.Parent.FullName; if (!Directory.Exists(newPath)) { Directory.CreateDirectory(newPath); } var stream = File.Create(path); stream.Close(); } else { PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("~/AttachFile/IndexOffice.aspx?cmd={0}|Companytemplate", TemplateId, "查看 -"))); PageContext.RegisterStartupScript(Window1.GetHideReference()); } } } }