Ejemplo n.º 1
0
        public MigrateManager(ImportPlan plan)
        {
            Plan           = plan;
            SourceDatabase = new PanelDatabase();
            LoadVariations();

            Api = new ApiClient(plan.Destination.ApiKey,
                                plan.Destination.ApiHost,
                                plan.Destination.ApiPort,
                                plan.Destination.UseHttps,
                                generatePassword: plan.MiscGeneratePassword);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 解析excel表
        /// </summary>
        /// <param name="ds"></param>
        /// <param name="errorStr"></param>
        /// <param name="excalPlan"></param>
        /// <returns></returns>
        private bool GetExcelPlan(DataSet ds, int planType, ref string errorStr, ref List <ImportPlan> excalPlan)
        {
            bool formworkflag = true;

            #region 验证excel模板

            if (ds.Tables[0].Columns.Count >= 15)
            {
                if (!ds.Tables[0].Columns[0].ToString().Contains("年度"))
                {
                    formworkflag = false;
                }
                if (!ds.Tables[0].Columns[1].ToString().Contains("培训班名称"))
                {
                    formworkflag = false;
                }
                if (!ds.Tables[0].Columns[2].ToString().Contains("培训内容"))
                {
                    formworkflag = false;
                }
                if (!ds.Tables[0].Columns[3].ToString().Contains("培训目标"))
                {
                    formworkflag = false;
                }
                if (!ds.Tables[0].Columns[4].ToString().Contains("培训对象"))
                {
                    formworkflag = false;
                }
                if (!ds.Tables[0].Columns[5].ToString().Contains("人数"))
                {
                    formworkflag = false;
                }
                if (!ds.Tables[0].Columns[6].ToString().Contains("学时"))
                {
                    formworkflag = false;
                }
                if (!ds.Tables[0].Columns[7].ToString().Contains("开始时间"))
                {
                    formworkflag = false;
                }
                if (!ds.Tables[0].Columns[8].ToString().Contains("结束时间"))
                {
                    formworkflag = false;
                }
                if (!ds.Tables[0].Columns[9].ToString().Contains("培训形式"))
                {
                    formworkflag = false;
                }
                if (!ds.Tables[0].Columns[10].ToString().Contains("培训类别"))
                {
                    formworkflag = false;
                }
                if (!ds.Tables[0].Columns[11].ToString().Contains("考核方式"))
                {
                    formworkflag = false;
                }
                if (!ds.Tables[0].Columns[12].ToString().Contains("费用"))
                {
                    formworkflag = false;
                }
                if (!ds.Tables[0].Columns[13].ToString().Contains("项目标识"))
                {
                    formworkflag = false;
                }
                if (!ds.Tables[0].Columns[14].ToString().Contains("备注"))
                {
                    formworkflag = false;
                }
            }
            else
            {
                formworkflag = false;
                errorStr     = "模板格式错误,请修改后重试!";
            }

            #endregion

            if (formworkflag)
            {
                //Excel正确
                int i = 2;

                var requiredEmpty  = "";//必填项为空的
                var yearError      = "";
                var numberError    = "";
                var scoreError     = "";
                var startTimeError = "";
                var endTimeError   = "";
                var costError      = "";
                var fromError      = "";
                var typeError      = "";
                var checkError     = "";

                var errorflag = false;
                foreach (DataRow dr in ds.Tables[0].Rows)
                {
                    #region 验证必填项
                    if (string.IsNullOrEmpty(dr[0].ToString()) &&
                        string.IsNullOrEmpty(dr[1].ToString()) &&
                        string.IsNullOrEmpty(dr[2].ToString()) &&
                        string.IsNullOrEmpty(dr[3].ToString()) &&
                        string.IsNullOrEmpty(dr[4].ToString()) &&
                        string.IsNullOrEmpty(dr[5].ToString()) &&
                        string.IsNullOrEmpty(dr[6].ToString()) &&
                        string.IsNullOrEmpty(dr[7].ToString()) &&
                        string.IsNullOrEmpty(dr[8].ToString()) &&
                        string.IsNullOrEmpty(dr[9].ToString()) &&
                        string.IsNullOrEmpty(dr[10].ToString()) &&
                        string.IsNullOrEmpty(dr[11].ToString()) &&
                        string.IsNullOrEmpty(dr[12].ToString()) &&
                        string.IsNullOrEmpty(dr[13].ToString()))
                    {
                        requiredEmpty += i + ",";
                        i++;
                        continue;
                    }
                    #endregion

                    #region 验证正确性
                    if (!VerifyNumber(dr[0].ToString()))
                    {
                        errorflag  = true;
                        yearError += i + ",";
                        i++;
                        continue;
                    }
                    if (!VerifyNumber(dr[5].ToString()))
                    {
                        errorflag    = true;
                        numberError += i + ",";
                        i++;
                        continue;
                    }
                    if (!VerifyNumber(dr[6].ToString()))
                    {
                        errorflag   = true;
                        scoreError += i + ",";
                        i++;
                        continue;
                    }
                    if (!VerifyDate(dr[7].ToString()))
                    {
                        errorflag       = true;
                        startTimeError += i + ",";
                        i++;
                        continue;
                    }
                    if (!VerifyDate(dr[8].ToString()))
                    {
                        errorflag     = true;
                        endTimeError += i + ",";
                        i++;
                        continue;
                    }
                    if (!VerifyDecimal(dr[12].ToString()))
                    {
                        errorflag  = true;
                        costError += i + ",";
                        i++;
                        continue;
                    }
                    if (!Enum.IsDefined(typeof(Enums.TrainForm), dr[9].ToString()))
                    {
                        errorflag  = true;
                        fromError += i + ",";
                        i++;
                        continue;
                    }
                    if (!Enum.IsDefined(typeof(Enums.TrainType), dr[10].ToString()))
                    {
                        errorflag  = true;
                        typeError += i + ",";
                        i++;
                        continue;
                    }
                    if (!Enum.IsDefined(typeof(Enums.CheckType), dr[11].ToString()))
                    {
                        errorflag   = true;
                        checkError += i + ",";
                        i++;
                        continue;
                    }

                    #endregion

                    #region 拼装数据

                    var plan = new ImportPlan();
                    plan.Year         = Convert.ToInt32(dr[0].ToString());
                    plan.ClassName    = dr[1].ToString();
                    plan.TrainContent = dr[2].ToString();
                    plan.TrainTarget  = dr[3].ToString();
                    plan.TrainObject  = dr[4].ToString();
                    plan.Number       = Convert.ToInt32(dr[5].ToString());
                    plan.Score        = Convert.ToInt32(dr[6].ToString());
                    plan.StartTime    = Convert.ToDateTime(dr[7].ToString());
                    plan.EndTime      = Convert.ToDateTime(dr[8].ToString());
                    plan.TrainForm    = (int)Enum.Parse(typeof(Enums.TrainForm), dr[9].ToString());
                    plan.TrainType    = (int)Enum.Parse(typeof(Enums.TrainType), dr[10].ToString());
                    plan.CheckType    = (int)Enum.Parse(typeof(Enums.CheckType), dr[11].ToString());
                    plan.TrainCost    = Convert.ToDecimal(dr[12].ToString());
                    var TrainIdentify = dr[13].ToString();
                    switch (TrainIdentify)
                    {
                    case "00 非精品非准入":
                        plan.TrainIdentify = 0;
                        break;

                    case "01 精品非准入":
                        plan.TrainIdentify = 1;
                        break;

                    case "10 准入非精品":
                        plan.TrainIdentify = 2;
                        break;

                    case "11 精品准入":
                        plan.TrainIdentify = 3;
                        break;
                    }
                    plan.Remarks = dr[14].ToString();
                    excalPlan.Add(plan);
                    #endregion
                }

                #region 错误记录

                if (requiredEmpty != "")
                {
                    errorStr = errorStr + string.Format("<br /> " + RetechWing.LanguageResources.SystemManage.Org.Itemisempty, requiredEmpty.TrimEnd(','));
                }
                if (yearError != "")
                {
                    errorStr = errorStr + string.Format("<br /> " + "第{0}行,年度必须为整数,且为当年或明年", yearError.TrimEnd(','));
                }
                if (numberError != "")
                {
                    errorStr = errorStr + string.Format("<br /> " + "第{0}行,人数必须为整数", numberError.TrimEnd(','));
                }
                if (scoreError != "")
                {
                    errorStr = errorStr + string.Format("<br /> " + "第{0}行,学时必须为整数", scoreError.TrimEnd(','));
                }
                if (startTimeError != "")
                {
                    errorStr = errorStr + string.Format("<br /> " + "第{0}行,开始时间填写错误", startTimeError.TrimEnd(','));
                }
                if (endTimeError != "")
                {
                    errorStr = errorStr + string.Format("<br /> " + "第{0}行,结束时间填写错误", endTimeError.TrimEnd(','));
                }
                if (costError != "")
                {
                    errorStr = errorStr + string.Format("<br /> " + "第{0}行,费用整数或者小数点后面2位小数", costError.TrimEnd(','));
                }
                if (fromError != "")
                {
                    errorStr = errorStr + string.Format("<br /> " + "第{0}行,培训形式错误,请选择已有的", fromError.TrimEnd(','));
                }
                if (typeError != "")
                {
                    errorStr = errorStr + string.Format("<br /> " + "第{0}行,培训类别错误,请选择已有的", typeError.TrimEnd(','));
                }
                if (checkError != "")
                {
                    errorStr = errorStr + string.Format("<br /> " + "第{0}行,考核方式错误,请选择已有的", checkError.TrimEnd(','));
                }

                #endregion


                return(errorflag);
            }
            return(false);
        }
Ejemplo n.º 3
0
 public MigrateManager()
 {
     Plan           = new ImportPlan();
     SourceDatabase = new PanelDatabase();
     LoadVariations();
 }