ChengDa_English/SGGL/FineUIPro.Web/CQMS/Solution/ConstructSolutionFinal.aspx.cs

644 lines
28 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using Aspose.Words;
using BLL;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace FineUIPro.Web.CQMS.Solution
{
public partial class ConstructSolutionFinal : PageBase
{
#region
/// <summary>
/// 获取按钮权限
/// </summary>
/// <param name="button"></param>
/// <returns></returns>
private void GetButtonPower()
{
if (Request.Params["value"] == "0")
{
return;
}
var buttonList = CommonService.GetAllButtonList(CurrUser.LoginProjectId, CurrUser.UserId, Const.CQMSConstructSolutionMenuId);
if (buttonList.Count() > 0)
{
if (buttonList.Contains(Const.BtnDelete))
{
btnMenuDel.Hidden = false;
}
}
}
#endregion
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
GetButtonPower();
//BLL.SolutionTempleteTypeService.InitSolutionTempleteDropDownList(drpSolutionType, true);
//Funs.FineUIPleaseSelect(drpState);
UnitService.InitUnitByProjectIdUnitTypeDropDownList(drpProposeUnit, CurrUser.LoginProjectId, BLL.Const.ProjectUnitType_2, true);
btnNew.OnClientClick = Window1.GetShowReference("EditConstructSolutionFinal.aspx") + "return false;";
if (this.CurrUser.UnitId != null && this.CurrUser.UnitId != Const.UnitId_CD && this.CurrUser.UnitId != Const.hfnbdId)
{
this.drpProposeUnit.Hidden = true;
}
BindGrid();
}
else
{
var eventArgs = GetRequestEventArgument(); // 此函数所在文件PageBase.cs
}
}
protected string ConvertEdition(object edition)
{
return string.Format("{0:#0.#}",((int)edition)/10.0);
}
protected void Grid1_RowDataBound(object sender, GridRowEventArgs e)
{
int i = e.RowIndex;
string id = Grid1.Rows[i].DataKeys[0].ToString();
}
protected DataTable ChecklistData()
{
string strSql = @"SELECT ConstructSolutionId
,ProjectId
,solution.UnitId
,UnitName
,SolutionName
,SolutionCode
,AuditDate
,State
FROM dbo.Solution_CQMSConstructSolution_Final as solution
left join Base_Unit unit on unit.unitId=solution.UnitId "
+ @" where ProjectId=@ProjectId";
List<SqlParameter> listStr = new List<SqlParameter>();
listStr.Add(new SqlParameter("@ProjectId", CurrUser.LoginProjectId));
if (this.CurrUser.UnitId != null && this.CurrUser.UnitId != Const.UnitId_CD && this.CurrUser.UnitId != Const.hfnbdId)
{
strSql += " AND solution.UnitId='" + this.CurrUser.UnitId+"'";
}
strSql += " order by AuditDate desc ";
//if (drpUnitWork.SelectedValue != Const._Null)
//{
// strSql += " AND chec.unitworkId=@unitworkId";
// listStr.Add(new SqlParameter("@unitworkId", drpUnitWork.SelectedValue));
//}
if (drpProposeUnit.SelectedValue != Const._Null)
{
strSql += " AND solution.UnitId='" + drpProposeUnit.SelectedValue + "'";
}
//if (drpQuestionType.SelectedValue != Const._Null)
//{
// strSql += " AND chec.QuestionType=@QuestionType";
// listStr.Add(new SqlParameter("@QuestionType", drpQuestionType.SelectedValue));
//}
//if (dpHandelStatus.SelectedValue != Const._Null)
//{
// if (dpHandelStatus.SelectedValue.Equals("1"))
// {
// strSql += " AND (chec.state='5' or chec.state='6')";
// }
// else if (dpHandelStatus.SelectedValue.Equals("2"))
// {
// strSql += " AND chec.state='7'";
// }
// else if (dpHandelStatus.SelectedValue.Equals("3"))
// {
// strSql += " AND DATEADD(day,1,chec.LimitDate)< GETDATE() and chec.state<>5 and chec.state<>6 and chec.state<>7";
// }
// else if (dpHandelStatus.SelectedValue.Equals("4"))
// {
// strSql += " AND DATEADD(day,1,chec.LimitDate)> GETDATE() and chec.state<>5 and chec.state<>6 and chec.state<>7";
// }
//}
SqlParameter[] parameter = listStr.ToArray();
DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter);
return tb;
}
private void BindGrid()
{
var list = ChecklistData();
Grid1.RecordCount = list.Rows.Count;
var CNProfessional = CNProfessionalService.GetCNProfessionalItem();
var uniWork = UnitWorkService.GetUnitWorkLists(CurrUser.LoginProjectId);
list = GetFilteredTable(Grid1.FilteredData, list);
var table = GetPagedDataTable(Grid1, list);
Grid1.DataSource = table;
Grid1.DataBind();
}
protected void Grid1_RowCommand(object sender, GridCommandEventArgs e)
{
object[] keys = Grid1.DataKeys[e.RowIndex];
string fileId = string.Empty;
if (keys == null)
{
return;
}
else
{
fileId = keys[0].ToString();
}
if (e.CommandName == "exportSuggestion")
{
Model.Solution_CQMSConstructSolution constructSolution = CQMSConstructSolutionService.GetConstructSolutionByConstructSolutionId(fileId);
var list = CQMSConstructSolutionApproveService.getListDataForExport(fileId);
string rootPath = Server.MapPath("~/");
string initTemplatePath = string.Empty;
string uploadfilepath = string.Empty;
string newUrl = string.Empty;
initTemplatePath = Const.ConstructSolutionSuggestTemplateUrl;
uploadfilepath = rootPath + initTemplatePath;
newUrl = uploadfilepath.Replace(".doc", constructSolution.Code.Replace("/", "-") + ".doc");
if (File.Exists(newUrl))
{
File.Delete(newUrl);
}
File.Copy(uploadfilepath, newUrl);
Document doc = new Aspose.Words.Document(newUrl);
Bookmark bookmarkProjectName = doc.Range.Bookmarks["projectName"];
Bookmark bookmarkProjectName2 = doc.Range.Bookmarks["projectName2"];
Bookmark bookmarkprojectNum = doc.Range.Bookmarks["projectNum"];
Bookmark FileNum = doc.Range.Bookmarks["FileNum"];
if (FileNum != null)
{
FileNum.Text = constructSolution.Code;
}
if (bookmarkProjectName != null)
{
var project = ProjectService.GetProjectByProjectId(constructSolution.ProjectId);
if (project != null)
{
bookmarkProjectName.Text = project.ProjectName;
bookmarkProjectName2.Text = project.ProjectName;
bookmarkprojectNum.Text = project.ProjectCode;
}
}
Bookmark bookmarkEdition = doc.Range.Bookmarks["Edition"];
if (bookmarkEdition != null && constructSolution.Edition.HasValue)
{
bookmarkEdition.Text =""+ (constructSolution.Edition.Value/10.0).ToString("0.0");
}
Bookmark bookmarkoption1 = doc.Range.Bookmarks["option1"];
Bookmark bookmarkAuditer1 = doc.Range.Bookmarks["Auditer1"];
Bookmark bookmarkAuditDate1 = doc.Range.Bookmarks["AuditDate1"];
if (bookmarkoption1 != null)
{
string option = "";
var listtemp = list.Where(u=>u.SignType=="ZY").ToList();
for (int i = 0; i < listtemp.Count; i++)
{
option += string.Format("{0}\n", listtemp[i].ApproveIdea);
}
bookmarkoption1.Text = option;
var temp = list.Where(u => u.SignType == "ZY").LastOrDefault();
if (temp != null)
{
var user = UserService.GetUserByUserId(temp.ApproveMan);
if (user != null)
{
bookmarkAuditer1.Text = user.UserName;
}
bookmarkAuditDate1.Text = temp.ApproveDate.Value.ToString("yyyy年 MM月 dd日");
}
}
Bookmark bookmarkoption2 = doc.Range.Bookmarks["option2"];
Bookmark bookmarkAuditer2 = doc.Range.Bookmarks["Auditer2"];
Bookmark bookmarkAuditDate2 = doc.Range.Bookmarks["AuditDate2"];
if (bookmarkoption2 != null)
{
string option = "";
var listtemp = list.Where(u => u.SignType == "ZL").ToList();
for (int i = 0; i < listtemp.Count; i++)
{
option += string.Format("{0}\n", listtemp[i].ApproveIdea);
}
bookmarkoption2.Text = option;
var temp = list.Where(u => u.SignType == "ZL").LastOrDefault();
if (temp != null)
{
var user = UserService.GetUserByUserId(temp.ApproveMan);
if (user != null)
{
bookmarkAuditer2.Text = user.UserName;
}
bookmarkAuditDate2.Text = temp.ApproveDate.Value.ToString("yyyy年 MM月 dd日");
}
}
Bookmark bookmarkoption3 = doc.Range.Bookmarks["option3"];
Bookmark bookmarkAuditer3 = doc.Range.Bookmarks["Auditer3"];
Bookmark bookmarkAuditDate3 = doc.Range.Bookmarks["AuditDate3"];
if (bookmarkoption3 != null)
{
string option = "";
var listtemp = list.Where(u => u.SignType == "AQ").ToList();
for (int i = 0; i < listtemp.Count; i++)
{
var puser = ProjectUserService.GetProjectUserByUserIdProjectId(constructSolution.ProjectId, listtemp[i].ApproveMan);
if (puser.RoleId.Contains(Const.HSSEEngineer))
{
var user = UserService.GetUserByUserId(listtemp[i].ApproveMan);
option += string.Format("{0}\n", listtemp[i].ApproveIdea);
if (user != null)
{
bookmarkAuditer3.Text = user.UserName;
}
bookmarkAuditDate3.Text = listtemp[i].ApproveDate.Value.ToString("yyyy年 MM月 dd日");
}
}
bookmarkoption3.Text = option;
}
Bookmark bookmarkoption4 = doc.Range.Bookmarks["option4"];
Bookmark bookmarkAuditer4 = doc.Range.Bookmarks["Auditer4"];
Bookmark bookmarkAuditDate4 = doc.Range.Bookmarks["AuditDate4"];
if (bookmarkoption4 != null)
{
string option = "";
var listtemp = list.Where(u => u.SignType == "AQ").ToList();
for (int i = 0; i < listtemp.Count; i++)
{
var puser = ProjectUserService.GetProjectUserByUserIdProjectId(constructSolution.ProjectId, listtemp[i].ApproveMan);
if (puser.RoleId.Contains(Const.HSSEManager))
{
var user = UserService.GetUserByUserId(listtemp[i].ApproveMan);
option += string.Format("{0}\n", listtemp[i].ApproveIdea);
if (user != null)
{
bookmarkAuditer4.Text = user.UserName;
}
bookmarkAuditDate4.Text = listtemp[i].ApproveDate.Value.ToString("yyyy年 MM月 dd日");
}
}
bookmarkoption4.Text = option;
}
Bookmark bookmarkoption5 = doc.Range.Bookmarks["option5"];
Bookmark bookmarkAuditer5 = doc.Range.Bookmarks["Auditer5"];
Bookmark bookmarkAuditDate5 = doc.Range.Bookmarks["AuditDate5"];
if (bookmarkoption5!= null)
{
string option = "";
var listtemp = list.Where(u => u.SignType == "SG").ToList();
for (int i = 0; i < listtemp.Count; i++)
{
option += string.Format("{0}\n", listtemp[i].ApproveIdea);
}
bookmarkoption5.Text = option;
var temp = list.Where(u => u.SignType == "SG").LastOrDefault();
if (temp != null)
{
var user = UserService.GetUserByUserId(temp.ApproveMan);
if (user != null)
{
bookmarkAuditer5.Text = user.UserName;
}
bookmarkAuditDate5.Text = temp.ApproveDate.Value.ToString("yyyy年 MM月 dd日");
}
}
doc.Save(newUrl);
Document doc1 = new Aspose.Words.Document(newUrl);
//验证参数
if (doc1 == null) { throw new Exception("Word文件无效"); }
string fileName = Path.GetFileName(newUrl);
FileInfo info = new FileInfo(newUrl);
long fileSize = info.Length;
Response.Clear();
Response.ContentType = "application/x-zip-compressed";
Response.AddHeader("Content-Disposition", "attachment;filename=" + System.Web.HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8));
Response.AddHeader("Content-Length", fileSize.ToString());
Response.TransmitFile(newUrl, 0, fileSize);
Response.Flush();
Response.Close();
File.Delete(newUrl);
}
else if (e.CommandName == "exportApproval")
{
Model.Solution_CQMSConstructSolution constructSolution = CQMSConstructSolutionService.GetConstructSolutionByConstructSolutionId(fileId);
var list = CQMSConstructSolutionApproveService.getListData(fileId);
string rootPath = Server.MapPath("~/");
string initTemplatePath = string.Empty;
string uploadfilepath = string.Empty;
string newUrl = string.Empty;
initTemplatePath = Const.ConstructSolutionApproveTemplateUrl;
uploadfilepath = rootPath + initTemplatePath;
newUrl = uploadfilepath.Replace(".doc", constructSolution.Code.Replace("/", "-") + ".doc");
if (File.Exists(newUrl))
{
File.Delete(newUrl);
}
File.Copy(uploadfilepath, newUrl);
Document doc = new Aspose.Words.Document(newUrl);
Bookmark bookmarkProjectName = doc.Range.Bookmarks["projectName"];
Bookmark bookmarkProjectName2 = doc.Range.Bookmarks["projectName2"];
Bookmark bookmarkprojectNum = doc.Range.Bookmarks["projectNum"];
Bookmark FileNum = doc.Range.Bookmarks["FileNum"];
if (FileNum !=null)
{
FileNum.Text = constructSolution.Code;
}
if (bookmarkProjectName != null)
{
var project = ProjectService.GetProjectByProjectId(constructSolution.ProjectId);
if (project != null)
{
bookmarkProjectName.Text = project.ProjectName;
bookmarkProjectName2.Text = project.ProjectName;
bookmarkprojectNum.Text = project.ProjectCode;
}
}
Bookmark bookmarkEdition = doc.Range.Bookmarks["Edition"];
if (bookmarkEdition != null && constructSolution.Edition.HasValue)
{
bookmarkEdition.Text = "" + (constructSolution.Edition.Value / 10.0).ToString("0.0");
}
Bookmark bookmarkoption1 = doc.Range.Bookmarks["option1"];
Bookmark bookmarkAuditer1 = doc.Range.Bookmarks["Auditer1"];
Bookmark bookmarkAuditDate1 = doc.Range.Bookmarks["AuditDate1"];
if (bookmarkoption1 != null)
{
string option = "";
var listtemp = list.Where(u => u.SignType == "ZY").LastOrDefault();
if (listtemp != null)
{
option += string.Format("{0}\n", listtemp.ApproveIdea);
var user = UserService.GetUserByUserId(listtemp.ApproveMan);
if (user != null)
{
bookmarkAuditer1.Text = user.UserName;
}
bookmarkAuditDate1.Text = listtemp.ApproveDate.Value.ToString("yyyy年 MM月 dd日");
}
bookmarkoption1.Text = option;
}
Bookmark bookmarkoption2 = doc.Range.Bookmarks["option2"];
Bookmark bookmarkAuditer2 = doc.Range.Bookmarks["Auditer2"];
Bookmark bookmarkAuditDate2 = doc.Range.Bookmarks["AuditDate2"];
if (bookmarkoption2 != null)
{
string option = "";
var listtemp = list.Where(u => u.SignType == "ZL").LastOrDefault();
if (listtemp != null)
{
option += string.Format("{0}\n", listtemp.ApproveIdea);
var user = UserService.GetUserByUserId(listtemp.ApproveMan);
if (user != null)
{
bookmarkAuditer2.Text = user.UserName;
}
bookmarkAuditDate2.Text = listtemp.ApproveDate.Value.ToString("yyyy年 MM月 dd日");
}
bookmarkoption2.Text = option;
}
Bookmark bookmarkoption3 = doc.Range.Bookmarks["option3"];
Bookmark bookmarkAuditer3 = doc.Range.Bookmarks["Auditer3"];
Bookmark bookmarkAuditDate3 = doc.Range.Bookmarks["AuditDate3"];
if (bookmarkoption3 != null)
{
string option = "";
var listtemp = list.Where(u => u.SignType == "AQ").ToList();
Model.Solution_CQMSConstructSolutionApprove lastApprove = null;
for (int i = 0; i < listtemp.Count; i++)
{
var puser = ProjectUserService.GetProjectUserByUserIdProjectId(constructSolution.ProjectId, listtemp[i].ApproveMan);
if (puser.RoleId.Contains(Const.HSSEEngineer))
{
lastApprove = listtemp[i];
}
}
if(lastApprove != null)
{
option += string.Format("{0}\n", lastApprove.ApproveIdea);
var user = UserService.GetUserByUserId(lastApprove.ApproveMan);
if (user != null)
{
bookmarkAuditer3.Text = user.UserName;
}
bookmarkAuditDate3.Text = lastApprove.ApproveDate.Value.ToString("yyyy年 MM月 dd日");
}
bookmarkoption3.Text = option;
}
Bookmark bookmarkoption4 = doc.Range.Bookmarks["option4"];
Bookmark bookmarkAuditer4 = doc.Range.Bookmarks["Auditer4"];
Bookmark bookmarkAuditDate4 = doc.Range.Bookmarks["AuditDate4"];
if (bookmarkoption4 != null)
{
string option = "";
var listtemp = list.Where(u => u.SignType == "AQ").ToList();
Model.Solution_CQMSConstructSolutionApprove lastApprove = null;
for (int i = 0; i < listtemp.Count; i++)
{
var puser = ProjectUserService.GetProjectUserByUserIdProjectId(constructSolution.ProjectId, listtemp[i].ApproveMan);
if (puser.RoleId.Contains(Const.HSSEManager))
{
lastApprove = listtemp[i];
}
}
if (lastApprove != null)
{
option += string.Format("{0}\n", lastApprove.ApproveIdea);
var user = UserService.GetUserByUserId(lastApprove.ApproveMan);
if (user != null)
{
bookmarkAuditer4.Text = user.UserName;
}
bookmarkAuditDate4.Text = lastApprove.ApproveDate.Value.ToString("yyyy年 MM月 dd日");
}
bookmarkoption4.Text = option;
}
Bookmark bookmarkoption5 = doc.Range.Bookmarks["option5"];
Bookmark bookmarkAuditer5 = doc.Range.Bookmarks["Auditer5"];
Bookmark bookmarkAuditDate5 = doc.Range.Bookmarks["AuditDate5"];
if (bookmarkoption5 != null)
{
string option = "";
var listtemp = list.Where(u => u.SignType == "SG").LastOrDefault();
if (listtemp != null)
{
option += string.Format("{0}\n", listtemp.ApproveIdea);
var user = UserService.GetUserByUserId(listtemp.ApproveMan);
if (user != null)
{
bookmarkAuditer5.Text = user.UserName;
}
bookmarkAuditDate5.Text = listtemp.ApproveDate.Value.ToString("yyyy年 MM月 dd日");
}
bookmarkoption5.Text = option;
}
doc.Save(newUrl);
Document doc1 = new Aspose.Words.Document(newUrl);
//验证参数
if (doc1 == null) { throw new Exception("Word文件无效"); }
string fileName = Path.GetFileName(newUrl);
FileInfo info = new FileInfo(newUrl);
long fileSize = info.Length;
Response.Clear();
Response.ContentType = "application/x-zip-compressed";
Response.AddHeader("Content-Disposition", "attachment;filename=" + System.Web.HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8));
Response.AddHeader("Content-Length", fileSize.ToString());
Response.TransmitFile(newUrl, 0, fileSize);
Response.Flush();
Response.Close();
File.Delete(newUrl);
}
else if (e.CommandName == "attchUrl")
{
Model.Solution_CQMSConstructSolution_Final constructSolution = CQMSConstructSolutionFinalService.GetConstructSolutionByConstructSolutionId(fileId);
if (constructSolution != null)
{
PageContext.RegisterStartupScript(WindowAtt.GetShowReference(String.Format("../../AttachFile/webuploader.aspx?type={0}&toKeyId={1}&path=FileUpload/Solution&menuId={2}",
-1, constructSolution.ConstructSolutionId , Const.CQMSConstructSolutionMenuId)));
}
}
}
protected void btnQuery_Click(object sender, EventArgs e)
{
BindGrid();
}
protected void btnRset_Click(object sender, EventArgs e)
{
//drpSolutionType.SelectedIndex = 0;
drpProposeUnit.SelectedIndex = 0;
BindGrid();
}
protected void ddlPageSize_SelectedIndexChanged(object sender, EventArgs e)
{
Grid1.PageSize = Convert.ToInt32(ddlPageSize.SelectedValue);
BindGrid();
}
protected void btnMenuModify_Click(object sender, EventArgs e)
{
if (Grid1.SelectedRowIndexArray.Length == 0)
{
Alert.ShowInTop("请至少选择一条记录!", MessageBoxIcon.Warning);
return;
}
string id = Grid1.SelectedRowID.Split(',')[0];
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("EditConstructSolutionFinal.aspx?constructSolutionId={0}", id)));
}
protected void btnMenuView_Click(object sender, EventArgs e)
{
if (Grid1.SelectedRowIndexArray.Length == 0)
{
Alert.ShowInTop("请至少选择一条记录!", MessageBoxIcon.Warning);
return;
}
string id = Grid1.SelectedRowID.Split(',')[0];
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("EditConstructSolutionFinal.aspx?constructSolutionId={0}", id)));
}
protected void btnMenuDel_Click(object sender, EventArgs e)
{
if (Grid1.SelectedRowIndexArray.Length == 0)
{
Alert.ShowInTop("请至少选择一条记录!", MessageBoxIcon.Warning);
return;
}
string id = Grid1.SelectedRowID.Split(',')[0];
if (CommonService.GetAllButtonPowerList(CurrUser.LoginProjectId, CurrUser.UserId, Const.CQMSConstructSolutionMenuId, Const.BtnDelete))
{
var constructSolution = CQMSConstructSolutionFinalService.GetConstructSolutionByConstructSolutionId(id);
CQMSConstructSolutionFinalService.DeleteConstructSolution(id);
LogService.AddSys_Log(CurrUser, constructSolution.ConstructSolutionId, id, Const.CQMSConstructSolutionFineMenuId, "删除方案审查");
BindGrid();
Alert.ShowInTop("删除成功!", MessageBoxIcon.Success);
}
else
{
Alert.ShowInTop("您没有这个权限,请与管理员联系!", MessageBoxIcon.Success);
}
}
protected void Window1_Close(object sender, WindowCloseEventArgs e)
{
BindGrid();
}
protected void window_tt_Close(object sender, WindowCloseEventArgs e)
{
BindGrid();
}
protected void Grid1_RowDoubleClick(object sender, GridRowClickEventArgs e)
{
btnMenuModify_Click(sender, e);
}
protected void Grid1_PageIndexChange(object sender, GridPageEventArgs e)
{
Grid1.PageIndex = e.NewPageIndex;
BindGrid();
}
}
}