This commit is contained in:
2024-07-01 09:29:35 +08:00
parent 3990f747ce
commit 26d1774fb1
35 changed files with 1432 additions and 488 deletions
@@ -4,11 +4,25 @@ using System.Collections.Generic;
using System.Linq;
using System.Data;
using System.Data.SqlClient;
using Model;
using System.IO;
using System.Drawing;
using System.Web.UI.WebControls;
namespace FineUIPro.Web.WeldingProcess.WeldingManage
{
public partial class MaterialCoode : PageBase
{
//定义变量
/// <summary>
/// 上传预设的虚拟路径
/// </summary>
private string initPath = Const.ExcelUrl;
/// <summary>
/// 错误集合
/// </summary>
public static string errorInfos = string.Empty;
#region
/// <summary>
/// 加载页面
@@ -179,18 +193,18 @@ namespace FineUIPro.Web.WeldingProcess.WeldingManage
foreach (int rowIndex in Grid1.SelectedRowIndexArray)
{
string rowID = Grid1.DataKeys[rowIndex][0].ToString();
var getMedium = BLL.Base_MediumService.GetMediumByMediumId(rowID);
if (getMedium != null)
var getCoode = BLL.MaterialCoodeService.GetMaterialCoode(rowID,this.CurrUser.LoginProjectId);
if (getCoode != null)
{
string cont = judgementDelete(rowID);
if (string.IsNullOrEmpty(cont))
{
BLL.Base_MediumService.DeleteMediumByMediumId(rowID);
BLL.MaterialCoodeService.DeleteMaterialCoode(rowID);
BLL.Sys_LogService.AddLog(Const.System_2, this.CurrUser.LoginProjectId, this.CurrUser.UserId, Const.MediumMenuId, Const.BtnDelete, rowID);
}
else
{
strShowNotify += Resources.Lan.MediumDefinition + "" + getMedium.MediumCode + cont;
strShowNotify += Resources.Lan.MediumDefinition + "" + getCoode.Coode + cont;
}
}
}
@@ -255,6 +269,181 @@ namespace FineUIPro.Web.WeldingProcess.WeldingManage
}
#endregion
protected void btnImport_Click(object sender, EventArgs e)
{
if (this.CoodeUrl.HasFile == false)
{
ShowNotify("请选择Excel文件!", MessageBoxIcon.Warning);
return;
}
string IsXls = Path.GetExtension(this.CoodeUrl.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.hidFileName.Text = BLL.Funs.GetNewFileName() + IsXls;
//上传文件路径
string filePath = initFullPath + this.hidFileName.Text;
//文件上传服务器
this.CoodeUrl.PostedFile.SaveAs(filePath);
//文件上传服务器后的名称
string fileName = rootPath + initPath + this.hidFileName.Text;
//读取Excel
DataSet ds = NPOIHelper.ExcelToDataSet(fileName, out errorInfos, true);
errorInfos = string.Empty;
//验证Excel读取是否有误
if (!string.IsNullOrEmpty(errorInfos))
{
ShowNotify(errorInfos, MessageBoxIcon.Warning);
return;
}
string message = string.Empty;
List<Model.Base_MaterialCoode> coodeList = new List<Model.Base_MaterialCoode>();
var coodes = from x in Funs.DB.Base_MaterialCoode where x.ProjectId == this.CurrUser.LoginProjectId select x;
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
Model.Base_MaterialCoode d = new Model.Base_MaterialCoode();
d.ProjectId = this.CurrUser.LoginProjectId;
d.MaterialCoodeId = SQLHelper.GetNewID(typeof(Model.Base_MaterialCoode));
d.Coode = ds.Tables[0].Rows[i]["Coode"].ToString();
d.HeartNo = ds.Tables[0].Rows[i]["炉批号"].ToString();
if (!string.IsNullOrEmpty(d.Coode) && !string.IsNullOrEmpty(d.HeartNo))
{
var c = from x in coodes where x.Coode == d.Coode && x.HeartNo == d.HeartNo select x;
if (c.Count() > 0)
{
errorInfos += (i + 2) + "行,Coode对应的炉批号已存在!</br>";
}
}
if (ds.Tables[0].Rows[i]["数量"] != null && !string.IsNullOrEmpty(ds.Tables[0].Rows[i]["数量"].ToString()))
{
int? dd = Funs.GetNewInt(ds.Tables[0].Rows[i]["数量"].ToString());
if (dd != null)
{
d.Amount = Funs.GetNewInt(ds.Tables[0].Rows[i]["数量"].ToString());
}
else
{
errorInfos += (i + 2) + "行,数量格式不正确!</br>";
}
}
if (ds.Tables[0].Rows[i]["是否启用"] != null && !string.IsNullOrEmpty(ds.Tables[0].Rows[i]["是否启用"].ToString()))
{
string isUser = ds.Tables[0].Rows[i]["是否启用"].ToString();
if (isUser != "是" && isUser != "否")
{
errorInfos += (i + 2) + "行,是否启用只能录入是或否!</br>";
}
else
{
if (isUser == "是")
{
d.IsUse = true;
}
else
{
d.IsUse = false;
}
}
}
else
{
d.IsUse = false;
}
coodeList.Add(d);
}
var coodeGroup = coodeList.GroupBy(x => new { x.Coode, x.HeartNo }).Select(g => new { Coode = g.Key.Coode, HeartNo = g.Key.HeartNo });
if (coodeList.Count() != coodeGroup.Count())
{
errorInfos += "Coode对应的炉批号有重复!";
}
// 数据验证错误,返回
if (!string.IsNullOrEmpty(errorInfos))
{
ShowNotify(errorInfos, MessageBoxIcon.Warning, 10000);
return;
}
else
{
foreach (var item in coodeList)
{
BLL.MaterialCoodeService.AddMaterialCoode(item);
}
ShowNotify("Coode导入成功!", MessageBoxIcon.Success);
this.BindGrid();
}
}
#region
/// <summary>
/// 模板下载
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnDownLoad_Click(object sender, EventArgs e)
{
string rootPath = Server.MapPath("~/");
string uploadfilepath = rootPath + Const.CoodeInTemplateUrl;
string filePath = Const.CoodeInTemplateUrl;
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();
//PageContext.RegisterStartupScript(Confirm.GetShowReference("确定要下载焊工资质导入模板?", String.Empty, MessageBoxIcon.Question, PageManager1.GetCustomEventReference(false, "Confirm_OK"), PageManager1.GetCustomEventReference("Confirm_Cancel")));
}
/// <summary>
/// 下载导入模板
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void PageManager1_CustomEvent(object sender, CustomEventArgs e)
{
if (e.EventArgument == "Confirm_OK")
{
string rootPath = Server.MapPath("~/");
string uploadfilepath = rootPath + Const.WelderQueTemplateUrl;
string filePath = Const.WelderQueTemplateUrl;
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();
}
}
#endregion
#region
/// <summary>
/// 获取按钮权限