protected void btnSave_Click(object sender, EventArgs e) { try { if (string.IsNullOrEmpty(hidTemplateID.Value)) { ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "alertnullExist", "javascript:showMessage('未获取到目标模板信息!',8);showDetail();", true); return; } string communicationDetails = hidCommunicationDetails.Value; if (hidSaveModel.Value == "add") { if (dc.CommunicationIsExist(txtName.Value, hidTemplateID.Value.Trim())) { ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "alertExist", "javascript:showMessage('该业务名称已存在,请重新输入!',8);showDetail();", true); return; } Guid sourceTemplateID = new Guid(ddlSourceTemplate.SelectedValue); Guid templateID = new Guid(hidTemplateID.Value); BS_COMMUNICATION_MAIN model = new BS_COMMUNICATION_MAIN(); Guid communicationID = Guid.NewGuid(); model.CommunicationID = communicationID; string currentUser = GetCurrentUserLoginId(); model.Author = currentUser; model.Created = DateTime.Now; model.Editor = currentUser; model.Modified = DateTime.Now; model.Name = txtName.Value; model.SourceTemplateID = sourceTemplateID; model.TargetTemplateID = templateID; BS_COMMUNICATION_MAINBLL bll = new BS_COMMUNICATION_MAINBLL(); if (bll.Add(model)) { string[] communication = communicationDetails.Split('|'); foreach (string details in communication) { string[] strDetail = details.Split(';'); BS_COMMUNICATION_DETAIL detailModel = new BS_COMMUNICATION_DETAIL(); detailModel.Author = currentUser; detailModel.CommunicationID = communicationID; detailModel.Created = DateTime.Now; detailModel.Editor = currentUser; detailModel.ID = Guid.NewGuid(); detailModel.Modified = DateTime.Now; detailModel.SourceColumnName = strDetail[0]; if (strDetail.Length > 1) { detailModel.TargetColumnName = strDetail[1]; } BS_COMMUNICATION_DETAILBLL detailBLL = new BS_COMMUNICATION_DETAILBLL(); detailBLL.Add(detailModel); } BindCommunicationData(); ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "alert1", "javascript:showMessage('新增成功!',9);", true); } else { ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "alert1", "javascript:showMessage('新增失败!',8);", true); } } else { if (!string.IsNullOrEmpty(hidCommunicationID.Value)) { string currentUser = GetCurrentUserLoginId(); Guid communicationID = new Guid(hidCommunicationID.Value); BS_COMMUNICATION_MAINBLL bll = new BS_COMMUNICATION_MAINBLL(); BS_COMMUNICATION_MAIN model = bll.GetModel(communicationID); model.Name = txtName.Value; model.Modified = DateTime.Now; model.Editor = currentUser; if (bll.Update(model)) { string[] communication = communicationDetails.Split('|'); BS_COMMUNICATION_DETAILBLL detailBLL = new BS_COMMUNICATION_DETAILBLL(); detailBLL.DeleteAll(communicationID); foreach (string details in communication) { string[] strDetail = details.Split(';'); BS_COMMUNICATION_DETAIL detailModel = new BS_COMMUNICATION_DETAIL(); detailModel.Author = currentUser; detailModel.CommunicationID = communicationID; detailModel.Created = DateTime.Now; detailModel.Editor = currentUser; detailModel.ID = Guid.NewGuid(); detailModel.Modified = DateTime.Now; detailModel.SourceColumnName = strDetail[0]; if (strDetail.Length > 1) { detailModel.TargetColumnName = strDetail[1]; } detailBLL.Add(detailModel); } BindCommunicationData(); ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "alert1", "javascript:showMessage('修改成功!',9);", true); } else { ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "alert1", "javascript:showMessage('修改失败!',8);", true); } } } } catch (Exception ex) { ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "alertException", "javascript:showMessage('操作发生错误:" + ex.Message.Replace("'", "").Replace("\"", "") + "!',8);", true); } }
//复制 protected void btncopy_Click(object sender, EventArgs e) { try { string TemplateID = hidtemplateid.Value.Trim(); string CopyNewName = hidCopyName.Value.Trim(); if (!string.IsNullOrEmpty(TemplateID) && !string.IsNullOrEmpty(CopyNewName)) { Guid temid = Guid.Parse(TemplateID); //复制templatemain表 BS_TEMPLATE_MAINBLL tmain = new BS_TEMPLATE_MAINBLL(); BS_TEMPLATE_MAIN tmodel = tmain.GetModel(temid); tmodel.TemplateName = CopyNewName; tmodel.Created = DateTime.Now; tmodel.Modified = DateTime.Now; tmodel.Author = BaseWebPart.GetCurrentUserLoginId(); tmodel.Editor = BaseWebPart.GetCurrentUserLoginId(); tmodel.TemplateStatus = "FREE"; string newtemplateid = tmain.Add(tmodel); if (!string.IsNullOrEmpty(newtemplateid)) { DisplayConfigComponent dcc = new DisplayConfigComponent(); #region 制表 Guid newtemplateguid = Guid.Parse(newtemplateid); //复制bscompare表 DataTable dt = dcc.GetCalListByTemplateID(temid); if (dt != null && dt.Rows.Count > 0) { BS_COMPUTEBLL cmain = new BS_COMPUTEBLL(); foreach (DataRow dr in dt.Rows) { BS_COMPUTE cmodel = cmain.GetModel(Guid.Parse(dr["id"].ToString())); if (cmodel != null) { cmodel.TemplateID = newtemplateguid; cmodel.Created = DateTime.Now; cmodel.Modified = DateTime.Now; cmodel.Author = BaseWebPart.GetCurrentUserLoginId(); cmodel.Editor = BaseWebPart.GetCurrentUserLoginId(); cmain.Add(cmodel); } } } //复制BS_CUSTOM_QUERY表 dt = tmbll.GetBS_CUSTOM_QUERYIDByTemplateID(temid); if (dt != null && dt.Rows.Count > 0) { BS_CUSTOM_QUERYBLL cbll = new BS_CUSTOM_QUERYBLL(); foreach (DataRow dr in dt.Rows) { BS_CUSTOM_QUERY cqmodel = cbll.GetModel(Guid.Parse(dr["id"].ToString())); if (cqmodel != null) { cqmodel.TemplateID = newtemplateguid; cqmodel.Created = DateTime.Now; cqmodel.Modified = DateTime.Now; cqmodel.Author = BaseWebPart.GetCurrentUserLoginId(); cqmodel.Editor = BaseWebPart.GetCurrentUserLoginId(); cbll.Add(cqmodel); } } } //复制BS_CUSTOM_QUERY表 dt = tmbll.GetBS_DEFAULT_QUERYIDByTemplateID(temid); if (dt != null && dt.Rows.Count > 0) { BS_DEFAULT_QUERYBLL dbll = new BS_DEFAULT_QUERYBLL(); foreach (DataRow dr in dt.Rows) { BS_DEFAULT_QUERY dmodel = dbll.GetModel(Guid.Parse(dr["id"].ToString())); if (dmodel != null) { dmodel.TemplateID = newtemplateguid; dmodel.Created = DateTime.Now; dmodel.Modified = DateTime.Now; dmodel.Author = BaseWebPart.GetCurrentUserLoginId(); dmodel.Editor = BaseWebPart.GetCurrentUserLoginId(); dbll.Add(dmodel); } } } //复制BS_GROUPBY表 dt = tmbll.GetBS_GROUPBYIDByTemplateID(temid); if (dt != null && dt.Rows.Count > 0) { BS_GROUPBYBLL gbll = new BS_GROUPBYBLL(); foreach (DataRow dr in dt.Rows) { BS_GROUPBY gmodel = gbll.GetModel(Guid.Parse(dr["id"].ToString())); if (gmodel != null) { gmodel.TemplateID = newtemplateguid; gmodel.Created = DateTime.Now; gmodel.Modified = DateTime.Now; gmodel.Author = BaseWebPart.GetCurrentUserLoginId(); gmodel.Editor = BaseWebPart.GetCurrentUserLoginId(); gbll.Add(gmodel); } } } //复制BS_TEMPLATE_COLUMNS表 dt = tmbll.GetBS_TEMPLATE_COLUMNSIDByTemplateID(temid); if (dt != null && dt.Rows.Count > 0) { BS_TEMPLATE_COLUMNSBLL tbll = new BS_TEMPLATE_COLUMNSBLL(); foreach (DataRow dr in dt.Rows) { BS_TEMPLATE_COLUMNS tcmodel = tbll.GetModel(Guid.Parse(dr["id"].ToString())); if (tcmodel != null) { tcmodel.TemplateID = newtemplateguid; tcmodel.Created = DateTime.Now; tcmodel.Modified = DateTime.Now; tcmodel.Author = BaseWebPart.GetCurrentUserLoginId(); tcmodel.Editor = BaseWebPart.GetCurrentUserLoginId(); tbll.Add(tcmodel); } } } //复制BS_TEMPLATE_SORT表 dt = tmbll.GetBS_TEMPLATE_SORTIDByTemplateID(temid); if (dt != null && dt.Rows.Count > 0) { BS_TEMPLATE_SORTBLL sbll = new BS_TEMPLATE_SORTBLL(); foreach (DataRow dr in dt.Rows) { BS_TEMPLATE_SORT smodel = sbll.GetModel(Guid.Parse(dr["id"].ToString())); if (smodel != null) { smodel.TemplateID = newtemplateguid; smodel.Created = DateTime.Now; smodel.Modified = DateTime.Now; smodel.Author = BaseWebPart.GetCurrentUserLoginId(); smodel.Editor = BaseWebPart.GetCurrentUserLoginId(); sbll.Add(smodel); } } } //复制BS_COMMUNICATION_MAIN表 dt = tmbll.GetBS_COMMUNICATION_MAINIDByTemplateID(temid); if (dt != null && dt.Rows.Count > 0) { BS_COMMUNICATION_MAINBLL sbll = new BS_COMMUNICATION_MAINBLL(); BS_COMMUNICATION_DETAILBLL detailbll = new BS_COMMUNICATION_DETAILBLL(); foreach (DataRow dr in dt.Rows) { Guid commid = Guid.NewGuid(); BS_COMMUNICATION_MAIN smodel = sbll.GetModel(Guid.Parse(dr["CommunicationID"].ToString())); if (smodel != null) { smodel.CommunicationID = commid; smodel.TargetTemplateID = newtemplateguid; smodel.Created = DateTime.Now; smodel.Modified = DateTime.Now; smodel.Author = BaseWebPart.GetCurrentUserLoginId(); smodel.Editor = BaseWebPart.GetCurrentUserLoginId(); sbll.Add(smodel); } DataTable dtdetail = tmbll.GetBS_COMMUNICATION_DETAILByID(Guid.Parse(dr["CommunicationID"].ToString())); if (dtdetail != null && dtdetail.Rows.Count > 0) { foreach (DataRow drd in dtdetail.Rows) { BS_COMMUNICATION_DETAIL sdmodel = detailbll.GetModel(Guid.Parse(drd["id"].ToString())); if (smodel != null) { sdmodel.ID = Guid.NewGuid(); sdmodel.CommunicationID = commid; sdmodel.Created = DateTime.Now; sdmodel.Modified = DateTime.Now; sdmodel.Author = BaseWebPart.GetCurrentUserLoginId(); sdmodel.Editor = BaseWebPart.GetCurrentUserLoginId(); detailbll.Add(sdmodel); } } } } } #endregion ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "sucadd", "layer.alert('模板复制成功!',9);", true); BindTemplateList(); } else { ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "erroradd", "layer.alert('模板复制失败!',8);", true); } } else { ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "errora", "layer.alert('未获取到模板源信息,无法复制!',8);", true); } } catch (Exception ee) { ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "erroradd", "layer.alert('模板复制失败!',8);", true); BaseComponent.Error(ee.Message); } }