private void Save() { KPI_ScoreBLL bll; int id, detailID; foreach (GridViewRow row in gv_List.Rows) { id = (int)gv_List.DataKeys[row.RowIndex][0]; detailID = (int)gv_List.DataKeys[row.RowIndex][1]; bll = new KPI_ScoreBLL(id); KPI_ScoreDetail item = bll.GetDetailModel(detailID); item.SelfCheckValue = decimal.Parse(((TextBox)row.FindControl("tbx_SelfCheckValue")).Text); item.LeadCheckValue = decimal.Parse(((TextBox)row.FindControl("tbx_LeadCheckValue")).Text); item.ApprovedValue = decimal.Parse(((TextBox)row.FindControl("tbx_ApprovedValue")).Text); bll.UpdateDetail(item); } }
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e) { if (dt_Data != null) { HSSFWorkbook hssfworkbook; FileStream file = new FileStream(fileName, FileMode.Open, FileAccess.ReadWrite); hssfworkbook = new HSSFWorkbook(file); ISheet sheet = hssfworkbook.GetSheetAt(0); int RowBase = 1; if (sheet.GetRow(1).GetCell(sheet.GetRow(1).FirstCellNum).ToString() == "") { RowBase = 2; } decimal lastValue; int staffid, month, Scheme; KPI_ScoreBLL _bll; Hashtable ht_table = new Hashtable(); for (int x = 0; x < dt_Data.Rows.Count; x++) { _bll = new KPI_ScoreBLL(); ((BackgroundWorker)sender).ReportProgress((x + 1) * 100 / dt_Data.Rows.Count, x + 1); try { if (dt_Data.Rows[x]["导入标志"].ToString().Trim() != "") continue; string errorText = ""; staffid = int.Parse(dt_Data.Rows[x]["员工ID"].ToString()); if (ht_table[dt_Data.Rows[x]["会计月"].ToString()] == null) { IList<AC_AccountMonth> _monthlist = AC_AccountMonthBLL.GetModelList("Name='" + dt_Data.Rows[x]["会计月"].ToString() + "'"); if (_monthlist.Count > 0) { month = _monthlist[0].ID; ht_table[dt_Data.Rows[x]["会计月"].ToString()] = month; } else { dt_Data.Rows[x]["导入标志"] += "会计月错误;"; continue; } } else { month = (int)ht_table[dt_Data.Rows[x]["会计月"].ToString()]; } if (ht_table[dt_Data.Rows[x]["考核方案"].ToString()] == null) { IList<KPI_Scheme> _schemelist = KPI_SchemeBLL.GetModelList("Name='" + dt_Data.Rows[x]["考核方案"].ToString() + "'"); if (_schemelist.Count > 0) { Scheme = _schemelist[0].ID; ht_table[dt_Data.Rows[x]["考核方案"].ToString()] = Scheme; } else { dt_Data.Rows[x]["导入标志"] += "未找到相应考核方案;"; continue; } } else { Scheme = (int)ht_table[dt_Data.Rows[x]["考核方案"].ToString()]; } Org_StaffBLL _staffbll = new Org_StaffBLL(staffid); if (_staffbll.Model == null) { dt_Data.Rows[x]["导入标志"] += "未找到相应员工;"; continue; } else { IList<KPI_Score> _kpilist = KPI_ScoreBLL.GetModelList("AccountMonth=" + month.ToString() + " AND RelateStaff=" + staffid.ToString() + " AND Scheme=" + Scheme.ToString()); if (_kpilist.Count > 0) { if (_kpilist.FirstOrDefault(p => p.ApproveFlag == 1) != null) { dt_Data.Rows[x]["导入标志"] += "该员工绩效已审核,不能再次导入;"; continue; } else { _bll = new KPI_ScoreBLL(_kpilist[0].ID); _bll.Model.UpdateTime = DateTime.Now; _bll.Items.Clear(); } } else { _bll.Model.Scheme = Scheme; _bll.Model.RelateStaff = staffid; _bll.Model.AccountMonth = month; _bll.Model.OrganizeCity = _staffbll.Model.OrganizeCity; _bll.Model.ApproveFlag = 2; _bll.Model.InsertStaff = 1; _bll.Model.Position = _staffbll.Model.Position; _bll.Model.InsertTime = DateTime.Now; } } IList<KPI_ScoreDetail> _details = new List<KPI_ScoreDetail>(); for (int y = 9; y < dt_Data.Columns.Count; y++) { KPI_ScoreDetail detail = new KPI_ScoreDetail(); if (ht_table[dt_Data.Columns[y].ColumnName.ToString() + "(" + _bll.Model.Scheme.ToString() + ")"] == null) { IList<KPI_SchemeDetail> _SchemeDetailList = new KPI_SchemeBLL().GetDetail("Name='" + dt_Data.Columns[y].ColumnName.ToString() + "' AND Scheme=" + _bll.Model.Scheme.ToString()); if (_SchemeDetailList.Count > 0) { detail.SchemeItem = _SchemeDetailList[0].ID; ht_table[dt_Data.Columns[y].ColumnName.ToString() + "(" + _bll.Model.Scheme.ToString() + ")"] = _SchemeDetailList[0].ID; } else { dt_Data.Rows[x]["导入标志"] += "考核指标未找到;"; } } else { detail.SchemeItem = (int)ht_table[dt_Data.Columns[y].ColumnName.ToString() + "(" + _bll.Model.Scheme.ToString() + ")"]; } if (!decimal.TryParse(dt_Data.Rows[x][y].ToString(), out lastValue)) { errorText += dt_Data.Columns[y] + "转换出错;导入失败!"; continue; } else { detail.LastValue = lastValue; } errorText = errorText.Replace("导入成功", ""); dt_Data.Rows[x]["导入标志"] = errorText == "" ? "导入成功" : errorText; _details.Add(detail); } if (_bll.Model.ID > 0) { _bll.DeleteDetail(); //先清除原先导入的数据 _bll.Items = _details; _bll.AddDetail(); _bll.Update(); } else { _bll.Items = _details; _bll.Add(); } } catch (Exception ex) { dt_Data.Rows[x]["导入标志"] = "导入出错"; MessageBox.Show(ex.Message); continue; } finally { sheet.GetRow(RowBase + x).GetCell(8).SetCellValue(dt_Data.Rows[x]["导入标志"].ToString()); } } FileStream writefile = new FileStream(fileName, FileMode.Open, FileAccess.ReadWrite); hssfworkbook.Write(writefile); writefile.Close(); sheet = null; } else { if (fileName != "") { ConvertToDataTable(fileName); } } }
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e) { if (dt_Data != null) { HSSFWorkbook hssfworkbook; FileStream file = new FileStream(fileName, FileMode.Open, FileAccess.ReadWrite); hssfworkbook = new HSSFWorkbook(file); ISheet sheet = hssfworkbook.GetSheetAt(0); int RowBase = 1; if (sheet.GetRow(1).GetCell(sheet.GetRow(1).FirstCellNum).ToString() == "") { RowBase = 2; } decimal lastValue; int staffid, month, Scheme; KPI_ScoreBLL _bll; Hashtable ht_table = new Hashtable(); for (int x = 0; x < dt_Data.Rows.Count; x++) { _bll = new KPI_ScoreBLL(); ((BackgroundWorker)sender).ReportProgress((x + 1) * 100 / dt_Data.Rows.Count, x + 1); try { if (dt_Data.Rows[x]["导入标志"].ToString().Trim() != "") { continue; } string errorText = ""; staffid = int.Parse(dt_Data.Rows[x]["员工ID"].ToString()); if (ht_table[dt_Data.Rows[x]["会计月"].ToString()] == null) { IList <AC_AccountMonth> _monthlist = AC_AccountMonthBLL.GetModelList("Name='" + dt_Data.Rows[x]["会计月"].ToString() + "'"); if (_monthlist.Count > 0) { month = _monthlist[0].ID; ht_table[dt_Data.Rows[x]["会计月"].ToString()] = month; } else { dt_Data.Rows[x]["导入标志"] += "会计月错误;"; continue; } } else { month = (int)ht_table[dt_Data.Rows[x]["会计月"].ToString()]; } if (ht_table[dt_Data.Rows[x]["考核方案"].ToString()] == null) { IList <KPI_Scheme> _schemelist = KPI_SchemeBLL.GetModelList("Name='" + dt_Data.Rows[x]["考核方案"].ToString() + "'"); if (_schemelist.Count > 0) { Scheme = _schemelist[0].ID; ht_table[dt_Data.Rows[x]["考核方案"].ToString()] = Scheme; } else { dt_Data.Rows[x]["导入标志"] += "未找到相应考核方案;"; continue; } } else { Scheme = (int)ht_table[dt_Data.Rows[x]["考核方案"].ToString()]; } Org_StaffBLL _staffbll = new Org_StaffBLL(staffid); if (_staffbll.Model == null) { dt_Data.Rows[x]["导入标志"] += "未找到相应员工;"; continue; } else { IList <KPI_Score> _kpilist = KPI_ScoreBLL.GetModelList("AccountMonth=" + month.ToString() + " AND RelateStaff=" + staffid.ToString() + " AND Scheme=" + Scheme.ToString()); if (_kpilist.Count > 0) { if (_kpilist.FirstOrDefault(p => p.ApproveFlag == 1) != null) { dt_Data.Rows[x]["导入标志"] += "该员工绩效已审核,不能再次导入;"; continue; } else { _bll = new KPI_ScoreBLL(_kpilist[0].ID); _bll.Model.UpdateTime = DateTime.Now; _bll.Items.Clear(); } } else { _bll.Model.Scheme = Scheme; _bll.Model.RelateStaff = staffid; _bll.Model.AccountMonth = month; _bll.Model.OrganizeCity = _staffbll.Model.OrganizeCity; _bll.Model.ApproveFlag = 2; _bll.Model.InsertStaff = 1; _bll.Model.Position = _staffbll.Model.Position; _bll.Model.InsertTime = DateTime.Now; } } IList <KPI_ScoreDetail> _details = new List <KPI_ScoreDetail>(); for (int y = 9; y < dt_Data.Columns.Count; y++) { KPI_ScoreDetail detail = new KPI_ScoreDetail(); if (ht_table[dt_Data.Columns[y].ColumnName.ToString() + "(" + _bll.Model.Scheme.ToString() + ")"] == null) { IList <KPI_SchemeDetail> _SchemeDetailList = new KPI_SchemeBLL().GetDetail("Name='" + dt_Data.Columns[y].ColumnName.ToString() + "' AND Scheme=" + _bll.Model.Scheme.ToString()); if (_SchemeDetailList.Count > 0) { detail.SchemeItem = _SchemeDetailList[0].ID; ht_table[dt_Data.Columns[y].ColumnName.ToString() + "(" + _bll.Model.Scheme.ToString() + ")"] = _SchemeDetailList[0].ID; } else { dt_Data.Rows[x]["导入标志"] += "考核指标未找到;"; } } else { detail.SchemeItem = (int)ht_table[dt_Data.Columns[y].ColumnName.ToString() + "(" + _bll.Model.Scheme.ToString() + ")"]; } if (!decimal.TryParse(dt_Data.Rows[x][y].ToString(), out lastValue)) { errorText += dt_Data.Columns[y] + "转换出错;导入失败!"; continue; } else { detail.LastValue = lastValue; } errorText = errorText.Replace("导入成功", ""); dt_Data.Rows[x]["导入标志"] = errorText == "" ? "导入成功" : errorText; _details.Add(detail); } if (_bll.Model.ID > 0) { _bll.DeleteDetail(); //先清除原先导入的数据 _bll.Items = _details; _bll.AddDetail(); _bll.Update(); } else { _bll.Items = _details; _bll.Add(); } } catch (Exception ex) { dt_Data.Rows[x]["导入标志"] = "导入出错"; MessageBox.Show(ex.Message); continue; } finally { sheet.GetRow(RowBase + x).GetCell(8).SetCellValue(dt_Data.Rows[x]["导入标志"].ToString()); } } FileStream writefile = new FileStream(fileName, FileMode.Open, FileAccess.ReadWrite); hssfworkbook.Write(writefile); writefile.Close(); sheet = null; } else { if (fileName != "") { ConvertToDataTable(fileName); } } }