示例#1
0
        public static void Main()
        {
            // 加入合理性檢查
            // 自訂欄位資料欄位重複
            try
            {
                DataRationalityManager.Checks.Add(new DoubleUserDefDataRAT());
            }
            catch (Exception ex)
            {
                FISCA.Presentation.Controls.MsgBox.Show("自訂資料欄位合理性檢查" + ex.Message);
            }

            LoadManager.Start();
        }
        /// <summary>
        /// 按下儲存
        /// </summary>
        /// <param name="e"></param>
        protected override void OnSaveButtonClick(EventArgs e)
        {
            try
            {
                // 檢查資料
                bool canSave = true;
                dgv.EndEdit();
                foreach (DataGridViewRow drv in dgv.Rows)
                {
                    foreach (DataGridViewCell cell in drv.Cells)
                    {
                        if (cell.ErrorText != "")
                        {
                            canSave = false;
                        }
                    }
                }

                if (canSave)
                {
                    // 刪除舊資料 UDT
                    if (_DeleteDataList.Count > 0)
                    {
                        // 真實刪除
                        foreach (DAL.UserDefData ud in _DeleteDataList)
                        {
                            ud.Deleted = true;
                        }
                        UDTTransfer.DeleteDataToUDT(_DeleteDataList);
                    }
                    _InsertDataList.Clear();

                    // 儲存資料到 UDT
                    foreach (DataGridViewRow row in dgv.Rows)
                    {
                        if (row.IsNewRow)
                        {
                            continue;
                        }
                        DAL.UserDefData udd = new UserDefineData.DAL.UserDefData();
                        // 資料轉型
                        if (row.Cells[Value.Index].Value != null)
                        {
                            udd.Value = row.Cells[Value.Index].Value.ToString();
                        }
                        udd.RefID = PrimaryKey;

                        string key = string.Empty;
                        if (row.Cells[FieldName.Index].Value != null)
                        {
                            key           = row.Cells[FieldName.Index].Value.ToString();
                            udd.FieldName = key;
                        }

                        prlp.SetAfterSaveText(key + "欄位名稱", key);
                        prlp.SetAfterSaveText(key + "值", udd.Value);


                        _InsertDataList.Add(udd);
                    }

                    // 新增至 UDT
                    UDTTransfer.InsertDataToUDT(_InsertDataList);

                    if (LoadManager.GetSystemType() == SystemType.中)
                    {
                        prlp.SetActionBy("學生", "自訂資料欄位");
                        prlp.SetAction("修改自訂資料欄位");
                        StudentRecord studRec = Student.SelectByID(PrimaryKey);
                        prlp.SetDescTitle("學生姓名:" + studRec.Name + ",學號:" + studRec.StudentNumber + ",");
                        prlp.SaveLog("", "", "student", PrimaryKey);
                    }
                }

                this.CancelButtonVisible = false;
                this.SaveButtonVisible   = false;
                _BGWorker.RunWorkerAsync();
            }
            catch (Exception ex)
            {
                FISCA.Presentation.Controls.MsgBox.Show("儲存失敗!" + ex.Message);
            }
        }