private void btnImport_Click(object sender, EventArgs e) { try { pgImport.Minimum = 0; pgImport.Maximum = 100; pgImport.Value = 0; btnImport.Enabled = false; ImportMessage("產生匯入資料…"); XmlElement output = DSXmlHelper.LoadXml("<ImportCourse/>"); SheetHelper sheet = new SheetHelper(Context.SourceFile); SheetRowSource sheetSource = new SheetRowSource(sheet, Context); int ProgressStep = 10; int progress = 0, firstRow = sheet.FirstDataRowIndex, maxRow = sheet.MaxDataRowIndex; for (int rowIndex = firstRow; rowIndex <= maxRow; rowIndex++) { sheetSource.BindRow(rowIndex); XmlElement record = CreateChild(output, "Course"); if (Context.CurrentMode == ImportMode.Insert) { GenerateInsertXml(sheetSource, record); } else { GenerateUpdateXml(sheetSource, record); } //回報進度。 if (((++progress) % ProgressStep) == 0) { int percentage = progress * 100 / (maxRow - firstRow); pgImport.Value = percentage; } } if (Context.SelectedFields.Contains("所屬班級")) { ConvertClassField(output); } if (Context.SelectedFields.Contains("評量設定")) { ConvertTemplateField(output); } pgImport.Value = 100; ImportMessage("上傳資料到主機,請稍後…"); //GeneralActionLog log = new GeneralActionLog(); //log.Source = "匯入課程基本資料"; //log.Diagnostics = output.OuterXml; if (Context.CurrentMode == ImportMode.Insert) { if (UpdateCourseRequired()) { Context.DataSource.InsertImportData(output); } //log.ActionName = "新增匯入"; //log.Description = "新增匯入 " + sheet.DataRowCount + " 筆課程資料。"; } else { if (UpdateCourseRequired()) { Context.DataSource.UpdateImportData(output); } //log.ActionName = "更新匯入"; //log.Description = "更新匯入 " + sheet.DataRowCount + " 筆課程資料。"; } //CurrentUser.Instance.AppLog.Write(log); UpdateTeacherInformation(sheet); ImportMessage("匯入完成。"); wpImport.FinishButtonEnabled = eWizardButtonState.True; wpImport.BackButtonEnabled = eWizardButtonState.False; //SmartSchool.CourseRelated.CourseEntity.Instance.InvokeAfterCourseInsert(); //SmartSchool.Broadcaster.Events.Items["課程/新增"].Invoke(); //SmartSchool.TeacherRelated.Teacher tea = SmartSchool.TeacherRelated.Teacher.Instance; //tea.Reflash(); Course.Instance.SyncAllBackground(); JHSchool.Data.JHCourse.RemoveAll(); JHSchool.Data.JHCourse.SelectAll(); eh(this, EventArgs.Empty); } catch (Exception ex) { //CurrentUser user = CurrentUser.Instance; //BugReporter.ReportException(user.SystemName, user.SystemVersion, ex, false); btnImport.Enabled = true; ImportMessage("上傳資料失敗"); ExceptionReport report = new ExceptionReport(); TextViewer.ViewXml(report.Transform(ex)); FISCA.Presentation.Controls.MsgBox.Show(ex.Message); } }
private void btnImport_Click(object sender, EventArgs e) { try { pgImport.Minimum = 0; pgImport.Maximum = 100; pgImport.Value = 0; btnImport.Enabled = false; ImportMessage("產生匯入資料…"); XmlElement output = DSXmlHelper.LoadXml("<ImportClass/>"); SheetHelper sheet = new SheetHelper(Context.SourceFile); SheetRowSource sheetSource = new SheetRowSource(sheet, Context); int ProgressStep = 10; int progress = 0, firstRow = sheet.FirstDataRowIndex, maxRow = sheet.MaxDataRowIndex; for (int rowIndex = firstRow; rowIndex <= maxRow; rowIndex++) { sheetSource.BindRow(rowIndex); XmlElement record = CreateChild(output, "Class"); if (Context.CurrentMode == ImportMode.Insert) { GenerateInsertXml(sheetSource, record); } else { GenerateUpdateXml(sheetSource, record); } //回報進度。 if (((++progress) % ProgressStep) == 0) { int percentage = progress * 100 / (maxRow - firstRow); pgImport.Value = percentage; } } if (Context.SelectedFields.Contains("班導師")) { ConvertTeacherField(output); } //if (Context.SelectedFields.Contains("科別")) // ConvertDeptField(output); if (Context.SelectedFields.Contains("課程規劃")) { ConvertGraduationPlanField(output); } if (Context.SelectedFields.Contains("計算規則")) { ConvertScoreCalcRuleField(output); } pgImport.Value = 100; ImportMessage("上傳資料到主機,請稍後…"); //GeneralActionLog log = new GeneralActionLog(); //log.Source = "匯入班級基本資料"; //log.Diagnostics = output.OuterXml; if (Context.CurrentMode == ImportMode.Insert) { Context.DataSource.InsertImportData(output); //log.ActionName = "新增匯入"; //log.Description = "新增匯入 " + sheet.DataRowCount + " 筆班級資料。"; } else { Context.DataSource.UpdateImportData(output); //log.ActionName = "更新匯入"; //log.Description = "更新匯入 " + sheet.DataRowCount + " 筆班級資料。"; } //CurrentUser.Instance.AppLog.Write(log); ImportMessage("匯入完成。"); wpImport.FinishButtonEnabled = eWizardButtonState.True; wpImport.BackButtonEnabled = eWizardButtonState.False; Class.Instance.SyncAllBackground(); // 與 DAL 同步 JHSchool.Data.JHClass.RemoveAll(); JHSchool.Data.JHClass.SelectAll(); //SmartSchool.ClassRelated.Class.Instance.Reflash(); } catch (Exception ex) { //CurrentUser user = CurrentUser.Instance; //BugReporter.ReportException(user.SystemName, user.SystemVersion, ex, false); btnImport.Enabled = true; ImportMessage("上傳資料失敗"); FISCA.Presentation.Controls.MsgBox.Show(ex.Message); } }
private void UpdateTeacherInformation(SheetHelper sheet) { Dictionary <string, string> selectedFields = new Dictionary <string, string>(); foreach (string each in Context.SelectedFields) { selectedFields.Add(each, each); } if (!UpdateRequired(selectedFields)) { return; } bool doAddRequired = false; ImportCondition condition = GetIdentifyField(); CourseLookup lookup = new CourseLookup(condition); TeacherLookup tlookup = Context.Extensions[TeacherLookup.Name] as TeacherLookup; SheetRowSource sheetSource = new SheetRowSource(sheet, Context); XmlElement removeReq = DSXmlHelper.LoadXml("<Request/>"); XmlElement addReq = DSXmlHelper.LoadXml("<Request/>"); int firstRow = sheet.FirstDataRowIndex, maxRow = sheet.MaxDataRowIndex; for (int rowIndex = firstRow; rowIndex <= maxRow; rowIndex++) { sheetSource.BindRow(rowIndex); string courseId = lookup.GetCourseID(sheetSource); if (string.IsNullOrEmpty(courseId)) { throw new Exception("資料更新過程中,資料可能被另一使用者更改,匯入資料失敗。"); } if (selectedFields.ContainsKey("授課教師一")) { XmlElement removeItem = CreateChild(removeReq, "Course"); CreateChild(removeItem, "CourseID").InnerText = courseId; CreateChild(removeItem, "Sequence").InnerText = "1"; } if (selectedFields.ContainsKey("授課教師二")) { XmlElement removeItem = CreateChild(removeReq, "Course"); CreateChild(removeItem, "CourseID").InnerText = courseId; CreateChild(removeItem, "Sequence").InnerText = "2"; } if (selectedFields.ContainsKey("授課教師三")) { XmlElement removeItem = CreateChild(removeReq, "Course"); CreateChild(removeItem, "CourseID").InnerText = courseId; CreateChild(removeItem, "Sequence").InnerText = "3"; } if (selectedFields.ContainsKey("授課教師一")) { string teacherId = tlookup.GetTeacherID(sheetSource.GetFieldData("授課教師一")); if (!string.IsNullOrEmpty(teacherId)) { XmlElement addItem = CreateChild(addReq, "CourseTeacher"); CreateChild(addItem, "RefCourseID").InnerText = courseId; CreateChild(addItem, "RefTeacherID").InnerText = teacherId; CreateChild(addItem, "Sequence").InnerText = "1"; doAddRequired = true; } } if (selectedFields.ContainsKey("授課教師二")) { string teacherId = tlookup.GetTeacherID(sheetSource.GetFieldData("授課教師二")); if (!string.IsNullOrEmpty(teacherId)) { XmlElement addItem = CreateChild(addReq, "CourseTeacher"); CreateChild(addItem, "RefCourseID").InnerText = courseId; CreateChild(addItem, "RefTeacherID").InnerText = teacherId; CreateChild(addItem, "Sequence").InnerText = "2"; doAddRequired = true; } } if (selectedFields.ContainsKey("授課教師三")) { string teacherId = tlookup.GetTeacherID(sheetSource.GetFieldData("授課教師三")); if (!string.IsNullOrEmpty(teacherId)) { XmlElement addItem = CreateChild(addReq, "CourseTeacher"); CreateChild(addItem, "RefCourseID").InnerText = courseId; CreateChild(addItem, "RefTeacherID").InnerText = teacherId; CreateChild(addItem, "Sequence").InnerText = "3"; doAddRequired = true; } } } ImportDataAccess da = Context.DataSource as ImportDataAccess; da.RemoveCourseTeachers(removeReq); if (doAddRequired) { da.AddCourseTeachers(addReq); } }