/// <summary> /// 完成 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnComplete_ServerClick(object sender, System.EventArgs e) { try { int step = 9; this.txtStep.Value = step.ToString(); int succ_count = 0; int err_count = 0; int succ_add_count = 0; try { this.txtResult.Value = ""; if (Session["tbImportMaterialCostStream"] == null) { throw new Exception("超时,请重新导入"); } DataTable tbStream = (DataTable)Session["tbImportMaterialCostStream"]; BLL.MaterialCostImport imp = new MaterialCostImport(); EntityData entity = DAL.EntityDAO.MaterialDAO.GetAllMaterialCost(); foreach (DataRow drStream in tbStream.Rows) { string s = BLL.ConvertRule.ToString(drStream["text"]); int r = BLL.ConvertRule.ToInt(drStream["rowid"]); string hint = ""; string Description = ""; string GroupFullName = ""; DataRow dr = imp.ImportMaterialCostSingle(s, entity, ref hint, ref Description, ref GroupFullName, false, (DataTable)Session["tbAllSystemGroup"]); if (dr == null) { //出错 err_count++; this.txtResult.Value = this.txtResult.Value + string.Format("第 {0} 行 {1}:", r, "") + hint + "\n"; } else { //成功 succ_count++; if (dr.RowState == DataRowState.Added) //新增 { succ_add_count++; } } } DAL.EntityDAO.MaterialDAO.SubmitAllMaterialCost(entity); } catch (Exception ex) { ApplicationLog.WriteLog(this.ToString(), ex, ""); Response.Write(JavaScript.Alert(true, "导入出错:" + ex.Message)); return; } int succ_edit_count = succ_count - succ_add_count; if (err_count > 0) { this.txtResult.Value = string.Format("导入完成,{0}条成功(新增{1}条、修改{2}条),{3}条出错:", succ_count, succ_add_count, succ_edit_count, err_count) + "\n" + this.txtResult.Value; } else { this.txtResult.Value = string.Format("导入完成,{0}条导入成功(新增{1}条、修改{2}条)", succ_count, succ_add_count, succ_edit_count); } //导入有错时记日志 ApplicationLog.WriteFile("材料价格导入.log", this.ToString(), this.txtResult.Value); RefreshParent(); } catch (Exception ex) { ApplicationLog.WriteLog(this.ToString(), ex, ""); Response.Write(JavaScript.Alert(true, "完成出错:" + ex.Message)); } }
/// <summary> /// 导入 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnOK_ServerClick(object sender, System.EventArgs e) { if (this.txtFile.PostedFile.FileName == "") { Response.Write(Rms.Web.JavaScript.Alert(true, "请选择文件")); return; } int succ_count = 0; int err_count = 0; try { this.txtResult.Value = ""; StreamReader m_sr = new StreamReader(this.txtFile.PostedFile.InputStream, System.Text.Encoding.Default); int r = 0; //第1行是标题 if (m_sr.Peek() >= 0) { m_sr.ReadLine(); r++; } BLL.MaterialCostImport imp = new MaterialCostImport(); EntityData entity = DAL.EntityDAO.MaterialDAO.GetAllMaterialCost(); while (m_sr.Peek() >= 0) { string s = m_sr.ReadLine(); r++; string hint = ""; string Description = ""; string MaterialCostGroupFullName = ""; DataRow dr = imp.ImportMaterialCostSingle(s, entity, ref hint, ref Description, ref MaterialCostGroupFullName, false, (DataTable)Session["tbAllSystemGroup"]); if (dr == null) { //出错 err_count++; this.txtResult.Value = this.txtResult.Value + string.Format("第 {0} 行 {1}:", r, "") + hint + "\n"; } else { //成功 succ_count++; } } DAL.EntityDAO.MaterialDAO.SubmitAllMaterialCost(entity); } catch (Exception ex) { ApplicationLog.WriteLog(this.ToString(), ex, ""); Response.Write(JavaScript.Alert(true, "导入出错:" + ex.Message)); return; } if (err_count > 0) { this.txtResult.Value = string.Format("导入完成,{0}条成功, {1}条出错:", succ_count, err_count) + "\n" + this.txtResult.Value; } else { this.txtResult.Value = string.Format("{0}条导入成功", succ_count); } //导入有错时记日志 ApplicationLog.WriteFile("材料价格导入.log", this.ToString(), this.txtResult.Value); RefreshParent(); // Response.Write(JavaScript.WinClose(false)); }
/// <summary> /// 显示要导入的材料价格列表 /// </summary> private void ShowImportList() { try { if (Session["tbImportMaterialCostStream"] == null) { throw new Exception("超时,请重新导入"); } DataTable tbStream = (DataTable)Session["tbImportMaterialCostStream"]; BLL.MaterialCostImport imp = new MaterialCostImport(); // EntityData entity = new EntityData("MaterialCost"); EntityData entity = DAL.EntityDAO.MaterialDAO.GetAllMaterialCost(); //增加预导入结果列 entity.CurrentTable.Columns.Add("GroupFullName"); entity.CurrentTable.Columns.Add("rowid", typeof(int)); entity.CurrentTable.Columns.Add("text"); entity.CurrentTable.Columns.Add("ImportHint"); entity.CurrentTable.Columns.Add("ImportResult", typeof(int)); entity.CurrentTable.Columns.Add("ImportResultName"); entity.CurrentTable.Columns.Add("IsImport", typeof(int)); int add_count = 0; int edit_count = 0; int err_count = 0; foreach (DataRow drStream in tbStream.Rows) { string s = BLL.ConvertRule.ToString(drStream["text"]); int r = BLL.ConvertRule.ToInt(drStream["rowid"]); string hint = ""; string Description = ""; string GroupFullName = ""; DataRow dr = imp.ImportMaterialCostSingle(s, entity, ref hint, ref Description, ref GroupFullName, true, (DataTable)Session["tbAllSystemGroup"]); if (dr == null) { //出错 err_count++; dr = entity.CurrentTable.NewRow(); dr["MaterialCostCode"] = "ERR_" + r.ToString(); dr["ImportHint"] = hint; dr["ImportResult"] = -1; dr["ImportResultName"] = "有错"; entity.CurrentTable.Rows.Add(dr); } else { //成功 if (dr.RowState == DataRowState.Added) { add_count++; dr["ImportResult"] = 1; dr["ImportResultName"] = "新增"; } else { edit_count++; dr["ImportResult"] = 2; dr["ImportResultName"] = "修改"; } } dr["GroupFullName"] = GroupFullName; dr["rowid"] = r; dr["text"] = s; dr["IsImport"] = 1; } this.lblCountAdd.Text = add_count.ToString(); this.lblCountEdit.Text = edit_count.ToString(); this.lblCountErr.Text = err_count.ToString(); Session["entityImportMaterialCost"] = entity; BindImportList(); // entity.Dispose(); } catch (Exception ex) { ApplicationLog.WriteLog(this.ToString(), ex, ""); Response.Write(JavaScript.Alert(true, "显示要导入的材料价格列表出错:" + ex.Message)); } }