/// <summary> /// 展示导入的数据 /// </summary> /// <param name="dtExcel"></param> /// <returns></returns> private bool ShowExcelImp(DataTable dtExcel) { DataTable dtCorr = dtSubjRela.Copy(); //已存在的对应关系() //foreach (DataRow r in dtSubjRela.Rows) //{ // if (r.RowState != DataRowState.Deleted) r.Delete(); //} //dtSubjRela.AcceptChanges(); //导入前行号 int RowNumBeforeImport = dtSubjRela.Rows.Count + GridSubjRela.Rows.Fixed; #region 导入新行;只导入不存在的行 foreach (DataRow rExcel in dtExcel.Rows) { if (dtCorr.Select("snckemu_code='" + rExcel["snckemu_code"] + "' and snckemu_name='" + rExcel["snckemu_name"] + "' or scwkemu_code='" + rExcel["scwkemu_code"] + "'").Length == 0) { DataRow r = dtSubjRela.NewRow(); r["sid"] = Guid.NewGuid().ToString(); r["scwkemu_code"] = rExcel["scwkemu_code"]; r["scwkemu_name"] = string.Empty; r["snckemu_code"] = rExcel["snckemu_code"]; r["snckemu_name"] = rExcel["snckemu_name"]; r["sflag"] = rExcel["sflag"]; dtSubjRela.Rows.Add(r); } } #endregion SetGridStyle(); #region 设置导入行突出显示(若导入行>0) if (RowNumBeforeImport != GridSubjRela.Rows.Count) { CellStyle csImp = GridSubjRela.Styles.Add("imp"); csImp.BackColor = Color.FromArgb(238, 255, 238); CellRange crImp = GridSubjRela.GetCellRange(RowNumBeforeImport, GridSubjRela.Cols.Fixed, GridSubjRela.Rows.Count - 1, GridSubjRela.Cols.Count - 1); crImp.Style = GridSubjRela.Styles["imp"]; //SetGridMap(); UIP.FrameManager.SetStatusMessage("导入完成!", true, Color.DarkGreen); } else { UIP.FrameManager.SetStatusMessage("没有新行被导入!", true, Color.Red); } //SetBackColor(GridSubjRela.GetCellRange(RowNumBeforeImport, GridSubjRela.Cols.Fixed, GridSubjRela.Rows.Count - 1, GridSubjRela.Cols.Count - 1), Color.FromArgb(238, 238, 255)); #endregion return(true); }
private void tsbSav_Click(object sender, EventArgs e) { //FinishEditing()后,不能重置DataViewRowState,用toolStrip1.Focus()代替 //GridSubjRela.FinishEditing(); toolStrip1.Focus(); //因为当数据量大时查找重复数据耗时较大,所以在保存出错后再检查主键 //if (!Ora00001()) //{ ReturnObject ro = UIP.FrameManager.ServerCall(sServerPath + "SaveSubjRela", dtSubjRela); if (ro.ErrorMessage == null) { UIP.FrameManager.SetStatusMessage("保存成功!", true, Color.DarkGreen); dtSubjRela.AcceptChanges(); #region 保存后,清除导入行的突出显示 if (GridSubjRela.Rows.Fixed != GridSubjRela.Rows.Count) { CellStyle csSaved = GridSubjRela.Styles.Add("csSaved"); csSaved.BackColor = Color.White; CellRange crSaved = GridSubjRela.GetCellRange(GridSubjRela.Rows.Fixed, GridSubjRela.Cols.Fixed, GridSubjRela.Rows.Count - 1, GridSubjRela.Cols.Count - 1); crSaved.Style = csSaved; } //SetBackColor(GridSubjRela.GetCellRange(GridSubjRela.Rows.Fixed, GridSubjRela.Cols.Fixed, GridSubjRela.Rows.Count - 1, GridSubjRela.Cols.Count - 1), Color.White); #endregion } else { if (ro.ErrorMessage.Message.Contains("ORA-00001")) { Ora00001(); } else { UIP.FrameManager.SetStatusMessage("保存失败! " + ro.ErrorMessage, true, Color.Red); } } //} }