20220929 人员离岗导入功能实现

This commit is contained in:
2022-09-29 14:21:52 +08:00
parent 18ed8e8833
commit b72cf8845f
5 changed files with 185 additions and 43 deletions
@@ -65,7 +65,11 @@ namespace FineUIPro.Web.HSSE.SitePerson
persons.Clear();
}
errorInfos = string.Empty;
this.ProjectId = Request.Params["ProjectId"];
this.ProjectId = this.CurrUser.LoginProjectId;
if (!string.IsNullOrEmpty(Request.Params["ProjectId"]))
{
this.ProjectId = Request.Params["ProjectId"];
}
}
}
#endregion
@@ -1134,6 +1138,13 @@ namespace FineUIPro.Web.HSSE.SitePerson
getPerson.IsUsed = persons[i].IsUsedName == "是" ? true : false;
getPerson.IsCardUsed = persons[i].IsCardUsedName == "是" ? true : false;
getPerson.IsCardNoOK = IDCardValid.CheckIDCard(persons[i].IdentityCard);
if (getPerson.OutTime.HasValue)
{
getPerson.IsUsed = true;
getPerson.ExchangeTime = null;
getPerson.ExchangeTime2 = null;
getPerson.RealNameUpdateTime = null;
}
Funs.DB.SubmitChanges();
}
}
@@ -1314,5 +1325,134 @@ namespace FineUIPro.Web.HSSE.SitePerson
{
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("PersonBaseData.aspx", "查看 - ")));
}
/// <summary>
/// 离岗导入
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnOut_Click1(object sender, EventArgs e)
{
try
{
if (this.fuAttachUrl.HasFile == false)
{
ShowNotify("请您选择Excel文件!", MessageBoxIcon.Warning);
return;
}
string IsXls = Path.GetExtension(this.fuAttachUrl.FileName).ToString().Trim().ToLower();
if (IsXls != ".xls")
{
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.fuAttachUrl.PostedFile.SaveAs(filePath);
string fileName = rootPath + initPath + this.hdFileName.Text;
string oleDBConnString = String.Empty;
oleDBConnString = "Provider=Microsoft.Jet.OLEDB.4.0;";
oleDBConnString += "Data Source=";
oleDBConnString += fileName;
oleDBConnString += ";Extended Properties=Excel 8.0;";
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.Fill(ds, "m_tableName");
oleAdMaster.Dispose();
oleDBConn.Close();
oleDBConn.Dispose();
AddDatasetToSQLout(ds.Tables[0]);
}
catch (Exception ex)
{
throw ex;
}
}
#region Dataset的数据导入数据库
/// <summary>
/// 将Dataset的数据导入数据库
/// </summary>
/// <param name="pds">数据集</param>
/// <param name="Cols">数据集列数</param>
/// <returns></returns>
private bool AddDatasetToSQLout(DataTable pds)
{
int ic, ir;
persons.Clear();
ic = pds.Columns.Count;
ir = pds.Rows.Count;
string info = string.Empty;
if (pds != null && ir > 0)
{
for (int i = 0; i < ir; i++)
{
string col4 = pds.Rows[i][4].ToString().Trim();
string col30 = pds.Rows[i][30].ToString().Trim();
string col31 = pds.Rows[i][31].ToString().Trim();
DateTime? outTime = Funs.GetNewDateTime(col30);
if (!string.IsNullOrEmpty(col4) && outTime.HasValue)
{
var getPerson = Funs.DB.SitePerson_Person.FirstOrDefault(x => x.IdentityCard == col4 && x.ProjectId == this.ProjectId);
if (getPerson != null)
{
getPerson.OutTime = outTime;
getPerson.OutResult = col31;
getPerson.IsUsed = true;
getPerson.ExchangeTime = null;
getPerson.ExchangeTime2 = null;
getPerson.RealNameUpdateTime = null;
Funs.DB.SubmitChanges();
info += "第" + (i + 1).ToString() + "行," + getPerson.PersonName + "离岗成功。";
}
else
{
info += "第" + (i + 1).ToString() + "行,人员不在当前项目。";
}
}
else
{
info += "第" + (i + 1).ToString() + "行,身份证号码、离场时间为空。";
}
}
if (!string.IsNullOrEmpty(info))
{
ShowNotify(info, MessageBoxIcon.Information);
}
}
else
{
ShowNotify("导入数据为空!", MessageBoxIcon.Warning);
}
return true;
}
#endregion
}
}