/// <summary>
        /// 取得單筆學生UDT資料,並轉換成 dic
        /// </summary>
        /// <param name="ID"></param>
        /// <returns></returns>
        public static Dictionary<string, DAL.UserDefData> GetDataFromUDTDict(string ID)
        {
            // 回傳資料
            Dictionary<string, DAL.UserDefData> retValue = new Dictionary<string, UserDefineData.DAL.UserDefData>();

            // 刪除可能多餘資料
            List<DAL.UserDefData> DeleteList = new List<UserDefineData.DAL.UserDefData>();

            // 取得 UDT 內
            foreach (DAL.UserDefData ud in GetDataFromUDT(ID))
                if (!retValue.ContainsKey(ud.FieldName))
                {
                    ud.isNull = false;
                    retValue.Add(ud.FieldName, ud);
                }
                else
                {
                    ud.Deleted = true;
                    DeleteList.Add(ud);
                }

            if (DeleteList.Count > 0)
                DeleteDataToUDT(DeleteList);

            // 取得自訂欄位設定,沒有使用空白
            foreach (string FName in Global.GetUserConfigData().Keys)
                if (!retValue.ContainsKey(FName))
                {
                    DAL.UserDefData ud = new UserDefineData.DAL.UserDefData();
                    ud.RefID = ID;
                    ud.FieldName = FName;
                    ud.Value = "";
                    retValue.Add(FName, ud);
                }
            return retValue;
        }
        /// <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);
            }
        }
        public override void InitializeImport(SmartSchool.API.PlugIn.Import.ImportWizard wizard)
        {
            // 取得學生資料
            Dictionary<string, StudentRecord> Students = new Dictionary<string, StudentRecord>();

            // 取得自訂資料欄位資料
            Dictionary<string,List<DAL.UserDefData>> UserDefDataDict = new Dictionary<string,List<UserDefineData.DAL.UserDefData>> ();

            // 取得使用這設定
            Dictionary<string, string> UserSetDataTypeDict = new Dictionary<string, string>();

            wizard.PackageLimit = 3000;
            wizard.ImportableFields.AddRange("欄位名稱","值");
            wizard.RequiredFields.AddRange("欄位名稱");
            wizard.ValidateStart += delegate(object sender, SmartSchool.API.PlugIn.Import.ValidateStartEventArgs e)
            {
                Students.Clear();
                UserDefDataDict.Clear();
                UserSetDataTypeDict.Clear();

                UserSetDataTypeDict = Global.GetUserConfigData();

                // 取得學生資料
                foreach (StudentRecord studRec in Student.SelectByIDs(e.List))
                    if (!Students.ContainsKey(studRec.ID))
                        Students.Add(studRec.ID, studRec);

                // 取得自訂資料欄位
                MultiThreadWorker<string> loader1 = new MultiThreadWorker<string>();
                loader1.MaxThreads = 3;
                loader1.PackageSize = 250;
                loader1.PackageWorker += delegate(object sender1, PackageWorkEventArgs<string> e1)
                {
                    foreach (DAL.UserDefData udd in UDTTransfer.GetDataFromUDT(e.List.ToList<string>()))
                    {
                        if(UserDefDataDict.ContainsKey(udd.RefID ))
                            UserDefDataDict[udd.RefID].Add(udd);
                        else
                        {
                            List<DAL.UserDefData> dd = new List<UserDefineData.DAL.UserDefData>();
                            dd.Add(udd);
                            UserDefDataDict.Add(udd.RefID,dd);
                        }
                    }
                };
                loader1.Run(e.List);
            };

            wizard.ValidateRow += delegate(object sender, SmartSchool.API.PlugIn.Import.ValidateRowEventArgs e)
            {
                int i = 0;
                // 檢查學生是否存在
                StudentRecord studRec = null;
                if (Students.ContainsKey(e.Data.ID))
                    studRec = Students[e.Data.ID];
                else
                {
                    e.ErrorMessage = "沒有這位學生" + e.Data.ID;
                    return;
                }

                // 驗證格式資料
                // 檢查每位學生欄位是否有重複
                List<string> CheckSameList = new List<string>();
                bool InputFormatPass = true;
                foreach (string field in e.SelectFields)
                {
                    string value = e.Data[field].Trim();
                    switch (field)
                    {
                        default:
                            break;

                        case "欄位名稱":
                            if (string.IsNullOrEmpty(value))
                            {
                                InputFormatPass &= false;
                                e.ErrorFields.Add(field, "不允許空白");
                            }
                            string key = e.Data.ID + value;
                            if (CheckSameList.Contains(key))
                            {
                                InputFormatPass &= false;
                                e.ErrorFields.Add(field, "欄位名稱:"+value+" 不允許重複");
                            }
                            CheckSameList.Add(key);
                            break;
                        case "值":
                            decimal dd; DateTime dt;
                            if (!string.IsNullOrEmpty(value))
                            {
                                if (e.Data.ContainsKey("欄位名稱"))
                                {
                                    string str = e.Data["欄位名稱"];

                                    if (UserSetDataTypeDict.ContainsKey(str))
                                    {
                                        if (UserSetDataTypeDict[str] == "Number")
                                        {
                                            if (!decimal.TryParse(value, out dd))
                                            {
                                                e.ErrorFields.Add(field, "非數字型態");
                                                InputFormatPass &= false;
                                                break;
                                            }
                                        }

                                        if (UserSetDataTypeDict[str] == "Date")
                                        {
                                            if (!DateTime.TryParse(value, out dt))
                                            {
                                                e.ErrorFields.Add(field, "非日期型態");
                                                InputFormatPass &= false;
                                                break;
                                            }
                                        }
                                    }
                                }
                            }

                            break;
                    }
                }

            };

            wizard.ImportPackage += delegate(object sender, SmartSchool.API.PlugIn.Import.ImportPackageEventArgs e)
            {

                Dictionary<string, List<RowData>> id_Rows = new Dictionary<string, List<RowData>>();
                foreach (RowData data in e.Items)
                {
                    if (!id_Rows.ContainsKey(data.ID))
                        id_Rows.Add(data.ID, new List<RowData>());
                    id_Rows[data.ID].Add(data);
                }

                List<DAL.UserDefData> InsertList = new List<UserDefineData.DAL.UserDefData> ();
                List<DAL.UserDefData> DeleteList = new List<UserDefineData.DAL.UserDefData>();

                foreach (string id in id_Rows.Keys)
                {
                    foreach (RowData data in id_Rows[id])
                    {
                        string FName = string.Empty, Value = string.Empty;
                        if (data.ContainsKey("欄位名稱"))
                            FName = data["欄位名稱"];

                        if (data.ContainsKey("值"))
                            Value = data["值"];

                        // 將需要刪除放入
                        if (UserDefDataDict.ContainsKey(id))
                        foreach (DAL.UserDefData udd in UserDefDataDict[id])
                            if (udd.FieldName == FName)
                            {
                                udd.Deleted = true;
                                DeleteList.Add(udd);
                            }

                        // 新增資料
                        DAL.UserDefData uddNew = new UserDefineData.DAL.UserDefData();
                        uddNew.FieldName = FName;
                        uddNew.RefID = id;
                        uddNew.Value = Value;
                        InsertList.Add(uddNew);
                    }
                }

                try
                {
                    // 先刪除舊的資料在新增新的
                    if(DeleteList.Count >0)
                        UDTTransfer.DeleteDataToUDT(DeleteList);

                    if (InsertList.Count > 0)
                        UDTTransfer.InsertDataToUDT(InsertList );

                    JHSchool.Student.Instance.SyncAllBackground();
                }
                catch (Exception ex) { }

            };
        }
        /// <summary>
        /// 取得單筆學生UDT資料,包括"自定資料管理" (add by 小郭, 2013/12/16)
        /// </summary>
        /// <param name="StudentID"></param>
        /// <returns></returns>
        public static List<DAL.UserDefData> GetDataFromUDTIncludeUserConfig(string StudentID)
        {
            // 回傳資料
            List<DAL.UserDefData> result = new List<DAL.UserDefData>();
            // 暫存資料, Key: 欄位名稱; Value: DAL.UserDefData
            Dictionary<string, DAL.UserDefData> temp = new Dictionary<string, UserDefineData.DAL.UserDefData>();
            // 刪除名單, 用來刪除可能重複的欄位名稱
            List<DAL.UserDefData> DeleteList = new List<UserDefineData.DAL.UserDefData>();

            // 取得UDT的資料
            List<DAL.UserDefData> userDefDataList = GetDataFromUDT(StudentID);
            // 依照uid反向排序
            userDefDataList.Sort(delegate(DAL.UserDefData obj1, DAL.UserDefData obj2)
            {
                string compare1 = (obj1.UID).PadLeft(20, '0');
                string compare2 = (obj2.UID).PadLeft(20, '0');
                return compare2.CompareTo(compare1);
            });

            // 找出重複的,並保留新的資料(uid比較大的為新的資料)
            foreach (DAL.UserDefData rec in userDefDataList)
            {
                if (!temp.ContainsKey(rec.FieldName))
                {
                    rec.isNull = false;
                    temp.Add(rec.FieldName, rec);
                }
                else
                {
                    // 假如找到重複的欄位名稱, 加入刪除名單, 因為排序過, 所以會刪除比較舊的資料
                    rec.Deleted = true;
                    DeleteList.Add(rec);
                }
            }

            if (DeleteList.Count > 0)
                DeleteDataToUDT(DeleteList);

            // 處理完需要刪除的名單後, 正向排序
            userDefDataList = temp.Values.ToList();
            userDefDataList.Reverse();

            // 取得自訂欄位設定,沒有使用空白
            int index = 0;
            foreach (string FName in Global.GetUserConfigData().Keys)
            {
                DAL.UserDefData ud;
                if (!temp.ContainsKey(FName))
                {
                    ud = new UserDefineData.DAL.UserDefData();
                    ud.RefID = StudentID;
                    ud.FieldName = FName;
                    ud.Value = "";
                }
                else
                {
                    ud = temp[FName];
                    // 先移除既有的資料
                    userDefDataList.Remove(ud);
                }

                // 新增到前面
                userDefDataList.Insert(index++, ud);
            }

            // 回傳List
            result = userDefDataList;

            return result;
        }
        public override void InitializeImport(SmartSchool.API.PlugIn.Import.ImportWizard wizard)
        {
            // 取得學生資料
            Dictionary <string, StudentRecord> Students = new Dictionary <string, StudentRecord>();

            // 取得自訂資料欄位資料
            Dictionary <string, List <DAL.UserDefData> > UserDefDataDict = new Dictionary <string, List <UserDefineData.DAL.UserDefData> > ();

            // 取得使用這設定
            Dictionary <string, string> UserSetDataTypeDict = new Dictionary <string, string>();

            wizard.PackageLimit = 3000;
            wizard.ImportableFields.AddRange("欄位名稱", "值");
            wizard.RequiredFields.AddRange("欄位名稱");
            wizard.ValidateStart += delegate(object sender, SmartSchool.API.PlugIn.Import.ValidateStartEventArgs e)
            {
                Students.Clear();
                UserDefDataDict.Clear();
                UserSetDataTypeDict.Clear();

                UserSetDataTypeDict = Global.GetUserConfigData();

                // 取得學生資料
                foreach (StudentRecord studRec in Student.SelectByIDs(e.List))
                {
                    if (!Students.ContainsKey(studRec.ID))
                    {
                        Students.Add(studRec.ID, studRec);
                    }
                }

                // 取得自訂資料欄位
                MultiThreadWorker <string> loader1 = new MultiThreadWorker <string>();
                loader1.MaxThreads     = 3;
                loader1.PackageSize    = 250;
                loader1.PackageWorker += delegate(object sender1, PackageWorkEventArgs <string> e1)
                {
                    foreach (DAL.UserDefData udd in UDTTransfer.GetDataFromUDT(e.List.ToList <string>()))
                    {
                        if (UserDefDataDict.ContainsKey(udd.RefID))
                        {
                            UserDefDataDict[udd.RefID].Add(udd);
                        }
                        else
                        {
                            List <DAL.UserDefData> dd = new List <UserDefineData.DAL.UserDefData>();
                            dd.Add(udd);
                            UserDefDataDict.Add(udd.RefID, dd);
                        }
                    }
                };
                loader1.Run(e.List);
            };


            wizard.ValidateRow += delegate(object sender, SmartSchool.API.PlugIn.Import.ValidateRowEventArgs e)
            {
                int i = 0;
                // 檢查學生是否存在
                StudentRecord studRec = null;
                if (Students.ContainsKey(e.Data.ID))
                {
                    studRec = Students[e.Data.ID];
                }
                else
                {
                    e.ErrorMessage = "沒有這位學生" + e.Data.ID;
                    return;
                }

                // 驗證格式資料
                // 檢查每位學生欄位是否有重複
                List <string> CheckSameList   = new List <string>();
                bool          InputFormatPass = true;
                foreach (string field in e.SelectFields)
                {
                    string value = e.Data[field].Trim();
                    switch (field)
                    {
                    default:
                        break;

                    case "欄位名稱":
                        if (string.IsNullOrEmpty(value))
                        {
                            InputFormatPass &= false;
                            e.ErrorFields.Add(field, "不允許空白");
                        }
                        string key = e.Data.ID + value;
                        if (CheckSameList.Contains(key))
                        {
                            InputFormatPass &= false;
                            e.ErrorFields.Add(field, "欄位名稱:" + value + " 不允許重複");
                        }
                        CheckSameList.Add(key);
                        break;

                    case "值":
                        decimal dd; DateTime dt;
                        if (!string.IsNullOrEmpty(value))
                        {
                            if (e.Data.ContainsKey("欄位名稱"))
                            {
                                string str = e.Data["欄位名稱"];

                                if (UserSetDataTypeDict.ContainsKey(str))
                                {
                                    if (UserSetDataTypeDict[str] == "Number")
                                    {
                                        if (!decimal.TryParse(value, out dd))
                                        {
                                            e.ErrorFields.Add(field, "非數字型態");
                                            InputFormatPass &= false;
                                            break;
                                        }
                                    }

                                    if (UserSetDataTypeDict[str] == "Date")
                                    {
                                        if (!DateTime.TryParse(value, out dt))
                                        {
                                            e.ErrorFields.Add(field, "非日期型態");
                                            InputFormatPass &= false;
                                            break;
                                        }
                                    }
                                }
                            }
                        }

                        break;
                    }
                }
            };

            wizard.ImportPackage += delegate(object sender, SmartSchool.API.PlugIn.Import.ImportPackageEventArgs e)
            {
                Dictionary <string, List <RowData> > id_Rows = new Dictionary <string, List <RowData> >();
                foreach (RowData data in e.Items)
                {
                    if (!id_Rows.ContainsKey(data.ID))
                    {
                        id_Rows.Add(data.ID, new List <RowData>());
                    }
                    id_Rows[data.ID].Add(data);
                }

                List <DAL.UserDefData> InsertList = new List <UserDefineData.DAL.UserDefData> ();
                List <DAL.UserDefData> DeleteList = new List <UserDefineData.DAL.UserDefData>();


                foreach (string id in id_Rows.Keys)
                {
                    foreach (RowData data in id_Rows[id])
                    {
                        string FName = string.Empty, Value = string.Empty;
                        if (data.ContainsKey("欄位名稱"))
                        {
                            FName = data["欄位名稱"];
                        }

                        if (data.ContainsKey("值"))
                        {
                            Value = data["值"];
                        }

                        // 將需要刪除放入
                        if (UserDefDataDict.ContainsKey(id))
                        {
                            foreach (DAL.UserDefData udd in UserDefDataDict[id])
                            {
                                if (udd.FieldName == FName)
                                {
                                    udd.Deleted = true;
                                    DeleteList.Add(udd);
                                }
                            }
                        }

                        // 新增資料
                        DAL.UserDefData uddNew = new UserDefineData.DAL.UserDefData();
                        uddNew.FieldName = FName;
                        uddNew.RefID     = id;
                        uddNew.Value     = Value;
                        InsertList.Add(uddNew);
                    }
                }

                try
                {
                    // 先刪除舊的資料在新增新的
                    if (DeleteList.Count > 0)
                    {
                        UDTTransfer.DeleteDataToUDT(DeleteList);
                    }

                    if (InsertList.Count > 0)
                    {
                        UDTTransfer.InsertDataToUDT(InsertList);
                    }

                    JHSchool.Student.Instance.SyncAllBackground();
                }
                catch (Exception ex) { }
            };
        }
