Ejemplo n.º 1
0
 public static void SetError(VGridControl vgrid, string FieldName, string ErrMsg, OutputError Output)
 {
     switch (Output)
     {
         case OutputError.ERROR_PROVIDER:
             vgrid.SetRowError(vgrid.GetRowByFieldName(FieldName).Properties, ErrMsg);
             break;
     }
 }
Ejemplo n.º 2
0
        /// <summary>Kiểm tra và đánh dấu lỗi
        /// </summary>
        /// <returns></returns>
        public static bool ValidateRecord(VGridControl vgrid, FieldNameCheck[] CheckList)
        {
            if (CheckList == null) return true;
            bool flag = true;
            for (int i = 0; i < CheckList.Length; i++)
            {
                string FieldName = CheckList[i].FieldName;
                string Data = null;
                BaseRow br = vgrid.GetRowByFieldName(FieldName);
                Data = vgrid.GetCellDisplayText(br, 0);
                for (int j = 0; j < CheckList[i].Types.Length; j++)
                {
                    string ErrMsg = "";
                    if (CheckList[i].Subject != null)
                        ErrMsg = GetErrMsg(CheckList[i].Types[j], CheckList[i].Subject);
                    else
                        ErrMsg = CheckList[i].ErrMsgs[j];
                    switch (CheckList[i].Types[j])
                    {
                        #region 1. Số thực
                        case CheckType.DecGreaterZero:
                            if (HelpIsCheck.isDecGreater0(Data))
                            {
                                ClearError(vgrid, FieldName);
                            }
                            else
                            {
                                SetError(vgrid, FieldName, ErrMsg);
                                flag = false;
                            }
                            break;
                        case CheckType.DecGreater0:
                            if (HelpIsCheck.isDecGreater0(Data))
                            {
                                ClearError(vgrid, FieldName);
                            }
                            else
                            {
                                SetError(vgrid, FieldName, ErrMsg);
                                flag = false;
                            }
                            break;
                        case CheckType.DecGreaterEqual0:
                            if (HelpIsCheck.isDecGreaterEqual0(Data))
                            {
                                ClearError(vgrid, FieldName);
                            }
                            else
                            {
                                SetError(vgrid, FieldName, ErrMsg);
                                flag = false;
                            }
                            break;
                        #endregion
                        #region 1. Số nguyên
                        case CheckType.IntGreaterZero:
                            if (HelpIsCheck.isIntGreater0(Data))
                            {
                                ClearError(vgrid, FieldName);
                            }
                            else
                            {
                                SetError(vgrid, FieldName, ErrMsg);
                                flag = false;
                            }
                            break;
                        case CheckType.IntGreater0:
                            if (HelpIsCheck.isIntGreater0(Data))
                            {
                                ClearError(vgrid, FieldName);
                            }
                            else
                            {
                                SetError(vgrid, FieldName, ErrMsg);
                                flag = false;
                            }
                            break;
                        case CheckType.IntGreaterEqual0:
                            if (HelpIsCheck.isIntGreaterEqual0(Data))
                            {
                                ClearError(vgrid, FieldName);
                            }
                            else
                            {
                                SetError(vgrid, FieldName, ErrMsg);
                                flag = false;
                            }
                            break;
                        #endregion
                        #region 1. Email
                        case CheckType.RequireEmail:
                            if (Data != null && Data != "" && HelpIsCheck.isValidEmail(Data))
                            {
                                ClearError(vgrid, FieldName);
                            }
                            else
                            {
                                SetError(vgrid, FieldName, ErrMsg);
                                flag = false;
                            }
                            break;
                        case CheckType.OptionEmail:
                            if (Data == null || Data == "" || HelpIsCheck.isValidEmail(Data))
                            {
                                ClearError(vgrid, FieldName);
                            }
                            else
                            {
                                SetError(vgrid, FieldName, ErrMsg);
                                flag = false;
                            }
                            break;
                        #endregion
                        #region 1. Chuỗi
                        case CheckType.RequireMaxLength:
                            if (Data != null && Data != "" && HelpIsCheck.IsMaxLength(Data, (int)CheckList[i].Params[j]))
                            {
                                ClearError(vgrid, FieldName);
                            }
                            else
                            {
                                SetError(vgrid, FieldName, ErrMsg);
                                flag = false;
                            }
                            break;
                        case CheckType.OptionMaxLength:
                            if (Data == null || Data == "" || HelpIsCheck.IsMaxLength(Data, (int)CheckList[i].Params[j]))
                            {
                                ClearError(vgrid, FieldName);
                            }
                            else
                            {
                                SetError(vgrid, FieldName, ErrMsg);
                                flag = false;
                            }
                            break;
                        #endregion
                        #region 1. Date
                        case CheckType.RequireDate:
                            if (Data != null && Data != "" && br.Properties.Value is DateTime && !HelpIsCheck.isBlankDate((DateTime)br.Properties.Value))
                            {
                                ClearError(vgrid, FieldName);
                            }
                            else
                            {
                                SetError(vgrid, FieldName, ErrMsg);
                                flag = false;
                            }
                            break;
                        case CheckType.OptionDate:
                            if (Data == null || Data == "" || br.Properties.Value is DateTime)
                            {
                                ClearError(vgrid, FieldName);
                            }
                            else
                            {
                                SetError(vgrid, FieldName, ErrMsg);
                                flag = false;
                            }
                            break;
                        case CheckType.DateALessB:
                            DateTime B;
                            if (CheckList[i].Params[j] is DateTime)
                                B = (DateTime)CheckList[i].Params[j];
                            else
                                B = (DateTime)vgrid.GetRowByFieldName(CheckList[i].Params[j].ToString()).Properties.Value;
                            if (HelpIsCheck.IsALessB((DateTime)br.Properties.Value, B))
                            {
                                ClearError(vgrid, FieldName);
                            }
                            else
                            {
                                SetError(vgrid, FieldName, ErrMsg);
                                flag = false;
                            }
                            break;
                        case CheckType.DateALessEqualB:
                            DateTime C;
                            if (CheckList[i].Params[j] is DateTime)
                                C = (DateTime)CheckList[i].Params[j];
                            else
                                C = (DateTime)vgrid.GetRowByFieldName(CheckList[i].Params[j].ToString()).Properties.Value;
                            if (HelpIsCheck.IsALessEqualB((DateTime)br.Properties.Value, C))
                            {
                                ClearError(vgrid, FieldName);
                            }
                            else
                            {
                                SetError(vgrid, FieldName, ErrMsg);
                                flag = false;
                            }
                            break;
                        #endregion
                        #region 1. Danh mục
                        case CheckType.RequiredID:
                            long ID = HelpNumber.DecimalToInt64(Data);
                            if (ID > 0)
                            {
                                ClearError(vgrid, FieldName);
                            }
                            else
                            {
                                SetError(vgrid, FieldName, ErrMsg);
                                flag = false;
                            }
                            break;
                        #endregion
                        #region 1. Other
                        case CheckType.Required:
                            if (Data != null && Data != "" && Data != "-1")
                            {
                                ClearError(vgrid, FieldName);
                            }
                            else
                            {
                                //PHUOCNT TODO Kiem tra lai
                                if (vgrid.GetCellValue(br, 0) == null)
                                {
                                    SetError(vgrid, FieldName, ErrMsg);
                                    flag = false;
                                }
                                else
                                {
                                    ClearError(vgrid, FieldName);
                                }
                            }
                            break;
                        #endregion
                    }

                    if (vgrid.HasRowErrors) break;
                }
            }
            return flag;
        }