Пример #1
0
        /// <summary>
        /// 验证单位信息
        /// </summary>
        /// <param name="dt"></param>
        /// <returns></returns>
        public static bool ValidateORG(DataTable dt)
        {
            bool          isSuccess = true;
            StringBuilder errormsg  = new StringBuilder();

            if (dt != null)
            {
                string error = string.Empty;
                int    index = 1;

                string orgname = dt.Columns[1].ColumnName;

                if (dt.Columns[1] != null)
                {
                    if (IsNull(dt.Columns[1].ColumnName))
                    {
                        errormsg.AppendFormat("{0}:单位名称不能为空 \r", index);
                        isSuccess = false;
                        index++;
                    }
                    else
                    {
                        if (dt.Columns[1].ColumnName.Length > 100)
                        {
                            errormsg.AppendFormat("{0}:单位名称不能超过100个字符串 \r", index);
                            isSuccess = false;
                            index++;
                        }
                    }
                }
                else
                {
                    errormsg.AppendFormat("{0}:单位名称不能为空 \r", index);
                    isSuccess = false;
                    index++;
                }

                if (IsNull(dt.Rows[0][1].ToString()))
                {
                    errormsg.AppendFormat("{0}:单位简称不能为空 \r", index);
                    isSuccess = false;
                    index++;
                }
                if (dt.Rows[0][1].ToString().Length > 20)
                {
                    errormsg.AppendFormat("{0}:单位简称不能超过20个字符串 \r", index);
                    isSuccess = false;
                    index++;
                }

                if (IsNull(dt.Rows[1][1].ToString()))
                {
                    errormsg.AppendFormat("{0}:保障类别不能为空 \r", index);
                    isSuccess = false;
                    index++;
                }
                if (dt.Rows[1][1].ToString().Length > 20)
                {
                    errormsg.AppendFormat("{0}:保障类别不能超过20个字符串 \r", index);
                    isSuccess = false;
                    index++;
                }

                if (dt.Rows[2][1].ToString().Length > 100)
                {
                    errormsg.AppendFormat("{0}:单位地址不能超过100个字符 \r", index);
                    isSuccess = false;
                    index++;
                }
                if (IsNull(dt.Rows[3][1].ToString()))
                {
                    errormsg.AppendFormat("{0}:联系人不能为空 \r", index);
                    isSuccess = false;
                    index++;
                }
                if (dt.Rows[3][1].ToString().Length > 20)
                {
                    errormsg.AppendFormat("{0}:联系人不能超过20个字符串 \r", index);
                    isSuccess = false;
                    index++;
                }
                if (IsNull(dt.Rows[4][1].ToString()))
                {
                    errormsg.AppendFormat("{0}:联系方式不能为空 \r", index);
                    isSuccess = false;
                    index++;
                }
                if (dt.Rows[4][1].ToString().Length > 20)
                {
                    errormsg.AppendFormat("{0}:联系方式不能超过20个字符串 \r", index);
                    isSuccess = false;
                    index++;
                }
            }
            else
            {
                errormsg.AppendFormat("导入单位信息为空,请先填写单位信息!");
            }
            if (!isSuccess)
            {
                string        title = string.Format("单位{0}错误信息如下:\r", dt.Rows[0][1].ToString());
                StringBuilder msg   = new StringBuilder();
                msg.Append(title);
                msg.Append(errormsg.ToString());

                ErrorDialog dialog = new ErrorDialog(msg.ToString());
                dialog.ShowDialog();
            }
            return(isSuccess);
        }