Beispiel #6
0
        /// <summary>
        /// 取得單筆學生UDT資料,包括"自定資料管理" (add by 小郭, 2013/12/16)
        /// </summary>
        /// <param name="StudentID"></param>
        /// <returns></returns>
        public static List <DAL.UserDefData> GetDataFromUDTIncludeUserConfig(string StudentID)
        {
            // 回傳資料
            List <DAL.UserDefData> result = new List <DAL.UserDefData>();
            // 暫存資料, Key: 欄位名稱; Value: DAL.UserDefData
            Dictionary <string, DAL.UserDefData> temp = new Dictionary <string, UserDefineData.DAL.UserDefData>();
            // 刪除名單, 用來刪除可能重複的欄位名稱
            List <DAL.UserDefData> DeleteList = new List <UserDefineData.DAL.UserDefData>();

            // 取得UDT的資料
            List <DAL.UserDefData> userDefDataList = GetDataFromUDT(StudentID);

            // 依照uid反向排序
            userDefDataList.Sort(delegate(DAL.UserDefData obj1, DAL.UserDefData obj2)
            {
                string compare1 = (obj1.UID).PadLeft(20, '0');
                string compare2 = (obj2.UID).PadLeft(20, '0');
                return(compare2.CompareTo(compare1));
            });

            // 找出重複的,並保留新的資料(uid比較大的為新的資料)
            foreach (DAL.UserDefData rec in userDefDataList)
            {
                if (!temp.ContainsKey(rec.FieldName))
                {
                    rec.isNull = false;
                    temp.Add(rec.FieldName, rec);
                }
                else
                {
                    // 假如找到重複的欄位名稱, 加入刪除名單, 因為排序過, 所以會刪除比較舊的資料
                    rec.Deleted = true;
                    DeleteList.Add(rec);
                }
            }

            if (DeleteList.Count > 0)
            {
                DeleteDataToUDT(DeleteList);
            }

            // 處理完需要刪除的名單後, 正向排序
            userDefDataList = temp.Values.ToList();
            userDefDataList.Reverse();

            // 取得自訂欄位設定,沒有使用空白
            int index = 0;

            foreach (string FName in Global.GetUserConfigData().Keys)
            {
                DAL.UserDefData ud;
                if (!temp.ContainsKey(FName))
                {
                    ud           = new UserDefineData.DAL.UserDefData();
                    ud.RefID     = StudentID;
                    ud.FieldName = FName;
                    ud.Value     = "";
                }
                else
                {
                    ud = temp[FName];
                    // 先移除既有的資料
                    userDefDataList.Remove(ud);
                }

                // 新增到前面
                userDefDataList.Insert(index++, ud);
            }

            // 回傳List
            result = userDefDataList;

            return(result);
        }
Beispiel #7
0
        /// <summary>
        /// 按下儲存
        /// </summary>
        /// <param name="e"></param>
        protected override void OnSaveButtonClick(EventArgs e)
        {
            if (!FISCA.Permission.UserAcl.Current[Global.自訂資料欄位功能代碼].Editable)
            {
                MessageBox.Show("此帳號無編輯權限...", "ischool");
                this.CancelButtonVisible = false;
                this.SaveButtonVisible   = false;
                return;
            }

            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);
                    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);
            }
        }