CNCEC_SUBQHSE_WUHUAN/SGGL/FineUIPro.Web/CQMS/Comprehensive/DataReceivingDocDataIn.aspx.cs

696 lines
30 KiB
C#
Raw Normal View History

using BLL;
using Model;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.IO;
using System.Linq;
using System.Threading;
namespace FineUIPro.Web.CQMS.Comprehensive
{
public partial class DataReceivingDocDataIn : PageBase
{
#region
/// <summary>
/// 上传预设的虚拟路径
/// </summary>
private string initPath = Const.ExcelUrl;
/// <summary>
/// 错误集合
/// </summary>
public static string errorInfos = string.Empty;
#endregion
#region
/// <summary>
/// 加载页面
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
if (percent == null)
{
percent = new Dictionary<string, int>();
}
this.id.Text = this.CurrUser.UserId;
this.ddlPageSize.SelectedValue = Grid1.PageSize.ToString();
// 绑定表格
this.BindGrid();
}
else if (GetRequestEventArgument() == "reloadGrid")
{
BindGrid();
}
}
#endregion
#region
/// <summary>
/// 绑定数据
/// </summary>
private void BindGrid()
{
string strSql = @"SELECT TempId,ProjectId,UserId,Time,RowNo,ToopValue,Value1,Value2,Value3,Value4,Value5,Value6,Value7,Value8,Value9,Value10"
+ @" ,Value11,Value12,Value13,Value14,Value15,Value16,Value17,Value18,Value19,Value20,Value21,Value22,Value23,Value24,Value25,Value26,Value27,Value28,Value29,Value30"
+ @" ,Value31,Value32,Value33,Value34,Value35,Value36,Value37,Value38,Value39,Value40,Value41,Value42,Value43,Value44,Value45,Value46,Value47,Value48,Value49,Value50,ToopValue,Type"
+ @" FROM Sys_DataInTemp "
+ @" WHERE ProjectId=@ProjectId AND UserId=@UserId AND Type=@Type";
List<SqlParameter> listStr = new List<SqlParameter>();
listStr.Add(new SqlParameter("@ProjectId", this.CurrUser.LoginProjectId));
listStr.Add(new SqlParameter("@UserId", this.CurrUser.UserId));
listStr.Add(new SqlParameter("@Type", "DataReceivingDoc"));//资料收发文登记记录
SqlParameter[] parameter = listStr.ToArray();
DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter);
Grid1.RecordCount = tb.Rows.Count;
var table = this.GetPagedDataTable(Grid1, tb);
Grid1.DataSource = table;
Grid1.DataBind();
var dataInTempAll = from x in Funs.DB.Sys_DataInTemp
where x.ProjectId == this.CurrUser.LoginProjectId && x.UserId == this.CurrUser.UserId && x.Type == "DataReceivingDoc"
select x;
for (int i = 0; i < Grid1.Rows.Count; i++)
{
var dataInTemp = dataInTempAll.FirstOrDefault(x => x.TempId == Grid1.Rows[i].DataKeys[0].ToString());
if (dataInTemp != null)
{
if (!string.IsNullOrEmpty(dataInTemp.ToopValue))
{
Grid1.Rows[i].RowCssClass = "red";
}
}
}
var errData = from x in dataInTempAll where x.ToopValue != null select x;
this.lbDataCout.Text = errData.Count().ToString();
}
#endregion
#region
/// <summary>
/// Grid行双击事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Grid1_RowDoubleClick(object sender, GridRowClickEventArgs e)
{
if (Grid1.SelectedRowIndexArray.Length == 0)
{
Alert.ShowInTop("请选择一条记录!", MessageBoxIcon.Warning);
return;
}
if (CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, Const.DataReceivingDocMenuId, Const.BtnSave))
{
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("DataReceivingDocDataInEdit.aspx?TempId={0}", Grid1.SelectedRowID, "维护 - ")));
}
else
{
ShowNotify("您没有这个权限,请与管理员联系!", MessageBoxIcon.Warning);
}
}
#endregion
#region
/// <summary>
/// 导入信息编辑
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnMenuEdit_Click(object sender, EventArgs e)
{
if (BLL.CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, BLL.Const.DataReceivingDocMenuId, BLL.Const.BtnSave))
{
if (Grid1.SelectedRowIndexArray.Length == 0)
{
Alert.ShowInTop("请选择一条记录!", MessageBoxIcon.Warning);
return;
}
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("DataReceivingDocDataInEdit.aspx?TempId={0}", Grid1.SelectedRowID, "维护 - ")));
}
else
{
ShowNotify("您没有这个权限,请与管理员联系!", MessageBoxIcon.Warning);
}
}
/// <summary>
/// 删除按钮
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnMenuDelete_Click(object sender, EventArgs e)
{
if (CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, Const.DataReceivingDocMenuId, Const.BtnSave))
{
if (Grid1.SelectedRowIndexArray.Length == 0)
{
Alert.ShowInTop("请选择一条记录!", MessageBoxIcon.Warning);
return;
}
foreach (int rowIndex in Grid1.SelectedRowIndexArray)
{
string rowID = Grid1.DataKeys[rowIndex][0].ToString();
BLL.Sys_DataTempService.DeleteDataInTempByDataInTempID(rowID);
}
ShowNotify("删除成功!", MessageBoxIcon.Success);
this.BindGrid();
}
else
{
Alert.ShowInTop("您没有这个权限,请与管理员联系!", MessageBoxIcon.Warning);
return;
}
}
#endregion
#region
/// <summary>
/// 分页
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Grid1_PageIndexChange(object sender, GridPageEventArgs e)
{
BindGrid();
}
/// <summary>
/// 分页显示条数下拉框
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void ddlPageSize_SelectedIndexChanged(object sender, EventArgs e)
{
Grid1.PageSize = Convert.ToInt32(ddlPageSize.SelectedValue);
BindGrid();
}
/// <summary>
/// 排序
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Grid1_Sort(object sender, FineUIPro.GridSortEventArgs e)
{
BindGrid();
}
#endregion
#region
/// <summary>
/// 删除所有数据事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnAllDelete_Click(object sender, EventArgs e)
{
if (CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, Const.DataReceivingDocMenuId, Const.BtnSave))
{
//先删除临时表中 该人员以前导入的数据
BLL.Sys_DataTempService.DeleteDataInTempByProjectIdUserId(this.CurrUser.LoginProjectId, this.CurrUser.UserId, "DataReceivingDoc");
this.BindGrid();
ShowNotify("删除成功!", MessageBoxIcon.Success);
this.lbDataCout.Text = string.Empty;
}
else
{
Alert.ShowInTop("您没有这个权限,请与管理员联系!", MessageBoxIcon.Warning);
return;
}
}
#endregion
#region
/// <summary>
/// 下载模板
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void imgbtnUpload_Click(object sender, EventArgs e)
{
this.TemplateUpload(BLL.Const.CQMS_DataReceivingDocTempUrl);
}
protected void TemplateUpload(string initTemplatePath)
{
string rootPath = Server.MapPath("~/");
string uploadfilepath = rootPath + initTemplatePath;
string filePath = Const.CQMS_DataReceivingDocTempUrl;
string fileName = Path.GetFileName(filePath);
FileInfo info = new FileInfo(uploadfilepath);
long fileSize = info.Length;
Response.ClearContent();
Response.AddHeader("Content-Disposition", "attachment;filename=" + System.Web.HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8));
Response.ContentType = "excel/plain";
Response.ContentEncoding = System.Text.Encoding.UTF8;
Response.AddHeader("Content-Length", fileSize.ToString().Trim());
Response.TransmitFile(uploadfilepath, 0, fileSize);
Response.End();
}
/// <summary>
/// 导入说明
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
//protected void lkAchievements_Click(object sender, EventArgs e)
//{
// this.TemplateUpload(Const.CQMS_DataReceivingDocTempUrl);
//}
#endregion
#region
public static Dictionary<string, int> percent { get; set; }
public static Dictionary<string, string> url { get; set; }
[System.Web.Services.WebMethod]
public static int getPercent(string id)
{
return percent[id];
}
#endregion
#region
/// <summary>
/// 文件上传
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void imgbtnImport_Click(object sender, EventArgs e)
{
try
{
if (this.FileExcel.HasFile == false)
{
ShowNotify("请选择Excel文件!", MessageBoxIcon.Warning);
return;
}
string IsXls = Path.GetExtension(this.FileExcel.FileName).ToString().Trim().ToLower();
if (IsXls != ".xls" && IsXls != ".xlsx")
{
ShowNotify("只能选择Excel文件!", MessageBoxIcon.Warning);
return;
}
string rootPath = Server.MapPath("~/");
string initFullPath = rootPath + initPath;
if (!Directory.Exists(initFullPath))
{
Directory.CreateDirectory(initFullPath);
}
//指定上传文件名称
this.hdfileName.Text = BLL.Funs.GetNewFileName() + IsXls;
//上传文件路径
string filePath = initFullPath + this.hdfileName.Text;
//文件上传服务器
this.FileExcel.PostedFile.SaveAs(filePath);
//文件上传服务器后的名称
string fileName = rootPath + initPath + this.hdfileName.Text;
//读取Excel
DataSet ds = NPOIHelper.ExcelToDataSet(fileName, out errorInfos, true);
//验证Excel读取是否有误
if (!string.IsNullOrEmpty(errorInfos))
{
ShowNotify(errorInfos, MessageBoxIcon.Warning);
return;
}
if (ds.Tables.Count > 0)
{
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
Sys_DataInTemp newDataInTemp = new Sys_DataInTemp();
newDataInTemp.TempId = SQLHelper.GetNewID(typeof(Model.Sys_DataInTemp));
newDataInTemp.ProjectId = this.CurrUser.LoginProjectId;
newDataInTemp.UserId = this.CurrUser.UserId;
newDataInTemp.Time = System.DateTime.Now;
newDataInTemp.Type = "DataReceivingDoc";
newDataInTemp.RowNo = i + 2;
newDataInTemp.Value1 = ds.Tables[0].Rows[i]["日期"].ToString().Trim();
newDataInTemp.Value2 = ds.Tables[0].Rows[i]["文件号"].ToString().Trim();
newDataInTemp.Value3 = ds.Tables[0].Rows[i]["文件名称"].ToString().Trim();
newDataInTemp.Value4 = ds.Tables[0].Rows[i]["文件类别"].ToString().Trim();
newDataInTemp.Value5 = ds.Tables[0].Rows[i]["专业"].ToString().Trim();
newDataInTemp.Value6 = ds.Tables[0].Rows[i]["发件单位"].ToString().Trim();
newDataInTemp.Value7 = ds.Tables[0].Rows[i]["发件人"].ToString().Trim();
newDataInTemp.Value8 = ds.Tables[0].Rows[i]["份数"].ToString().Trim();
newDataInTemp.Value9 = ds.Tables[0].Rows[i]["文件处理人"].ToString().Trim();
newDataInTemp.Value10 = ds.Tables[0].Rows[i]["发出日期"].ToString().Trim();
newDataInTemp.Value11 = ds.Tables[0].Rows[i]["接收单位"].ToString().Trim();
newDataInTemp.Value12 = ds.Tables[0].Rows[i]["接收人"].ToString().Trim();
newDataInTemp.Value13 = ds.Tables[0].Rows[i]["是否需回复"].ToString().Trim();
newDataInTemp.Value14 = ds.Tables[0].Rows[i]["返回五环日期"].ToString().Trim();
newDataInTemp.Value15 = ds.Tables[0].Rows[i]["返回五环份数"].ToString().Trim();
newDataInTemp.Value16 = ds.Tables[0].Rows[i]["下发至单位"].ToString().Trim();
newDataInTemp.Value17 = ds.Tables[0].Rows[i]["下发份数"].ToString().Trim();
newDataInTemp.Value18 = ds.Tables[0].Rows[i]["下发单位接收人"].ToString().Trim();
newDataInTemp.Value19 = ds.Tables[0].Rows[i]["是否存档"].ToString().Trim();
BLL.Sys_DataTempService.AddDataInTemp(newDataInTemp);
}
this.BindGrid();
ShowNotify("数据已导入临时表!", MessageBoxIcon.Success);
}
else
{
ShowNotify("无数据!", MessageBoxIcon.Warning);
return;
}
}
catch (Exception ex)
{
Alert.ShowInTop("'" + ex.Message + "'", MessageBoxIcon.Warning);
}
}
#endregion
#region
/// <summary>
/// 保存审核事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnSave_Click(object sender, EventArgs e)
{
Thread t = new Thread(new ThreadStart(() => { btnSaveMethod(this.CurrUser.LoginProjectId, this.CurrUser.UserId); }));
t.Start();
if (percent.ContainsKey(this.CurrUser.UserId))
{
percent[CurrUser.UserId] = 0;
}
else
{
percent.Add(CurrUser.UserId, 0);
}
PageContext.RegisterStartupScript("printX()");
}
protected void btnRefresh_Click(object sender, EventArgs e)
{
this.BindGrid();
}
protected void btnSaveMethod(string LoginProjectId, string UserId)
{
var units = from x in Funs.DB.Base_Unit
join y in Funs.DB.Project_ProjectUnit on x.UnitId equals y.UnitId
where y.ProjectId == LoginProjectId
select x;
var cNProfessionals = from x in Funs.DB.Base_CNProfessional select x;//专业
var dataInTemp = from x in Funs.DB.Sys_DataInTemp
where x.ProjectId == LoginProjectId && x.UserId == UserId && x.Type == "DataReceivingDoc"
select x;
int okCount = 0;
int i = 0;
int ir = dataInTemp.Count();
string erreMessage = "";
foreach (var tempData in dataInTemp)
{
if (tempData != null)
{
i++;
percent[UserId] = (int)(100 * i / ir);
string errInfo = string.Empty;
var isExitValue = Funs.DB.Comprehensive_DataReceivingDoc.FirstOrDefault(x => x.ProjectId == this.CurrUser.LoginProjectId && x.FileCode == tempData.Value2
&& x.FileName == tempData.Value3);
if (isExitValue == null || this.ckUpdate.Checked)
{
Model.Comprehensive_DataReceivingDoc newData = new Model.Comprehensive_DataReceivingDoc();
if (!string.IsNullOrEmpty(tempData.Value1.Trim()))
{
try
{
newData.ReceiveDate = Funs.GetNewDateTime(tempData.Value1.Trim());
}
catch (Exception)
{
errInfo += "日期格式不正确;";
}
}
else
{
errInfo += "日期为必填项;";
}
if (!string.IsNullOrEmpty(tempData.Value2.Trim()))
{
newData.FileCode = tempData.Value2.Trim();
}
else
{
errInfo += "文件号为必填项;";
}
if (!string.IsNullOrEmpty(tempData.Value3.Trim()))
{
newData.FileName = tempData.Value3.Trim();
}
else
{
errInfo += "文件名称为必填项;";
}
if (!string.IsNullOrEmpty(tempData.Value4.Trim()))
{
newData.FileType = tempData.Value4.Trim();
}
else
{
errInfo += "文件类别为必填项;";
}
if (!string.IsNullOrEmpty(tempData.Value5.Trim()))
{
var professional = cNProfessionals.FirstOrDefault(e => e.ProfessionalName == tempData.Value5.Trim());
if (professional != null)
{
newData.CNProfessionalId = professional.CNProfessionalId;
}
else
{
errInfo += "专业不存在;";
}
}
else
{
errInfo += "专业为必填项;";
}
if (!string.IsNullOrEmpty(tempData.Value6.Trim()))
{
var unit = units.FirstOrDefault(e => e.UnitName == tempData.Value6.Trim());
if (unit != null)
{
newData.SendUnit = unit.UnitId;
}
else
{
errInfo += "发件单位不存在;";
}
}
else
{
errInfo += "发件单位为必填项;";
}
if (!string.IsNullOrEmpty(tempData.Value7.Trim()))//发件人
{
newData.SendMan = tempData.Value7.Trim();
}
else
{
errInfo += "发件人为必填项;";
}
if (!string.IsNullOrEmpty(tempData.Value8.Trim()))//份数
{
try
{
newData.Copies = Funs.GetNewInt(tempData.Value8.Trim());
}
catch (Exception)
{
errInfo += "份数格式不正确;";
}
}
else
{
errInfo += "份数为必填项;";
}
if (!string.IsNullOrEmpty(tempData.Value9.Trim())) //文件处理人
{
newData.DocumentHandler = tempData.Value9.Trim();
}
if (!string.IsNullOrEmpty(tempData.Value10.Trim())) //发出日期
{
try
{
newData.SendDate = Funs.GetNewDateTime(tempData.Value10.Trim());
}
catch (Exception)
{
errInfo += "发出日期格式不正确;";
}
}
if (!string.IsNullOrEmpty(tempData.Value11.Trim()))//接收单位
{
string unitList = string.Empty;
List<string> lists = tempData.Value11.Trim().Split(',').ToList();
if (lists.Count > 0)
{
foreach (var item in lists)
{
var unit = units.FirstOrDefault(x => x.UnitName == item.Trim());
if (unit != null)
{
unitList += unit.UnitId + ",";
}
else
{
errInfo += "接收单位不存在;";
}
}
if (!string.IsNullOrEmpty(unitList))
{
newData.ReceiveUnit = unitList.Substring(0, unitList.LastIndexOf(","));
}
}
}
if (!string.IsNullOrEmpty(tempData.Value12.Trim()))//接收人
{
newData.ReceiveMan = tempData.Value12.Trim();
}
if (tempData.Value13.Trim() == "是") //是否需回复
{
newData.IsReply = true;
}
else
{
newData.IsReply = false;
}
if (!string.IsNullOrEmpty(tempData.Value14.Trim())) //返回五环日期
{
try
{
newData.ReturnWuhuangDate = Funs.GetNewDateTime(tempData.Value14.Trim());
}
catch (Exception)
{
errInfo += "返回五环日期格式不正确;";
}
}
if (!string.IsNullOrEmpty(tempData.Value15.Trim()))//返回五环份数
{
try
{
newData.RetrunWuhuangCopies = Funs.GetNewInt(tempData.Value15.Trim());
}
catch (Exception)
{
errInfo += "返回五环份数格式不正确;";
}
}
if (!string.IsNullOrEmpty(tempData.Value16.Trim()))//下发至单位
{
string unitLists = string.Empty;
List<string> lists = tempData.Value16.Trim().Split(',').ToList();
if (lists.Count > 0)
{
foreach (var item in lists)
{
var unit = units.FirstOrDefault(x => x.UnitName == item.Trim());
if (unit != null)
{
unitLists += unit.UnitId + ",";
}
else
{
errInfo += "下发至单位不存在;";
}
}
if (!string.IsNullOrEmpty(unitLists))
{
newData.IssueToUnit = unitLists.Substring(0, unitLists.LastIndexOf(","));
}
}
}
if (!string.IsNullOrEmpty(tempData.Value17.Trim())) //下发份数
{
try
{
newData.IssueCopies = Funs.GetNewInt(tempData.Value17.Trim());
}
catch (Exception)
{
errInfo += "下发份数格式不正确;";
}
}
if (!string.IsNullOrEmpty(tempData.Value18.Trim()))//下发单位接收人
{
newData.IssueUnitReceiver = tempData.Value18.Trim();
}
if (!string.IsNullOrEmpty(tempData.Value19.Trim())) //是否存档
{
if (tempData.Value19.Trim() == "是")
{
newData.IsOnFile = true;
}
else
{
newData.IsOnFile = false;
}
}
if (string.IsNullOrEmpty(errInfo)) ////所有信息正确的话 这插入管线焊口
{
newData.ProjectId = this.CurrUser.LoginProjectId;
var data = BLL.DataReceivingDocService.GetDataReceivingDocByCodeAndName(newData.FileCode, newData.FileName);
if (data == null)
{
newData.DataReceivingDocId = SQLHelper.GetNewID(typeof(Model.Comprehensive_DataReceivingDoc));
BLL.DataReceivingDocService.AddDataReceivingDoc(newData);
}
else
{
newData.DataReceivingDocId = data.DataReceivingDocId;
BLL.DataReceivingDocService.UpdateDataReceivingDoc(newData);
}
BLL.Sys_DataTempService.DeleteDataInTempByDataInTempID(tempData.TempId);
okCount++;
}
}
else
{
errInfo = "该条记录已存在于资料收发文登记记录表中。";
}
if (!string.IsNullOrEmpty(errInfo))
{
tempData.ToopValue = errInfo;
BLL.Sys_DataTempService.UpdateDataInTemp(tempData);
erreMessage += errInfo + ";";
}
}
}
}
#endregion
#region
/// 导出按钮
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnOut_Click(object sender, EventArgs e)
{
Response.ClearContent();
string filename = Funs.GetNewFileName();
Response.AddHeader("content-disposition", "attachment; filename=" + System.Web.HttpUtility.UrlEncode("资料收发文登记记录导入模板" + filename, System.Text.Encoding.UTF8) + ".xlsx");
Response.ContentType = "application/excel";
Response.ContentEncoding = System.Text.Encoding.UTF8;
Response.Write(GetGridTableHtml(Grid1));
Response.End();
}
#endregion
}
}