xinjiang/SGGL/FineUIPro.Web/HJGL/CheckManage/CheckManageImport.aspx.cs

1407 lines
58 KiB
C#

using BLL;
using BLL.Common;
using FineUIPro.Web.HJGL.WeldingManage;
using Microsoft.JScript.Vsa;
using Model;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.OleDb;
using System.Data.SqlClient;
using System.IO;
using System.Linq;
using System.Threading;
namespace FineUIPro.Web.HJGL.CheckManage
{
public partial class CheckManageImport : PageBase
{
#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 HJGL_CheckImportTemp "
+ @" WHERE ProjectId=@ProjectId AND UserId=@UserId ";
List<SqlParameter> listStr = new List<SqlParameter>();
listStr.Add(new SqlParameter("@ProjectId", this.CurrUser.LoginProjectId));
listStr.Add(new SqlParameter("@UserId", this.CurrUser.UserId));
//if (!string.IsNullOrEmpty(this.txtValue1.Text.Trim()))
//{
// strSql += " AND Value1 LIKE @Value1";
// listStr.Add(new SqlParameter("@Value1", "%" + this.txtValue1.Text.Trim() + "%"));
//}
//if (!string.IsNullOrEmpty(this.txtValue2.Text.Trim()))
//{
// strSql += " AND Value2 LIKE @Value2";
// listStr.Add(new SqlParameter("@Value2", "%" + this.txtValue2.Text.Trim() + "%"));
//}
//if (!string.IsNullOrEmpty(this.txtValue3.Text.Trim()))
//{
// strSql += " AND Value3 LIKE @Value3";
// listStr.Add(new SqlParameter("@Value3", "%" + this.txtValue3.Text.Trim() + "%"));
//}
//if (!string.IsNullOrEmpty(this.txtValue4.Text.Trim()))
//{
// strSql += " AND Value4 LIKE @Value4";
// listStr.Add(new SqlParameter("@Value4", "%" + this.txtValue4.Text.Trim() + "%"));
//}
//if (!string.IsNullOrEmpty(this.txtToopValue.Text.Trim()))
//{
// strSql += " AND ToopValue LIKE @ToopValue";
// listStr.Add(new SqlParameter("@ToopValue", "%" + this.txtToopValue.Text.Trim() + "%"));
//}
SqlParameter[] parameter = listStr.ToArray();
DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter);
// 2.获取当前分页数据
//var table = this.GetPagedDataTable(Grid1, tb1);
Grid1.RecordCount = tb.Rows.Count;
//tb = GetFilteredTable(Grid1.FilteredData, tb);
var table = this.GetPagedDataTable(Grid1, tb);
Grid1.DataSource = table;
Grid1.DataBind();
var dataInTempAll = from x in Funs.DB.HJGL_CheckImportTemp
where x.ProjectId == this.CurrUser.LoginProjectId && x.UserId == this.CurrUser.UserId
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;
}
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("CheckManageImportEdit.aspx?TempId={0}", Grid1.SelectedRowID, "维护 - ")));
}
#endregion
#region
/// <summary>
/// 导入信息编辑
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnMenuEdit_Click(object sender, EventArgs e)
{
if (Grid1.SelectedRowIndexArray.Length == 0)
{
Alert.ShowInTop("请选择一条记录!", MessageBoxIcon.Warning);
return;
}
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("CheckManageImportEdit.aspx?TempId={0}", Grid1.SelectedRowID, "维护 - ")));
}
/// <summary>
/// 删除按钮
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnMenuDelete_Click(object sender, EventArgs e)
{
if (Grid1.SelectedRowIndexArray.Length == 0)
{
Alert.ShowInTop("请选择一条记录!", MessageBoxIcon.Warning);
return;
}
foreach (int rowIndex in Grid1.SelectedRowIndexArray)
{
string rowID = Grid1.DataKeys[rowIndex][0].ToString();
BLL.CheckManageImportTempService.DeleteDataInTempByDataInTempID(rowID);
//BLL.Sys_LogService.AddLog(Const.System_7, this.CurrUser.LoginProjectId, this.CurrUser.UserId, "删除导入信息");
}
ShowNotify("删除成功!", MessageBoxIcon.Success);
this.BindGrid();
}
#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 imgbtnImport_Click(object sender, EventArgs e)
{
try
{
if (this.FileExcel.HasFile == false)
{
Response.Write("<script>alert('请您选择Excel文件')</script> ");
//for (int i = 0; i < 10; i++)
//{
// Response.Flush();
// Response.Write("<script>alert('请您选择Excel文件')</script> ");
// System.Threading.Thread.Sleep(5000);
// Response.Flush();
//}
return;
}
string IsXls = Path.GetExtension(FileExcel.FileName).ToString().Trim().ToLower();
if (IsXls != ".xls")
{
Response.Write("<script>alert('只可以选择Excel文件')</script>");
return;
}
string rootPath = Server.MapPath("~/");
string initFullPath = rootPath + Const.ExcelUrl;
if (!Directory.Exists(initFullPath))
{
Directory.CreateDirectory(initFullPath);
}
string fileUrl = initFullPath + BLL.Funs.GetNewFileName() + IsXls;
this.FileExcel.PostedFile.SaveAs(fileUrl);
//string oleDBConnString = String.Empty;
//oleDBConnString = "Provider=Microsoft.Jet.OLEDB.4.0;";
//oleDBConnString += "Data Source=";
//oleDBConnString += fileUrl;
//oleDBConnString += ";Extended Properties=Excel 8.0;";
////oleDBConnString = "Provider=Microsoft.ACE.OLEDB.12.0;";
////oleDBConnString += "Data Source=";
////oleDBConnString += fileUrl;
////oleDBConnString += ";Extended Properties='Excel 8.0;HDR=Yes;IMEX=1;'";
//OleDbConnection oleDBConn = null;
//OleDbDataAdapter oleAdMaster = null;
//DataTable m_tableName = new DataTable();
//DataSet ds = new DataSet();
//oleDBConn = new OleDbConnection(oleDBConnString);
//oleDBConn.Open();
//m_tableName = oleDBConn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
//if (m_tableName != null && m_tableName.Rows.Count > 0)
//{
// m_tableName.TableName = m_tableName.Rows[0]["TABLE_NAME"].ToString().Trim();
//}
//string sqlMaster;
//sqlMaster = " SELECT * FROM [" + m_tableName.TableName + "]";
//oleAdMaster = new OleDbDataAdapter(sqlMaster, oleDBConn);
//oleAdMaster.SelectCommand.CommandTimeout = 3600;
//oleAdMaster.Fill(ds, "m_tableName");
//oleAdMaster.Dispose();
//oleDBConn.Close();
//oleDBConn.Dispose();
//this.AddDatasetToSQL(ds.Tables[0]);
DataTable dt = NPOIHelper.ExcelToDataTable1(fileUrl);
this.AddDatasetToSQL(dt);
if (!string.IsNullOrEmpty(fileUrl) && System.IO.File.Exists(fileUrl))
{
System.IO.File.Delete(fileUrl);//删除上传的XLS文件
}
this.FileExcel.Reset();
}
catch (Exception ex)
{
ShowNotify(ex.Message, MessageBoxIcon.Warning);
return;
}
}
#endregion
#region Dataset的数据导入数据库
/// <summary>
/// 将Dataset的数据导入数据库
/// </summary>
/// <param name="pds">数据集</param>
/// <param name="Cols">数据集列数</param>
/// <returns></returns>
private void AddDatasetToSQL(DataTable pds)
{
if (pds != null && pds.Rows.Count > 0)
{
int ir = pds.Rows.Count;
List<Model.HJGL_CheckImportTemp> newDataInTempList = new List<Model.HJGL_CheckImportTemp>();
for (int i = 0; i < ir; i++)
{
if (!string.IsNullOrEmpty(pds.Rows[i][3].ToString()))
{
Model.HJGL_CheckImportTemp newDataInTemp = new Model.HJGL_CheckImportTemp();
newDataInTemp.TempId = SQLHelper.GetNewID(typeof(Model.Sys_DataInTemp));
newDataInTemp.ProjectId = this.CurrUser.LoginProjectId;
newDataInTemp.UserId = this.CurrUser.UserId;
newDataInTemp.Time = System.DateTime.Now;
newDataInTemp.RowNo = i + 2;
newDataInTemp.Value1 = pds.Rows[i][0].ToString().Trim();//单位代号
newDataInTemp.Value2 = pds.Rows[i][1].ToString().Trim();//工区代号
newDataInTemp.Value3 = pds.Rows[i][2].ToString().Trim();//管线代号
newDataInTemp.Value4 = pds.Rows[i][3].ToString().Trim();//焊口代号
newDataInTemp.Value5 = pds.Rows[i][4].ToString().Trim();//点口委托日期
newDataInTemp.Value6 = pds.Rows[i][5].ToString().Trim();//委托单号
newDataInTemp.Value7 = pds.Rows[i][6].ToString().Trim();//检测单位名称
newDataInTemp.Value8 = pds.Rows[i][7].ToString().Trim();//检测方法代号
newDataInTemp.Value9 = pds.Rows[i][8].ToString().Trim();//检测方法代号
newDataInTemp.Value10 = pds.Rows[i][9].ToString().Trim();//合格等级(I\II\III\IV\V)
newDataInTemp.Value11 = pds.Rows[i][10].ToString().Trim();//检测(拍片)日期
newDataInTemp.Value12 = pds.Rows[i][11].ToString().Trim();//报告日期
newDataInTemp.Value13 = pds.Rows[i][12].ToString().Trim();//返修位置
newDataInTemp.Value14 = pds.Rows[i][13].ToString().Trim();//拍片总数
newDataInTemp.Value15 = pds.Rows[i][14].ToString().Trim(); //合格片数
newDataInTemp.Value16 = pds.Rows[i][15].ToString().Trim();//是否合格(合格/不合格)
newDataInTemp.Value17 = pds.Rows[i][16].ToString().Trim();//缺陷定义
newDataInTemp.Value18 = pds.Rows[i][17].ToString().Trim(); //胶片规格
newDataInTemp.Value19 = pds.Rows[i][18].ToString().Trim(); //缺陷长度
newDataInTempList.Add(newDataInTemp);
}
}
BLL.CheckManageImportTempService.AddDataInTemp(newDataInTempList);
this.BindGrid();
ShowNotify("数据已导入临时表!", MessageBoxIcon.Success);
}
else
{
Alert.ShowInTop("导入数据为空!", MessageBoxIcon.Success);
return;
}
}
#endregion
#region
/// <summary>
/// 保存审核事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnSave_Click(object sender, EventArgs e)
{
btnSaveMethod(this.CurrUser.LoginProjectId, this.CurrUser.UserId);
}
protected void btnSaveCheck_Click(object sender, EventArgs e)
{
btnSaveCheckMethod(this.CurrUser.LoginProjectId, this.CurrUser.UserId);
}
protected void btnRefresh_Click(object sender, EventArgs e)
{
this.BindGrid();
}
protected void btnSaveMethod(string LoginProjectId, string UserId)
{
//beginProgress();
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 isos = from x in Funs.DB.PW_IsoInfo
where x.ProjectId == CurrUser.LoginProjectId
select x;
var jointInfos = from x in Funs.DB.PW_JointInfo
where x.ProjectId == CurrUser.LoginProjectId
select x;
var workAreas = from x in Funs.DB.ProjectData_WorkArea where x.ProjectId == LoginProjectId select x;
var acceptGrades = BLL.TrustManageEditService.GetAcceptGradeList();//合格等级(I\II\III\IV\V)
var detectionTypes = from x in Funs.DB.Base_DetectionType select x;
var dataInTemp = from x in Funs.DB.HJGL_CheckImportTemp
where x.ProjectId == LoginProjectId && x.UserId == UserId
select x;
int okCount = 0;
int ir = dataInTemp.Count();
string erreMessage = "";
foreach (var tempData in dataInTemp)
{
if (tempData != null)
{
string errInfo = string.Empty;
string unitId = "";
string isoId = "";
if (!string.IsNullOrEmpty(tempData.Value1))
{
var unit = units.FirstOrDefault(x => x.UnitCode == tempData.Value1);
if (unit == null)
{
errInfo += "单位代码[" + tempData.Value1 + "]不存在;";
}
else
{
unitId = unit.UnitId;
}
}
else
{
errInfo += "单位代码为必填项;";
}
if (!string.IsNullOrEmpty(tempData.Value2) && !string.IsNullOrEmpty(unitId))
{
var workArea = workAreas.FirstOrDefault(x => x.WorkAreaCode == tempData.Value2 && x.UnitId == unitId);
if (workArea == null)
{
errInfo += "工区编号[" + tempData.Value2 + "]该单位下不存在;";
}
}
else
{
errInfo += "工区编号为必填项;";
}
if (string.IsNullOrEmpty(tempData.Value3))
{
errInfo += "管线代号此项为必填项!";
}
else
{
var iso = isos.FirstOrDefault(x => x.UnitId == unitId && x.ISO_IsoNo == tempData.Value3);
if (iso == null)
{
errInfo += "管线代号[" + tempData.Value3 + "]该单位下不存在!";
}
else
{
isoId = iso.ISO_ID;
}
}
if (string.IsNullOrEmpty(tempData.Value4))
{
errInfo += "焊口代号此项为必填项!";
}
else
{
var jointInfo = jointInfos.FirstOrDefault(x => x.ISO_ID == isoId && x.JOT_JointNo == tempData.Value4);
if (jointInfo == null)
{
errInfo += "焊口代号[" + tempData.Value4 + "]该管线下不存在!";
}
else if (!string.IsNullOrEmpty(jointInfo.PW_PointID) && !string.IsNullOrEmpty(tempData.Value5))
{
errInfo += "焊口代号[" + tempData.Value4 + "]已点!";
}
else if (string.IsNullOrEmpty(tempData.Value5))
{
errInfo += "点口委托日期此项为必填项!";
}
}
if (string.IsNullOrEmpty(tempData.Value6))
{
errInfo += "委托单号此项为必填项!";
}
if (string.IsNullOrEmpty(tempData.Value7))
{
errInfo += "检测单位名称此项为必填项!";
}
else
{
var unit = units.FirstOrDefault(x => x.UnitName == tempData.Value7);
if (unit == null)
{
errInfo += "检测单位名称此项不存在!";
}
}
if (string.IsNullOrEmpty(tempData.Value8))
{
errInfo += "检测代号此项为必填项!";
}
if (string.IsNullOrEmpty(tempData.Value9))
{
errInfo += "检测方法代号此项为必填项!";
}
else
{
var detectionType = detectionTypes.FirstOrDefault(x => x.DetectionTypeCode == tempData.Value9);
if (detectionType == null)
{
errInfo += "检测方法代号此项不存在!";
}
if ("RT" == tempData.Value9)
{
if (string.IsNullOrEmpty(tempData.Value14))
{
errInfo += "拍片总数此项为必填项!";
}
if (string.IsNullOrEmpty(tempData.Value15))
{
errInfo += "合格片数此项为必填项!";
}
}
}
if (string.IsNullOrEmpty(tempData.Value10))
{
errInfo += "合格等级此项为必填项!";
}
else
{
var acceptGrade = acceptGrades.FirstOrDefault(x => x.Text == tempData.Value10);
if (acceptGrade == null)
{
errInfo += "合格等级此项不存在!";
}
}
if (string.IsNullOrEmpty(tempData.Value16))
{
errInfo += "是否合格此项为必填项!";
}
if (!string.IsNullOrEmpty(errInfo))
{
tempData.ToopValue = errInfo;
BLL.CheckManageImportTempService.UpdateDataInTemp(tempData);
erreMessage += errInfo + ";";
}
}
}
if (dataInTemp.Where(x => x.ToopValue != null && x.ToopValue != "").Select(x => x.ToopValue).Count() > 0)
{
this.BindGrid();
return;
}
//新增点口数据
List<Model.BO_Point> points = new List<Model.BO_Point>();
var dataInUnits = dataInTemp.Select(x => x.Value1).Distinct();
foreach (var unitCode in dataInUnits)
{
var dataInWorkAreas = dataInTemp.Where(x => x.Value1 == unitCode).Select(x => x.Value2).Distinct();
foreach (var WorkArea in dataInWorkAreas)
{
var dataInPointDates = dataInTemp.Where(x => x.Value1 == unitCode && x.Value2 == WorkArea && x.Value5 != null && x.Value5 != "").Select(x => x.Value5).Distinct();
foreach (var pointDate in dataInPointDates)
{
Model.BO_Point point = new Model.BO_Point();
string date = pointDate.Trim().Replace("-", "").Replace("/", "");
point.PW_PointNo = BLL.SQLHelper.RunProcNewId("SpGetNewCode3ByProjectPrefix", "dbo.BO_Point", "PW_PointNo", this.CurrUser.LoginProjectId, date + "-");
point.PW_PointID = Guid.NewGuid().ToString();
var u = units.FirstOrDefault(x => x.UnitCode == unitCode);
if (u != null)
{
point.UnitId = u.UnitId;
}
point.PW_PointDate = DateTime.Parse(pointDate);
point.ProjectId = this.CurrUser.LoginProjectId;
var w = workAreas.FirstOrDefault(x => x.WorkAreaCode == WorkArea);
if (w != null)
{
point.InstallationId = w.InstallationId;
}
point.PW_TablerDate = DateTime.Now;
point.PW_Tabler = this.CurrUser.UserId;
Funs.DB.BO_Point.InsertOnSubmit(point);
var dataInJoints = dataInTemp.Where(x => x.Value1 == unitCode && x.Value2 == WorkArea && x.Value5 == pointDate).Select(x => new { x.Value3, x.Value4 }).Distinct();
foreach (var joint in dataInJoints)
{
var isoTemp = isos.Where(x => x.ISO_IsoNo == joint.Value3).FirstOrDefault();
if (isoTemp != null)
{
var jointTemp = jointInfos.Where(x => x.JOT_JointNo == joint.Value4 && x.ISO_ID == isoTemp.ISO_ID);
if (jointTemp != null)
{
foreach (var jot in jointTemp)
{
jot.PW_PointID = point.PW_PointID;
}
}
}
}
}
}
}
//新增委托
try
{
var dataInTrusts = dataInTemp.Select(x => x.Value6).Distinct();
List<Model.CH_Trust> newTrusts = new List<Model.CH_Trust>();
List<Model.CH_TrustItem> TrustItem = new List<Model.CH_TrustItem>();
foreach (var trust in dataInTrusts)
{
var firstDataTemp = dataInTemp.FirstOrDefault(x => x.Value6 == trust);
Model.CH_Trust newTrust = new Model.CH_Trust();
newTrust.CH_TrustID = Guid.NewGuid().ToString();
newTrust.ProjectId = this.CurrUser.LoginProjectId;
newTrust.CH_TrustCode = firstDataTemp.Value6;
var iso = isos.FirstOrDefault(x => x.ISO_IsoNo == firstDataTemp.Value3);
var unit = units.FirstOrDefault(x => x.UnitCode == firstDataTemp.Value1);
var workArea = workAreas.FirstOrDefault(x => x.WorkAreaCode == firstDataTemp.Value2 && x.UnitId == unit.UnitId);
var joint = jointInfos.FirstOrDefault(x => x.ISO_ID == iso.ISO_ID && x.JOT_JointNo == firstDataTemp.Value4);
if (joint != null)
{
if (unit != null)
{
newTrust.CH_TrustUnit = unit.UnitId;
}
if (workArea != null)
{
newTrust.InstallationId = workArea.InstallationId;
}
newTrust.CH_TrustDate = Funs.GetNewDateTime(firstDataTemp.Value5);
if (iso != null)
{
newTrust.CH_NDTRate = iso.DetectionRateId;
}
newTrust.CH_TrustType = "1";
var detectionType = detectionTypes.FirstOrDefault(x => x.DetectionTypeCode == firstDataTemp.Value9);
if (detectionType != null)
{
newTrust.CH_NDTMethod = detectionType.DetectionTypeId;
}
// newTrust.CH_TrustMan = this.CurrUser.UserId;
//newTrust.CH_ItemName = this.txtCH_ItemName.Text.Trim();
var acceptGrade = acceptGrades.FirstOrDefault(x => x.Text == firstDataTemp.Value10);
newTrust.CH_AcceptGrade = acceptGrade.Value;
newTrust.CH_Tabler = this.CurrUser.UserId;
newTrust.CH_SlopeType = joint.JST_ID;
string type = detectionType.DetectionTypeCode.Split('\\')[0];
if (type != null)
switch (type)
{
case "RT":
// RT采用标准--NB / T47013.2 - 2015 II级
//UT采用标准--NB / T47013.3 - 2015 I级
//MT采用标准--NB / T47013.4 - 2015 I级
//PT采用标准--NB / T47013.5 - 2015 I级
// TOFD采用标准--NB / T47013.10 - 2015 II级
//3D - TFM--NB / T47013.15 - 2021 II级
if (acceptGrade != null)
{
newTrust.CH_NDTCriteria = "NB/T47013.2-2015/AB级" + "(" + acceptGrade.Text + ")";
}
else
{
newTrust.CH_NDTCriteria = "NB/T47013.2-2015/AB级";
}
break;
case "UT":
if (acceptGrade != null)
{
newTrust.CH_NDTCriteria = "NB/T47013.3-2015/B级" + "(" + acceptGrade.Text + ")";
}
else
{
newTrust.CH_NDTCriteria = "NB/T47013.3-2015/B级";
}
break;
case "MT":
if (acceptGrade != null)
{
newTrust.CH_NDTCriteria = "NB/T47013.4-2015" + "(" + acceptGrade.Text + ")";
}
else
{
newTrust.CH_NDTCriteria = "NB/T47013.4-2015";
}
break;
case "PT":
if (acceptGrade != null)
{
newTrust.CH_NDTCriteria = "NB/T47013.5-2015" + "(" + acceptGrade.Text + ")";
}
else
{
newTrust.CH_NDTCriteria = "NB/T47013.5-2015";
}
break;
case "TOFD":
if (acceptGrade != null)
{
newTrust.CH_NDTCriteria = "NB/T47013.10-2015/B级" + "(" + acceptGrade.Text + ")";
}
else
{
newTrust.CH_NDTCriteria = "NB/T47013.10-2015/B级";
}
break;
case "3D-TFM":
if (acceptGrade != null)
{
newTrust.CH_NDTCriteria = "NB/T47013.15-2015" + "(" + acceptGrade.Text + ")";
}
else
{
newTrust.CH_NDTCriteria = "NB/T47013.15-2015";
}
break;
}
newTrust.CH_WeldMethod = joint.WME_ID;
var checkUnit = units.FirstOrDefault(x => x.UnitName == firstDataTemp.Value7);
if (checkUnit != null)
{
newTrust.CH_CheckUnit = checkUnit.UnitId;
}
newTrust.CH_RequestDate = Funs.GetNewDateTime(firstDataTemp.Value5);
newTrust.CH_AuditDate = DateTime.Now;
newTrust.CH_AuditMan = this.CurrUser.UserId;
newTrusts.Add(newTrust);
Funs.DB.CH_Trust.InsertOnSubmit(newTrust);
}
var allJoints = dataInTemp.Where(x => x.Value6 == trust);
if (allJoints != null)
{
foreach (var allJoint in allJoints)
{
var isotemp = isos.FirstOrDefault(x => x.ISO_IsoNo == allJoint.Value3);
if (isotemp != null)
{
var joints = jointInfos.FirstOrDefault(x => x.ISO_ID == isotemp.ISO_ID && x.JOT_JointNo == allJoint.Value4);
if (joints != null)
{
Model.CH_TrustItem newitem = new Model.CH_TrustItem();
newitem.CH_TrustID = newTrust.CH_TrustID;
newitem.JOT_ID = joints.JOT_ID;
newitem.CH_TrustItemID = Guid.NewGuid().ToString();
TrustItem.Add(newitem);
Funs.DB.CH_TrustItem.InsertOnSubmit(newitem);
if (String.IsNullOrEmpty(joints.JOT_TrustFlag) || joints.JOT_TrustFlag == "00")//未下委托
{
joints.JOT_TrustFlag = "01";
}
else if (joints.JOT_TrustFlag == "01")//一次委托,未审核
{
joints.JOT_TrustFlag = "02";
}
else if (joints.JOT_TrustFlag == "02")//一次委托,已审核
{
joints.JOT_TrustFlag = "11";
}
else if (joints.JOT_TrustFlag == "11")//二次委托,未审核
{
joints.JOT_TrustFlag = "12";
}
else if (joints.JOT_TrustFlag == "12")//二次委托,已审核
{
joints.JOT_TrustFlag = "21";
}
else if (joints.JOT_TrustFlag == "21")//三次委托,未审核
{
joints.JOT_TrustFlag = "22";//三次委托,已审核
}
}
}
}
}
}
var dataInChecks = dataInTemp.Select(x => x.Value8).Distinct();
foreach (var checkCode in dataInChecks)
{
var firstDataTemp = dataInTemp.FirstOrDefault(x => x.Value8 == checkCode);
var trust = newTrusts.FirstOrDefault(x => x.CH_TrustCode == firstDataTemp.Value6);
if (trust != null)
{
Model.CH_Check check = new Model.CH_Check();
check.CHT_CheckID = Guid.NewGuid().ToString();
check.ProjectId = this.CurrUser.LoginProjectId;
check.CHT_CheckCode = checkCode;
check.CH_TrustID = trust.CH_TrustID;
check.UnitId = trust.CH_TrustUnit;
check.InstallationId = trust.InstallationId;
if (!string.IsNullOrEmpty(firstDataTemp.Value11))
{
check.CHT_CheckDate = Funs.GetNewDateTime(firstDataTemp.Value11);
}
// check.CHT_CheckType = this.txtCheckType.Text.Trim();
check.CHT_Tabler = this.CurrUser.UserId;
check.CHT_TableDate = DateTime.Now;
check.CHT_AuditMan = this.CurrUser.UserId;
check.CHT_AuditDate = DateTime.Now;
// check.CHT_CheckMan = this.ddlCheckMan.SelectedValue;
check.ContractualUnits = trust.CH_CheckUnit;
Funs.DB.CH_Check.InsertOnSubmit(check);
var allCheckData = dataInTemp.Where(x => x.Value8 == checkCode);
foreach (var allCheck in allCheckData)
{
var isotemp = isos.FirstOrDefault(x => x.ISO_IsoNo == allCheck.Value3);
var joint = jointInfos.FirstOrDefault(x => x.ISO_ID == isotemp.ISO_ID && x.JOT_JointNo == allCheck.Value4);
var detectionType = detectionTypes.FirstOrDefault(x => x.DetectionTypeCode == allCheck.Value9);
var temptrust = newTrusts.Where(x => x.CH_TrustCode == allCheck.Value6).FirstOrDefault();
var trustItem = TrustItem.FirstOrDefault(x => x.CH_TrustID == temptrust.CH_TrustID && x.JOT_ID == joint.JOT_ID);
if (trustItem != null)
{
Model.CH_CheckItem checkitem = new Model.CH_CheckItem();
checkitem.CHT_CheckItemID = Guid.NewGuid().ToString();
checkitem.CHT_CheckID = check.CHT_CheckID;
checkitem.JOT_ID = joint.JOT_ID;
checkitem.CH_TrustItemID = trustItem.CH_TrustItemID;
checkitem.CHT_CheckMethod = detectionType.DetectionTypeId;
//checkitem.CHT_RequestDate = int.Parse(allCheck.Value14);
checkitem.CHT_RepairLocation = allCheck.Value13;
if (!string.IsNullOrEmpty(allCheck.Value14))
{
try
{
checkitem.CHT_TotalFilm = int.Parse(allCheck.Value14);
}
catch (Exception e) { }
}
if (!string.IsNullOrEmpty(allCheck.Value15))
{
try
{
checkitem.CHT_PassFilm = int.Parse(allCheck.Value15);
}
catch (Exception e) { }
}
checkitem.CHT_CheckResult = allCheck.Value16;
//checkitem.CHT_CheckNo = allCheck.Value8;
if (!string.IsNullOrEmpty(allCheck.Value11))
{
checkitem.CHT_FilmDate = Funs.GetNewDateTime(allCheck.Value11);
}
if (!string.IsNullOrEmpty(allCheck.Value12))
{
checkitem.CHT_ReportDate = Funs.GetNewDateTime(allCheck.Value12);
}
checkitem.FilmSpecifications = allCheck.Value18;
if (!string.IsNullOrEmpty(allCheck.Value19))
{
try
{
checkitem.DefectLength = decimal.Parse(allCheck.Value19);
}
catch (Exception e) { }
}
if (!string.IsNullOrEmpty(joint.Extend_Length))
{
checkitem.ExtendingRice = Decimal.Parse(joint.Extend_Length);
}
checkitem.Defects_Definition = allCheck.Value17;
Funs.DB.CH_CheckItem.InsertOnSubmit(checkitem);
if (string.IsNullOrEmpty(joint.JOT_CheckFlag) || joint.JOT_CheckFlag == "00")
{
joint.JOT_CheckFlag = "01";
}
else if (joint.JOT_CheckFlag == "01")//一次检测,未审核
{
joint.JOT_CheckFlag = "02";
}
else if (joint.JOT_CheckFlag == "02")//一次检测,已审核
{
joint.JOT_CheckFlag = "11";
}
else if (joint.JOT_CheckFlag == "11")//二次检测,未审核
{
joint.JOT_CheckFlag = "12";
}
else if (joint.JOT_CheckFlag == "12")//二次检测,已审核
{
joint.JOT_CheckFlag = "21";
}
else if (joint.JOT_CheckFlag == "21")//三次检测,未审核
{
joint.JOT_CheckFlag = "22";//三次检测,已审核
}
}
}
}
}
Funs.DB.HJGL_CheckImportTemp.DeleteAllOnSubmit(dataInTemp);
Funs.DB.SubmitChanges();
this.BindGrid();
}
catch (Exception e)
{
ErrLogInfo.WriteLog("新增检测记录错误");
}
}
protected void btnSaveCheckMethod(string LoginProjectId, string UserId)
{
//beginProgress();
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 isos = from x in Funs.DB.PW_IsoInfo
where x.ProjectId == CurrUser.LoginProjectId
select x;
var jointInfos = from x in Funs.DB.PW_JointInfo
where x.ProjectId == CurrUser.LoginProjectId
select x;
var workAreas = from x in Funs.DB.ProjectData_WorkArea where x.ProjectId == LoginProjectId select x;
var acceptGrades = BLL.TrustManageEditService.GetAcceptGradeList();//合格等级(I\II\III\IV\V)
var detectionTypes = from x in Funs.DB.Base_DetectionType select x;
var dataInTemp = from x in Funs.DB.HJGL_CheckImportTemp
where x.ProjectId == LoginProjectId && x.UserId == UserId
select x;
int okCount = 0;
int ir = dataInTemp.Count();
string erreMessage = "";
PW_JointInfo jointInfo=null;
foreach (var tempData in dataInTemp)
{
jointInfo = null;
if (tempData != null)
{
try
{
string errInfo = string.Empty;
string unitId = "";
string isoId = "";
if (!string.IsNullOrEmpty(tempData.Value1))
{
var unit = units.FirstOrDefault(x => x.UnitCode == tempData.Value1);
if (unit == null)
{
errInfo += "单位代码[" + tempData.Value1 + "]不存在;";
}
else
{
unitId = unit.UnitId;
}
}
else
{
errInfo += "单位代码为必填项;";
}
if (!string.IsNullOrEmpty(tempData.Value2) && !string.IsNullOrEmpty(unitId))
{
var workArea = workAreas.FirstOrDefault(x => x.WorkAreaCode == tempData.Value2 && x.UnitId == unitId);
if (workArea == null)
{
errInfo += "工区编号[" + tempData.Value2 + "]该单位下不存在;";
}
}
else
{
errInfo += "工区编号为必填项;";
}
if (string.IsNullOrEmpty(tempData.Value3))
{
errInfo += "管线代号此项为必填项!";
}
else
{
var iso = isos.FirstOrDefault(x => x.UnitId == unitId && x.ISO_IsoNo == tempData.Value3);
if (iso == null)
{
errInfo += "管线代号[" + tempData.Value3 + "]该单位下不存在!";
}
else
{
isoId = iso.ISO_ID;
}
}
if (string.IsNullOrEmpty(tempData.Value4))
{
errInfo += "焊口代号此项为必填项!";
}
else
{
jointInfo = jointInfos.FirstOrDefault(x => x.ISO_ID == isoId && x.JOT_JointNo == tempData.Value4);
if (jointInfo == null)
{
errInfo += "焊口代号[" + tempData.Value4 + "]该管线下不存在!";
}
}
if (string.IsNullOrEmpty(tempData.Value6))
{
errInfo += "委托单号此项为必填项!";
}
else
{
var trust = Funs.DB.CH_Trust.FirstOrDefault(x => x.ProjectId == CurrUser.LoginProjectId && x.CH_TrustCode == tempData.Value6);
if (trust == null)
{
errInfo += "委托单号[" + tempData.Value6 + "]不存在!";
}
else
{
if (jointInfo != null)
{
var cH_TrustItem = Funs.DB.CH_TrustItem.FirstOrDefault(x => x.CH_TrustID == trust.CH_TrustID && x.JOT_ID == jointInfo.JOT_ID);
if (cH_TrustItem == null)
{
errInfo += "委托单号[" + tempData.Value6 + "]下,不存在焊口" + jointInfo.JOT_JointNo + "不存在!";
}
}
}
}
if (string.IsNullOrEmpty(tempData.Value7))
{
errInfo += "检测单位名称此项为必填项!";
}
else
{
var unit = units.FirstOrDefault(x => x.UnitName == tempData.Value7);
if (unit == null)
{
errInfo += "检测单位名称此项不存在!";
}
}
if (string.IsNullOrEmpty(tempData.Value8))
{
errInfo += "检测代号此项为必填项!";
}
if (string.IsNullOrEmpty(tempData.Value9))
{
errInfo += "检测方法代号此项为必填项!";
}
else
{
var detectionType = detectionTypes.FirstOrDefault(x => x.DetectionTypeCode == tempData.Value9);
if (detectionType == null)
{
errInfo += "检测方法代号此项不存在!";
}
if ("RT" == tempData.Value9)
{
if (string.IsNullOrEmpty(tempData.Value14))
{
errInfo += "拍片总数此项为必填项!";
}
if (string.IsNullOrEmpty(tempData.Value15))
{
errInfo += "合格片数此项为必填项!";
}
}
}
if (string.IsNullOrEmpty(tempData.Value10))
{
errInfo += "合格等级此项为必填项!";
}
else
{
var acceptGrade = acceptGrades.FirstOrDefault(x => x.Text == tempData.Value10);
if (acceptGrade == null)
{
errInfo += "合格等级此项不存在!";
}
}
if (string.IsNullOrEmpty(tempData.Value16))
{
errInfo += "是否合格此项为必填项!";
}
if (!string.IsNullOrEmpty(errInfo))
{
tempData.ToopValue = errInfo;
BLL.CheckManageImportTempService.UpdateDataInTemp(tempData);
erreMessage += errInfo + ";";
}
}
catch (Exception e)
{
tempData.ToopValue = e.Message;
BLL.CheckManageImportTempService.UpdateDataInTemp(tempData);
erreMessage += e.Message + ";";
}
}
}
if (dataInTemp.Where(x => x.ToopValue != null && x.ToopValue != "").Select(x => x.ToopValue).Count() > 0)
{
this.BindGrid();
return;
}
//新增检测记录
var dataInChecks = dataInTemp.Select(x => x.Value8).Distinct();
foreach (var checkCode in dataInChecks)
{
var firstDataTemp = dataInTemp.FirstOrDefault(x => x.Value8 == checkCode);
if (firstDataTemp != null)
{
bool hasAdd = false;
var trust = Funs.DB.CH_Trust.FirstOrDefault(x => x.ProjectId == CurrUser.LoginProjectId && x.CH_TrustCode == firstDataTemp.Value6);
Model.CH_Check check = new Model.CH_Check();
check.CHT_CheckID = Guid.NewGuid().ToString();
if (chAddForCheck.Checked)
{
check = Funs.DB.CH_Check.FirstOrDefault(x => x.ProjectId == CurrUser.LoginProjectId && x.CHT_CheckCode == checkCode);
if (check == null)
{
check = new Model.CH_Check();
check.CHT_CheckID = Guid.NewGuid().ToString();
}
else
{
hasAdd = true;
}
}
check.ProjectId = this.CurrUser.LoginProjectId;
check.CHT_CheckCode = checkCode;
check.CH_TrustID = trust.CH_TrustID;
check.UnitId = trust.CH_TrustUnit;
check.InstallationId = trust.InstallationId;
if (!string.IsNullOrEmpty(firstDataTemp.Value11))
{
check.CHT_CheckDate = Funs.GetNewDateTime(firstDataTemp.Value11);
}
// check.CHT_CheckType = this.txtCheckType.Text.Trim();
check.CHT_Tabler = this.CurrUser.UserId;
check.CHT_TableDate = DateTime.Now;
check.CHT_AuditMan = this.CurrUser.UserId;
check.CHT_AuditDate = DateTime.Now;
// check.CHT_CheckMan = this.ddlCheckMan.SelectedValue;
check.ContractualUnits = trust.CH_CheckUnit;
if (!hasAdd)
{
Funs.DB.CH_Check.InsertOnSubmit(check);
}
var allCheckData = dataInTemp.Where(x => x.Value8 == checkCode);
foreach (var allCheck in allCheckData)
{
var isotemp = isos.FirstOrDefault(x => x.ISO_IsoNo == allCheck.Value3);
var joint = jointInfos.FirstOrDefault(x => x.ISO_ID == isotemp.ISO_ID && x.JOT_JointNo == allCheck.Value4);
var detectionType = detectionTypes.FirstOrDefault(x => x.DetectionTypeCode == allCheck.Value9);
//var temptrust = newTrusts.Where(x => x.CH_TrustCode == allCheck.Value6).FirstOrDefault(); ;
if (joint != null)
{
var trustItem = Funs.DB.CH_TrustItem.FirstOrDefault(x => x.CH_TrustID == trust.CH_TrustID && x.JOT_ID == joint.JOT_ID);
bool hasitem = false;
Model.CH_CheckItem checkitem = new Model.CH_CheckItem();
checkitem.CHT_CheckItemID = Guid.NewGuid().ToString();
if (chAddForCheck.Checked)
{
checkitem = Funs.DB.CH_CheckItem.FirstOrDefault(x => x.JOT_ID == joint.JOT_ID && x.CHT_CheckID == check.CHT_CheckID);
if (checkitem == null)
{
checkitem = new Model.CH_CheckItem();
checkitem.CHT_CheckItemID = Guid.NewGuid().ToString();
}
else
{
hasitem = true;
}
}
checkitem.CHT_CheckID = check.CHT_CheckID;
checkitem.JOT_ID = joint.JOT_ID;
if (trustItem != null)
{
checkitem.CH_TrustItemID = trustItem.CH_TrustItemID;
}
checkitem.CHT_CheckMethod = detectionType.DetectionTypeId;
//checkitem.CHT_RequestDate = int.Parse(allCheck.Value14);
checkitem.CHT_RepairLocation = allCheck.Value13;
if (!string.IsNullOrEmpty(allCheck.Value14))
{
try
{
checkitem.CHT_TotalFilm = int.Parse(allCheck.Value14);
}
catch (Exception e) { }
}
if (!string.IsNullOrEmpty(allCheck.Value15))
{
try
{
checkitem.CHT_PassFilm = int.Parse(allCheck.Value15);
}
catch (Exception e) { }
}
checkitem.CHT_CheckResult = allCheck.Value16;
//checkitem.CHT_CheckNo = allCheck.Value8;
if (!string.IsNullOrEmpty(allCheck.Value11))
{
checkitem.CHT_FilmDate = Funs.GetNewDateTime(allCheck.Value11);
}
if (!string.IsNullOrEmpty(allCheck.Value12))
{
checkitem.CHT_ReportDate = Funs.GetNewDateTime(allCheck.Value12);
}
checkitem.FilmSpecifications = allCheck.Value18;
if (!string.IsNullOrEmpty(allCheck.Value19))
{
try
{
checkitem.DefectLength = decimal.Parse(allCheck.Value19);
}
catch (Exception e) { }
}
if (!string.IsNullOrEmpty(joint.Extend_Length))
{
try
{
checkitem.ExtendingRice = Decimal.Parse(joint.Extend_Length);
}
catch (Exception e) { }
}
checkitem.Defects_Definition = allCheck.Value17;
if (!hasitem)
{
Funs.DB.CH_CheckItem.InsertOnSubmit(checkitem);
}
if (string.IsNullOrEmpty(joint.JOT_CheckFlag) || joint.JOT_CheckFlag == "00")
{
joint.JOT_CheckFlag = "01";
}
else if (joint.JOT_CheckFlag == "01")//一次检测,未审核
{
joint.JOT_CheckFlag = "02";
}
else if (joint.JOT_CheckFlag == "02")//一次检测,已审核
{
joint.JOT_CheckFlag = "11";
}
else if (joint.JOT_CheckFlag == "11")//二次检测,未审核
{
joint.JOT_CheckFlag = "12";
}
else if (joint.JOT_CheckFlag == "12")//二次检测,已审核
{
joint.JOT_CheckFlag = "21";
}
else if (joint.JOT_CheckFlag == "21")//三次检测,未审核
{
joint.JOT_CheckFlag = "22";//三次检测,已审核
}
if (String.IsNullOrEmpty(joint.JOT_TrustFlag) || joint.JOT_TrustFlag == "00")//未下委托
{
joint.JOT_TrustFlag = "01";
}
else if (joint.JOT_TrustFlag == "01")//一次委托,未审核
{
joint.JOT_TrustFlag = "02";
}
else if (joint.JOT_TrustFlag == "02")//一次委托,已审核
{
joint.JOT_TrustFlag = "11";
}
else if (joint.JOT_TrustFlag == "11")//二次委托,未审核
{
joint.JOT_TrustFlag = "12";
}
else if (joint.JOT_TrustFlag == "12")//二次委托,已审核
{
joint.JOT_TrustFlag = "21";
}
else if (joint.JOT_TrustFlag == "21")//三次委托,未审核
{
joint.JOT_TrustFlag = "22";//三次委托,已审核
}
}
}
}
}
Funs.DB.HJGL_CheckImportTemp.DeleteAllOnSubmit(dataInTemp);
Funs.DB.SubmitChanges();
this.BindGrid();
}
#endregion
#region
/// <summary>
/// 删除所有数据事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnAllDelete_Click(object sender, EventArgs e)
{
////先删除临时表中 该人员以前导入的数据
BLL.CheckManageImportTempService.DeleteDataInTempByProjectIdUserId(this.CurrUser.LoginProjectId, this.CurrUser.UserId);
this.BindGrid();
ShowNotify("删除成功!", MessageBoxIcon.Success);
this.lbDataCout.Text = string.Empty;
}
#endregion
#region
/// <summary>
/// 下载模版
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void imgbtnUpload_Click(object sender, EventArgs e)
{
this.TemplateUpload(BLL.Const.HJGL_CheckImportTemplateUrl);
}
/// <summary>
/// 模板下载方法
/// </summary>
/// <param name="initTemplatePath"></param>
protected void TemplateUpload(string initTemplatePath)
{
string uploadfilepath = Server.MapPath("~/") + initTemplatePath;
string fileName = Path.GetFileName(initTemplatePath);
FileInfo info = new FileInfo(uploadfilepath);
if (info.Exists)
{
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(uploadfilepath, 0, fileSize);
Response.Flush();
Response.Close();
}
else
{
ShowNotify("文件不存在!", MessageBoxIcon.Warning);
}
}
#endregion
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];
}
}
}