private void btnSave_Click(object sender, EventArgs e) { if (txtName.Text.Trim() == "") return; // 檢查教師名稱,驗證方式,姓名+暱稱 不能重複。 List<K12.Data.TeacherRecord> TRecs = K12.Data.Teacher.SelectAll(); Dictionary<string, K12.Data.TeacherRecord> checkStr = new Dictionary<string, K12.Data.TeacherRecord>(); foreach (K12.Data.TeacherRecord TRec in TRecs) checkStr.Add(TRec.Name + TRec.Nickname, TRec); string strName = txtName.Text + txtNickName.Text; if (checkStr.ContainsKey(strName)) { if (checkStr[strName].Status == K12.Data.TeacherRecord.TeacherStatus.一般) { MsgBox.Show("教師姓名:" + txtName.Text + ",已存在系統內,如果要使用相同姓名請加暱稱."); return; } // 當刪除狀態,修正刪除教師內的暱稱 與 TeacherID if (checkStr[strName].Status == K12.Data.TeacherRecord.TeacherStatus.刪除) { K12.Data.TeacherRecord delRec = checkStr[strName]; delRec.Nickname = delRec.ID; K12.Data.Teacher.Update(delRec); } } K12.Data.TeacherRecord teacherRec = new K12.Data.TeacherRecord(); teacherRec.Name = txtName.Text; teacherRec.Nickname = txtNickName.Text; string TeacherID = K12.Data.Teacher.Insert(teacherRec); Teacher.Instance.SyncDataBackground(TeacherID); if (chkInputData.Checked == true) { if (TeacherID != "") { Teacher.Instance.PopupDetailPane(TeacherID); Teacher.Instance.SyncDataBackground(TeacherID); } } PermRecLogProcess prlp = new PermRecLogProcess(); prlp.SaveLog("學籍.教師", "新增教師", "新增教師,姓名:" + txtName.Text + ",暱稱:" + txtNickName.Text); this.Close(); }
private void btnSave_Click(object sender, EventArgs e) { if (txtName.Text.Trim() == "") return; QueryHelper queryHelper = new QueryHelper(); string strQuery = String.Format(@"select id, teacher_name, nickname from teacher where teacher_name='{0}'", txtName.Text.Trim()); DataTable dataTable = queryHelper.Select(strQuery); IEnumerable<DataRow> teacherDatas = dataTable.Rows.Cast<DataRow>(); string TeacherID = string.Empty; K12.Data.TeacherRecord teacherRec = new K12.Data.TeacherRecord(); teacherRec.Name = txtName.Text.Trim(); if (dataTable == null || dataTable.Rows.Count == 0) teacherRec.Nickname = txtNickName.Text.Trim(); else teacherRec.Nickname = GetUniqueNickName(teacherDatas.Where(x=>x["teacher_name"].ToString() == txtName.Text.Trim())); TeacherID = K12.Data.Teacher.Insert(teacherRec); // 同步資料 // Teacher.Instance.SyncDataBackground(TeacherID); if (chkInputData.Checked) { if (!String.IsNullOrEmpty(TeacherID)) { K12.Presentation.NLDPanels.Teacher.PopupDetailPane(TeacherID); // 同步資料 // Teacher.Instance.SyncDataBackground(TeacherID); } } // log //PermRecLogProcess prlp = new PermRecLogProcess(); //prlp.SaveLog("學籍.教師", "新增教師", "新增教師,姓名:" + txtName.Text + ",暱稱:" + txtNickName.Text); this.Close(); }
private void _BKWValidate_DoWork(object sender, DoWorkEventArgs e) { BackgroundWorker bkw = (BackgroundWorker)sender; List<string> selectedFields = (List<string>)((object[])e.Argument)[0]; Dictionary<string, int> importFields = (Dictionary<string, int>)((object[])e.Argument)[1]; Workbook wb = (Workbook)((object[])e.Argument)[2]; wb.Worksheets[0].Comments.Clear(); wb.Worksheets[0].Hyperlinks.Clear(); int errorSheetIndex = wb.Worksheets.Add(); { int errc = 0; #region 命名 for (; ; errc++) { bool pass = true; string n = "錯誤&警告說明" + (errc == 0 ? "" : "(" + errc + ")"); foreach (Aspose.Cells.Worksheet var in wb.Worksheets) { if (n == var.Name) { pass = false; break; } } if (pass) break; } #endregion wb.Worksheets[errorSheetIndex].Name = "錯誤&警告說明" + (errc == 0 ? "" : "(" + errc + ")"); } string errorSheetName = wb.Worksheets[errorSheetIndex].Name; Worksheet errorSheet = wb.Worksheets[errorSheetIndex]; errorSheet.Cells[0, 0].PutValue("行號"); errorSheet.Cells[0, 1].PutValue("種類"); errorSheet.Cells[0, 2].PutValue("說明"); int errorSheetRowIndex = 1; Style errorStyle = wb.Styles[wb.Styles.Add()]; Style warningStyle = wb.Styles[wb.Styles.Add()]; Style passStyle = wb.Styles[wb.Styles.Add()]; Style errorStyle2 = wb.Styles[wb.Styles.Add()]; Style warningStyle2 = wb.Styles[wb.Styles.Add()]; //errorStyle.Pattern = BackgroundType.Solid; //errorStyle.ForegroundColor = Color.Red; errorStyle.Font.Color = Color.Red; errorStyle.Font.Underline = FontUnderlineType.Single; //warningStyle.Pattern = BackgroundType.Solid; //warningStyle.ForegroundColor = Color.Yellow; warningStyle.Font.Color = wb.GetMatchingColor(Color.Goldenrod); warningStyle.Font.Underline = FontUnderlineType.Single; //passStyle.Pattern = BackgroundType.Solid; //passStyle.ForegroundColor = Color.Green; passStyle.Font.Color = Color.Green; warningStyle2.Font.Color = wb.GetMatchingColor(Color.Goldenrod); errorStyle2.Font.Color = Color.Red; int errorCount = 0; int warningCount = 0; Dictionary<RowData, int> rowDataIndex = new Dictionary<RowData, int>(); Dictionary<int, string> fieldIndex = new Dictionary<int, string>(); foreach (string field in selectedFields) { fieldIndex.Add(importFields[field], field); } double progress = 0.0; // 讀取驗證資料工作表使用 Dictionary<string, int> checkSameDataDic = new Dictionary<string, int>(); for (int i = 1; i <= wb.Worksheets[0].Cells.MaxDataRow; i++) { string chkStr = ImportUtil.GetChekcDataStr(i, wb.Worksheets[0], importFields); if (!checkSameDataDic.ContainsKey(chkStr)) checkSameDataDic.Add(chkStr, 0); } #region 產生RowData資料 if (importFields.ContainsKey("姓名") && importFields.ContainsKey("暱稱")) { #region 用「姓名+暱稱」驗證資料 List<K12.Data.TeacherRecord> stus = K12.Data.Teacher.SelectAll(); K12.Data.TeacherRecord stu = new K12.Data.TeacherRecord(); for (int i = 1; i <= wb.Worksheets[0].Cells.MaxDataRow; i++) { // , "學號", "班級", "座號", "科別", "姓名" string name = GetTrimText("" + wb.Worksheets[0].Cells[i, importFields["姓名"]].StringValue); string nickName = GetTrimText("" + wb.Worksheets[0].Cells[i, importFields["暱稱"]].StringValue); if ((name+nickName) != "") { string rowError = ""; // 檢查重複資料 string chkStr = ImportUtil.GetChekcDataStr(i, wb.Worksheets[0], importFields); if (checkSameDataDic.ContainsKey(chkStr)) { checkSameDataDic[chkStr]++; if (checkSameDataDic[chkStr] > 1) rowError = "有重複資料!"; } #region 驗明正身 if (stus != null) { if (stus.Where(x => (x.Name.Trim() == name.Trim() && x.Nickname.Trim() == nickName.Trim())).Count() == 0) rowError = "教師不存在於系統中,請先新增教師資料!!"; } else rowError = "教師不存在於系統中,請先新增教師資料!!"; #endregion if (rowError == "") { stu = stus.Where(x => (x.Name.Trim() == name.Trim() && x.Nickname.Trim() == nickName.Trim())).ElementAt(0); if (!(stu.Status == _StudStatus)) { #region 警告非在職教師 errorSheet.Cells[errorSheetRowIndex, 0].PutValue(i + 1); errorSheet.Cells[errorSheetRowIndex, 1].PutValue("警告"); //errorSheet.Cells[errorSheetRowIndex, 2].PutValue("學生不是在校生。"); errorSheet.Cells[errorSheetRowIndex, 2].PutValue("教師不在所選擇狀態內。"); errorSheet.Cells[errorSheetRowIndex, 0].Style = warningStyle; errorSheet.Cells[errorSheetRowIndex, 1].Style = warningStyle2; errorSheet.Cells[errorSheetRowIndex, 2].Style = warningStyle2; errorSheet.Hyperlinks.Add(errorSheetRowIndex, 0, 1, 1, "'" + wb.Worksheets[0].Name + "'!" + wb.Worksheets[0].Cells[i, 0].Name); errorSheet.AutoFitRow(errorSheetRowIndex); errorSheetRowIndex++; warningCount++; #endregion } RowData rowdata = new RowData(); rowdata.ID = stu.ID; foreach (int index in fieldIndex.Keys) { if (wb.Worksheets[0].Cells[i, index].Type == CellValueType.IsDateTime) { rowdata.Add(fieldIndex[index], wb.Worksheets[0].Cells[i, index].DateTimeValue.ToString()); } else rowdata.Add(fieldIndex[index], GetTrimText("" + wb.Worksheets[0].Cells[i, index].StringValue)); } rowDataIndex.Add(rowdata, i); } else { errorCount++; errorSheet.Cells[errorSheetRowIndex, 0].PutValue(i + 1); errorSheet.Cells[errorSheetRowIndex, 1].PutValue("錯誤"); errorSheet.Cells[errorSheetRowIndex, 2].PutValue(rowError); errorSheet.Cells[errorSheetRowIndex, 0].Style = errorStyle; errorSheet.Cells[errorSheetRowIndex, 1].Style = errorStyle2; errorSheet.Cells[errorSheetRowIndex, 2].Style = errorStyle2; errorSheet.Hyperlinks.Add(errorSheetRowIndex, 0, 1, 1, "'" + wb.Worksheets[0].Name + "'!" + wb.Worksheets[0].Cells[i, 0].Name); wb.Worksheets[0].Hyperlinks.Add(i, 0, 1, 1, "'" + errorSheetName + "'!" + errorSheet.Cells[errorSheetRowIndex, 0].Name); errorSheet.AutoFitRow(errorSheetRowIndex); errorSheetRowIndex++; wb.Worksheets[0].Cells[i, 0].Style = errorStyle; } } else { bool isNullRow = true; for (byte c = 0; c < wb.Worksheets[0].Cells.MaxDataColumn; c++) { if (GetTrimText("" + wb.Worksheets[0].Cells[i, c].StringValue) != "") isNullRow = false; } if (!isNullRow) { errorCount++; errorSheet.Cells[errorSheetRowIndex, 0].PutValue(i + 1); errorSheet.Cells[errorSheetRowIndex, 1].PutValue("錯誤"); errorSheet.Cells[errorSheetRowIndex, 2].PutValue("驗證欄位(姓名+暱稱)不得空白"); errorSheet.Cells[errorSheetRowIndex, 0].Style = errorStyle; errorSheet.Cells[errorSheetRowIndex, 1].Style = errorStyle2; errorSheet.Cells[errorSheetRowIndex, 2].Style = errorStyle2; errorSheet.Hyperlinks.Add(errorSheetRowIndex, 0, 1, 1, "'" + wb.Worksheets[0].Name + "'!" + wb.Worksheets[0].Cells[i, 0].Name); wb.Worksheets[0].Hyperlinks.Add(i, 0, 1, 1, "'" + errorSheetName + "'!" + errorSheet.Cells[errorSheetRowIndex, 0].Name); errorSheet.AutoFitRow(errorSheetRowIndex); errorSheetRowIndex++; wb.Worksheets[0].Cells[i, 0].Style = errorStyle; } } if (bkw.CancellationPending) { e.Cancel = true; _ErrorWB = wb; return; } progress = ((double)i) * 100.0 / 100000; bkw.ReportProgress((int)progress, new int[] { errorCount, warningCount }); } #endregion } #endregion #region 驗證資料 List<string> list = new List<string>(); foreach (RowData row in rowDataIndex.Keys) { if (!list.Contains(row.ID)) list.Add(row.ID); } //_Process.StartValidate(list); if (ValidateStart != null) { SmartSchool.API.PlugIn.Import.ValidateStartEventArgs args = new SmartSchool.API.PlugIn.Import.ValidateStartEventArgs(); args.List = list.ToArray(); ValidateStart(this, args); } double totleCount = (double)rowDataIndex.Count; double count = 0.0; foreach (RowData row in rowDataIndex.Keys) { #region 驗證 string rowError = ""; Dictionary<string, string> errorFields, warningFields; //RowDataValidatedEventArgs args = _Process.ValidateRow(row, selectedFields); SmartSchool.API.PlugIn.Import.ValidateRowEventArgs args = new SmartSchool.API.PlugIn.Import.ValidateRowEventArgs(); args.Data = row; args.SelectFields.AddRange(selectedFields); if (ValidateRow != null) { ValidateRow(this, args); } errorFields = args.ErrorFields; warningFields = args.WarningFields; rowError += args.ErrorMessage; if (rowError == "" && errorFields.Count == 0 && warningFields.Count == 0) { wb.Worksheets[0].Cells[rowDataIndex[row], 0].Style = passStyle; } else { string message = ""; bool hasError = false; if (rowError != "" || errorFields.Count != 0) { errorCount++; hasError = true; message = rowError; message += (message == "" ? "" : "\n") + ""; foreach (string key in errorFields.Keys) { message += (message == "" ? "" : "\n") + " " + key + ":" + errorFields[key]; } errorSheet.Cells[errorSheetRowIndex, 0].PutValue(rowDataIndex[row] + 1); errorSheet.Cells[errorSheetRowIndex, 1].PutValue(hasError ? "錯誤" : "警告"); errorSheet.Cells[errorSheetRowIndex, 2].PutValue(message); errorSheet.Cells[errorSheetRowIndex, 0].Style = errorStyle; errorSheet.Cells[errorSheetRowIndex, 1].Style = errorStyle2; errorSheet.Cells[errorSheetRowIndex, 2].Style = errorStyle2; errorSheet.Hyperlinks.Add(errorSheetRowIndex, 0, 1, 1, "'" + wb.Worksheets[0].Name + "'!" + wb.Worksheets[0].Cells[rowDataIndex[row], 0].Name); wb.Worksheets[0].Hyperlinks.Add(rowDataIndex[row], 0, 1, 1, "'" + errorSheetName + "'!" + errorSheet.Cells[errorSheetRowIndex, 0].Name); errorSheet.AutoFitRow(errorSheetRowIndex); errorSheetRowIndex++; } message = ""; if (warningFields.Count != 0) { if (!hasError) warningCount++; message += (message == "" ? "" : "\n") + ""; foreach (string key in warningFields.Keys) { message += (message == "" ? "" : "\n") + " " + key + ":" + warningFields[key]; } errorSheet.Cells[errorSheetRowIndex, 0].PutValue(rowDataIndex[row] + 1); errorSheet.Cells[errorSheetRowIndex, 1].PutValue("警告"); errorSheet.Cells[errorSheetRowIndex, 2].PutValue(message); errorSheet.Cells[errorSheetRowIndex, 0].Style = warningStyle; errorSheet.Cells[errorSheetRowIndex, 1].Style = warningStyle2; errorSheet.Cells[errorSheetRowIndex, 2].Style = warningStyle2; errorSheet.Hyperlinks.Add(errorSheetRowIndex, 0, 1, 1, "'" + wb.Worksheets[0].Name + "'!" + wb.Worksheets[0].Cells[rowDataIndex[row], 0].Name); if (!hasError) wb.Worksheets[0].Hyperlinks.Add(rowDataIndex[row], 0, 1, 1, "'" + errorSheetName + "'!" + errorSheet.Cells[errorSheetRowIndex, 0].Name); errorSheet.AutoFitRow(errorSheetRowIndex); errorSheetRowIndex++; } wb.Worksheets[0].Cells[rowDataIndex[row], 0].Style = hasError ? errorStyle : warningStyle; } #endregion if (bkw.CancellationPending) { e.Cancel = true; _ErrorWB = wb; return; } count++; bkw.ReportProgress((int)(progress + count * (100.0 - progress) / totleCount), new int[] { errorCount, warningCount }); } //_Process.FinishValidate(); if (ValidateComplete != null) ValidateComplete(this, new EventArgs()); #endregion List<RowData> rows = new List<RowData>(); rows.AddRange(rowDataIndex.Keys); bkw.ReportProgress(100, new int[] { errorCount, warningCount }); errorSheet.AutoFitColumn(0); errorSheet.AutoFitColumn(1, 1, 500); errorSheet.AutoFitColumn(2, 1, 500); e.Result = new object[] { wb, errorCount == 0, rows, selectedFields }; }
private void btnImport_Click(object sender, EventArgs e) { Aspose.Cells.Workbook wb = new Aspose.Cells.Workbook(); try { wb.Open(this.textBoxX1.Text); Aspose.Cells.Worksheet ws = wb.Worksheets[0]; int rowIndex = 1; int totalCount = 0; while (ws.Cells[rowIndex, 0].Value != null && !string.IsNullOrWhiteSpace(ws.Cells[rowIndex, 0].Value.ToString())) { rowIndex += 1; totalCount += 1; } this.progressBarX1.Maximum = totalCount; rowIndex = 1; AccessHelper ah = new AccessHelper(); while (ws.Cells[rowIndex, 0].Value != null && !string.IsNullOrWhiteSpace(ws.Cells[rowIndex, 0].Value.ToString())) { string ntu_sys_no = GetCellValue(ws.Cells[rowIndex, 0]); string tea_name = GetCellValue(ws.Cells[rowIndex, 1]); string tea_eng_name = GetCellValue(ws.Cells[rowIndex, 2]); string tea_account = GetCellValue(ws.Cells[rowIndex, 7]); string tea_email = GetCellValue(ws.Cells[rowIndex, 8]); string tea_office_telno = GetCellValue(ws.Cells[rowIndex, 12]); string unit = GetCellValue(ws.Cells[rowIndex, 15]); //string emp_no = ws.Cells[rowIndex, 5].Value.ToString(); K12.Data.TeacherRecord tea = new K12.Data.TeacherRecord(); tea.Name = tea_name; tea.TALoginName = tea_account; tea.Email = tea_email; string newTID = K12.Data.Teacher.Insert(tea); //K12.Data.Teacher.Update(tea); UDT.TeacherExtVO udtTe = new UDT.TeacherExtVO(); udtTe.EnglishName = tea_eng_name; udtTe.TeacherID = int.Parse(newTID); udtTe.NtuSystemNo = ntu_sys_no; //udtTe.EmployeeNo = emp_no; udtTe.OtherPhone = tea_office_telno; udtTe.MajorWorkPlace = unit; List<ActiveRecord> rec = new List<ActiveRecord>(); rec.Add(udtTe); ah.SaveAll(rec); rowIndex += 1; this.labelX1.Text = string.Format("{0} / {1} ", rowIndex.ToString(), totalCount.ToString()); this.progressBarX1.Value = rowIndex; } } catch (Exception ex) { MessageBox.Show(ex.Message); return; } }
private void btnDelete_Click(object sender, EventArgs e) { if (lvCaseMeeting.SelectedItems.Count == 1) { DAO.UDT_CounselCaseMeetingRecordDef CaseMeetingRecord = lvCaseMeeting.SelectedItems[0].Tag as DAO.UDT_CounselCaseMeetingRecordDef; if (CaseMeetingRecord != null) { DAO.LogTransfer logTransfer = new DAO.LogTransfer(); K12.Data.StudentRecord studRec = K12.Data.Student.SelectByID(PrimaryKey); StringBuilder logData = new StringBuilder(); logData.AppendLine("刪除" + Utility.ConvertString1(studRec)); // 取得 XML 解析後 Dictionary <string, string> item_AttendessDict = Utility.GetConvertCounselXMLVal_Attendees(CaseMeetingRecord.Attendees); Dictionary <string, string> item_CounselTypeDict = Utility.GetConvertCounselXMLVal_CounselType(CaseMeetingRecord.CounselType); Dictionary <string, string> item_CounselTypeKindDict = Utility.GetConvertCounselXMLVal_CounselTypeKind(CaseMeetingRecord.CounselTypeKind); if (FISCA.Presentation.Controls.MsgBox.Show("請問是否確定刪除個案會議?", "刪除個案會議", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.Yes) { // log logData.AppendLine("個案編號:" + CaseMeetingRecord.CaseNo); if (CaseMeetingRecord.MeetingDate.HasValue) { logData.AppendLine("會議日期" + CaseMeetingRecord.MeetingDate.Value.ToShortDateString()); } K12.Data.TeacherRecord tRec = K12.Data.Teacher.SelectByID(CaseMeetingRecord.CounselTeacherID.ToString()); if (tRec != null) { if (string.IsNullOrEmpty(tRec.Nickname)) { logData.AppendLine("晤談老師:" + tRec.Name); } else { logData.AppendLine("晤談老師:" + tRec.Name + "(" + tRec.Nickname + ")"); } } logData.AppendLine("會議時間:" + CaseMeetingRecord.MeetigTime); logData.AppendLine("會議事由:" + CaseMeetingRecord.MeetingCause); logData.AppendLine("會議地點:" + CaseMeetingRecord.Place); logData.AppendLine("內容要點:" + CaseMeetingRecord.ContentDigest); logData.AppendLine("記錄者:" + CaseMeetingRecord.AuthorID); logData.AppendLine("記錄者姓名:" + CaseMeetingRecord.AuthorName); logData.AppendLine("參與人員:"); foreach (KeyValuePair <string, string> data in item_AttendessDict) { if (!string.IsNullOrEmpty(data.Value)) { logData.AppendLine(data.Key + ":" + data.Value); } } logData.AppendLine("輔導方式:"); foreach (KeyValuePair <string, string> data in item_CounselTypeDict) { if (!string.IsNullOrEmpty(data.Value)) { logData.AppendLine(data.Key + ":" + data.Value); } } logData.AppendLine("輔導歸類:"); foreach (KeyValuePair <string, string> data in item_CounselTypeKindDict) { if (!string.IsNullOrEmpty(data.Value)) { logData.AppendLine(data.Key + ":" + data.Value); } } _UDTTransfer.DeleteCaseMeetingRecord(CaseMeetingRecord); logTransfer.SaveLog("學生.輔導個案會議-刪除", "刪除", "student", PrimaryKey, logData); _BGRun(); } } } else { FISCA.Presentation.Controls.MsgBox.Show("請選擇資料."); } }