Example #1
0
 public Office2013()
 {
     _tools            = new OfficeTools();
     _installUninstall = new InstUninst();
     _source           = _tools.Paths("ZipFile");
     _proFile          = _tools.Paths("UserProfile");
     _destination      = _tools.Paths("Downloads");
     _setupExe         = _tools.Paths("SetupExe");
     _msgsApps         = new MsgsApps();
 }
    /// <summary>
    /// 导入
    /// </summary>
    private void BatchImport()
    {
        AjaxResult result = new AjaxResult();

        result.IsSuccess = true;
        result.Msg       = "操作成功!";
        try
        {
            #region 校验数据

            string    filepath = Request.Params["PlanFilesPath"].Split(',')[0];
            string    temppath = DownFile(filepath);
            DataTable dt       = OfficeTools.GetDT(temppath);
            if (dt.Rows.Count > 100)
            {
                result.IsSuccess = false;
                result.Msg       = "最多只能导入500条数据!";
                Response.Write(result.ToJsonString());
                Response.ContentType = "application/json";
                Response.End();
            }
            if (dt.Columns.Count != 11)
            {
                result.IsSuccess = false;
                result.Msg       = "导入的文件模板不正确,请更新导入模板!";
                Response.Write(result.ToJsonString());
                Response.ContentType = "application/json";
                Response.End();
            }
            int    length           = 0;
            string baseerrormessage = "第{0}行错误,错误信息为{1}:";
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                var rowobj = dt.Rows[i];
                for (int j = 0; j < rowobj.ItemArray.Length; j++)
                {
                    var colobj = rowobj.ItemArray[j].ToString();

                    switch (j)
                    {
                    case 0:
                        length = string.IsNullOrEmpty(colobj) ? 0 : colobj.Length;
                        if (colobj == null || string.IsNullOrEmpty(colobj))
                        {
                            throw new Exception(string.Format(baseerrormessage, i + 2, "飞行员姓名不能为空!"));
                        }
                        if (length > 10)
                        {
                            throw new Exception(string.Format(baseerrormessage, i + 2, "飞行员姓名不能超过10个字符!"));
                        }
                        break;

                    case 1:
                        length = string.IsNullOrEmpty(colobj) ? 0 : colobj.Length;
                        if (colobj == null || string.IsNullOrEmpty(colobj))
                        {
                            throw new Exception(string.Format(baseerrormessage, i + 2, "身份证号不能为空!"));
                        }
                        if (length > 18)
                        {
                            throw new Exception(string.Format(baseerrormessage, i + 2, "身份证号不能超过18个字符!"));
                        }
                        break;

                    case 2:
                        DateTime bdt = DateTime.MinValue;
                        if (!string.IsNullOrEmpty(colobj) && !DateTime.TryParse(colobj, out bdt))
                        {
                            throw new Exception(string.Format(baseerrormessage, i + 2, "出生日期格式不正确!"));
                        }
                        break;

                    case 3:
                        length = string.IsNullOrEmpty(colobj) ? 0 : colobj.Length;
                        if (colobj == null || string.IsNullOrEmpty(colobj))
                        {
                            throw new Exception(string.Format(baseerrormessage, i + 2, "年龄不能为空!"));
                        }
                        if (length > 3)
                        {
                            throw new Exception(string.Format(baseerrormessage, i + 2, "年龄不能超过3个字符!"));
                        }
                        break;

                    case 4:
                        length = string.IsNullOrEmpty(colobj) ? 0 : colobj.Length;
                        if (colobj == null || string.IsNullOrEmpty(colobj))
                        {
                            throw new Exception(string.Format(baseerrormessage, i + 2, "联系电话不能为空!"));
                        }
                        if (length > 11)
                        {
                            throw new Exception(string.Format(baseerrormessage, i + 2, "联系电话不能超过11个字符!"));
                        }
                        break;

                    case 5:
                        length = string.IsNullOrEmpty(colobj) ? 0 : colobj.Length;
                        if (colobj == null || string.IsNullOrEmpty(colobj))
                        {
                            throw new Exception(string.Format(baseerrormessage, i + 2, "执照编号不能为空!"));
                        }
                        if (length > 30)
                        {
                            throw new Exception(string.Format(baseerrormessage, i + 2, "执照编号不能超过30个字符!"));
                        }
                        break;

                    case 6:
                        length = string.IsNullOrEmpty(colobj) ? 0 : colobj.Length;
                        if (colobj == null || string.IsNullOrEmpty(colobj))
                        {
                            throw new Exception(string.Format(baseerrormessage, i + 2, "签发单位不能为空!"));
                        }
                        if (length > 30)
                        {
                            throw new Exception(string.Format(baseerrormessage, i + 2, "签发单位不能超过30个字符!"));
                        }
                        break;

                    case 7:
                        DateTime edt = DateTime.MinValue;
                        if (!string.IsNullOrEmpty(colobj) && !DateTime.TryParse(colobj, out edt))
                        {
                            throw new Exception(string.Format(baseerrormessage, i + 2, "签发日期格式不正确!"));
                        }
                        break;

                    case 8:
                        length = string.IsNullOrEmpty(colobj) ? 0 : colobj.Length;
                        if (colobj == null || string.IsNullOrEmpty(colobj))
                        {
                            throw new Exception(string.Format(baseerrormessage, i + 2, "执照类别不能为空!"));
                        }
                        if (length > 8)
                        {
                            throw new Exception(string.Format(baseerrormessage, i + 2, "执照类别不能超过8个字符!"));
                        }
                        break;

                    case 9:
                        length = string.IsNullOrEmpty(colobj) ? 0 : colobj.Length;
                        if (colobj == null || string.IsNullOrEmpty(colobj))
                        {
                            throw new Exception(string.Format(baseerrormessage, i + 2, "性别不能为空!"));
                        }
                        if (length > 1)
                        {
                            throw new Exception(string.Format(baseerrormessage, i + 2, "性别不能超过1个字符!"));
                        }
                        break;

                    case 10:
                        length = string.IsNullOrEmpty(colobj) ? 0 : colobj.Length;
                        if (colobj == null || string.IsNullOrEmpty(colobj))
                        {
                            throw new Exception(string.Format(baseerrormessage, i + 2, "公司三字码不能为空!"));
                        }
                        if (length > 3)
                        {
                            throw new Exception(string.Format(baseerrormessage, i + 2, "公司三字码不能超过3个字符!"));
                        }
                        break;
                    }
                }
            }

            #endregion
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                var rowobj = dt.Rows[i];
                var model  = new Pilot()
                {
                    Pilots       = rowobj.ItemArray[0].ToString(),
                    PilotCardNo  = rowobj.ItemArray[1].ToString(),
                    PilotDT      = DateTime.Parse(rowobj.ItemArray[2].ToString()),
                    PilotAge     = int.Parse(rowobj.ItemArray[3].ToString()),
                    PhoneNo      = rowobj.ItemArray[4].ToString(),
                    LicenseNo    = rowobj.ItemArray[5].ToString(),
                    Sign         = rowobj.ItemArray[6].ToString(),
                    LicenseTime  = DateTime.Parse(rowobj.ItemArray[7].ToString()),
                    Licensesort  = rowobj.ItemArray[8].ToString() == "航线运输驾驶执照" ? "0" : (rowobj.ItemArray[8].ToString() == "商用飞机驾照" ? "1" : "2"),
                    Sex          = byte.Parse(rowobj.ItemArray[9].ToString() == "男" ? "0" : "1"),
                    CompanyCode3 = rowobj.ItemArray[10].ToString(),
                    CreateTime   = DateTime.Now,
                };
                bll.Add(model);

                if (result.IsSuccess)
                {
                    result.Msg = "导入成功!";
                }
            }
        }
        catch (Exception ex)
        {
            result.IsSuccess = false;
            result.Msg       = ex.Message;
        }
        Response.Write(result.ToJsonString());
        Response.ContentType = "application/json";
        Response.End();
    }
Example #3
0
    /// <summary>
    /// 导入
    /// </summary>
    private void BatchImport()
    {
        AjaxResult result = new AjaxResult();

        result.IsSuccess = true;
        result.Msg       = "操作成功!";
        try
        {
            #region 校验数据

            string    filepath = Request.Params["PlanFilesPath"].Split(',')[0];
            string    temppath = DownFile(filepath);
            DataTable dt       = OfficeTools.GetDT(temppath);
            if (dt.Rows.Count > 100)
            {
                result.IsSuccess = false;
                result.Msg       = "最多只能导入500条数据!";
                Response.Write(result.ToJsonString());
                Response.ContentType = "application/json";
                Response.End();
            }
            if (dt.Columns.Count != 16)
            {
                result.IsSuccess = false;
                result.Msg       = "导入的文件模板不正确,请更新导入模板!";
                Response.Write(result.ToJsonString());
                Response.ContentType = "application/json";
                Response.End();
            }
            int    length           = 0;
            string baseerrormessage = "第{0}行错误,错误信息为{1}:";
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                var rowobj = dt.Rows[i];
                for (int j = 0; j < rowobj.ItemArray.Length; j++)
                {
                    var colobj = rowobj.ItemArray[j].ToString();

                    switch (j)
                    {
                    case 0:
                        length = string.IsNullOrEmpty(colobj) ? 0 : colobj.Length;
                        if (colobj == null || string.IsNullOrEmpty(colobj))
                        {
                            throw new Exception(string.Format(baseerrormessage, i + 2, "国籍和登记标志不能为空!"));
                        }
                        if (length > 10)
                        {
                            throw new Exception(string.Format(baseerrormessage, i + 2, "国籍和登记标志不能超过10个字符!"));
                        }
                        break;

                    case 1:
                        length = string.IsNullOrEmpty(colobj) ? 0 : colobj.Length;

                        if (length > 4)
                        {
                            throw new Exception(string.Format(baseerrormessage, i + 2, "最大加油量不能超过4个字符!"));
                        }
                        break;

                    case 2:
                        length = string.IsNullOrEmpty(colobj) ? 0 : colobj.Length;
                        if (colobj == null || string.IsNullOrEmpty(colobj))
                        {
                            throw new Exception(string.Format(baseerrormessage, i + 2, "机型不能为空!"));
                        }
                        if (length > 20)
                        {
                            throw new Exception(string.Format(baseerrormessage, i + 2, "机型不能超过20个字符!"));
                        }
                        break;

                    case 3:
                        length = string.IsNullOrEmpty(colobj) ? 0 : colobj.Length;

                        if (length > 6)
                        {
                            throw new Exception(string.Format(baseerrormessage, i + 2, "最大航程不能超过6个字符!"));
                        }
                        break;

                    case 4:
                        length = string.IsNullOrEmpty(colobj) ? 0 : colobj.Length;
                        if (colobj == null || string.IsNullOrEmpty(colobj))
                        {
                            throw new Exception(string.Format(baseerrormessage, i + 2, "航空器出厂序号不能为空!"));
                        }
                        if (length > 10)
                        {
                            throw new Exception(string.Format(baseerrormessage, i + 2, "航空器出厂序号不能超过10个字符!"));
                        }
                        break;

                    case 5:
                        DateTime bdt = DateTime.MinValue;
                        if (!string.IsNullOrEmpty(colobj) && !DateTime.TryParse(colobj, out bdt))
                        {
                            throw new Exception(string.Format(baseerrormessage, i + 2, "年检日期格式不正确!"));
                        }
                        break;

                    case 6:
                        length = string.IsNullOrEmpty(colobj) ? 0 : colobj.Length;
                        if (colobj == null || string.IsNullOrEmpty(colobj))
                        {
                            throw new Exception(string.Format(baseerrormessage, i + 2, "飞行器类别不能为空!"));
                        }
                        if (length > 30)
                        {
                            throw new Exception(string.Format(baseerrormessage, i + 2, "飞行器类别不能超过30个字符!"));
                        }
                        break;

                    case 7:
                        length = string.IsNullOrEmpty(colobj) ? 0 : colobj.Length;

                        if (length > 4)
                        {
                            throw new Exception(string.Format(baseerrormessage, i + 2, "巡航高度不能超过4个字符!"));
                        }
                        break;

                    case 8:
                        length = string.IsNullOrEmpty(colobj) ? 0 : colobj.Length;
                        if (colobj == null || string.IsNullOrEmpty(colobj))
                        {
                            throw new Exception(string.Format(baseerrormessage, i + 2, "制造商不能为空!"));
                        }
                        if (length > 30)
                        {
                            throw new Exception(string.Format(baseerrormessage, i + 2, "制造商不能超过30个字符!"));
                        }
                        break;

                    case 9:
                        length = string.IsNullOrEmpty(colobj) ? 0 : colobj.Length;

                        if (length > 5)
                        {
                            throw new Exception(string.Format(baseerrormessage, i + 2, "巡航速度不能超过5个字符!"));
                        }
                        break;

                    case 10:
                        length = string.IsNullOrEmpty(colobj) ? 0 : colobj.Length;

                        if (length > 5)
                        {
                            throw new Exception(string.Format(baseerrormessage, i + 2, "最大速度不能超过5个字符!"));
                        }
                        break;

                    case 11:
                        length = string.IsNullOrEmpty(colobj) ? 0 : colobj.Length;

                        if (length > 5)
                        {
                            throw new Exception(string.Format(baseerrormessage, i + 2, "最大起飞重量不能超过5个字符!"));
                        }
                        break;

                    case 12:
                        length = string.IsNullOrEmpty(colobj) ? 0 : colobj.Length;
                        if (colobj == null || string.IsNullOrEmpty(colobj))
                        {
                            throw new Exception(string.Format(baseerrormessage, i + 2, "最大续航时间不能为空!"));
                        }
                        if (length > 4)
                        {
                            throw new Exception(string.Format(baseerrormessage, i + 2, "最大续航时间不能超过4个字符!"));
                        }
                        //if (colobj != /^\d{ })
                        break;

                    case 13:
                        length = string.IsNullOrEmpty(colobj) ? 0 : colobj.Length;
                        if (colobj == null || string.IsNullOrEmpty(colobj))
                        {
                            throw new Exception(string.Format(baseerrormessage, i + 2, "乘客人数不能为空!"));
                        }
                        if (length > 2)
                        {
                            throw new Exception(string.Format(baseerrormessage, i + 2, "乘客人数不能超过2个字符!"));
                        }
                        break;

                    case 14:
                        length = string.IsNullOrEmpty(colobj) ? 0 : colobj.Length;
                        if (colobj == null || string.IsNullOrEmpty(colobj))
                        {
                            throw new Exception(string.Format(baseerrormessage, i + 2, "适航证颁发单位不能为空!"));
                        }
                        if (length > 30)
                        {
                            throw new Exception(string.Format(baseerrormessage, i + 2, "适航证颁发单位不能超过30个字符!"));
                        }
                        break;

                    case 15:
                        length = string.IsNullOrEmpty(colobj) ? 0 : colobj.Length;
                        if (colobj == null || string.IsNullOrEmpty(colobj))
                        {
                            throw new Exception(string.Format(baseerrormessage, i + 2, "公司三字码不能为空!"));
                        }
                        if (length > 3)
                        {
                            throw new Exception(string.Format(baseerrormessage, i + 2, "公司三字码不能超过3个字符!"));
                        }
                        break;
                    }
                }
            }

            #endregion
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                var rowobj = dt.Rows[i];
                var model  = new Aircraft()
                {
                    AircraftSign  = rowobj.ItemArray[0].ToString(),
                    FuelCapacity  = int.Parse(rowobj.ItemArray[1].ToString()),
                    AcfType       = rowobj.ItemArray[2].ToString(),
                    Range         = int.Parse(rowobj.ItemArray[3].ToString()),
                    AcfNo         = rowobj.ItemArray[4].ToString(),
                    ASdate        = DateTime.Parse(rowobj.ItemArray[5].ToString()),
                    AcfClass      = rowobj.ItemArray[6].ToString(),
                    CruiseAltd    = int.Parse(rowobj.ItemArray[7].ToString()),
                    Manufacture   = rowobj.ItemArray[8].ToString(),
                    CruiseSpeed   = int.Parse(rowobj.ItemArray[9].ToString()),
                    MaxSpeed      = int.Parse(rowobj.ItemArray[10].ToString()),
                    FueledWeight  = int.Parse(rowobj.ItemArray[11].ToString()),
                    MaxEndurance  = float.Parse(rowobj.ItemArray[12].ToString()),
                    Passenger     = int.Parse(rowobj.ItemArray[13].ToString()),
                    Airworthiness = rowobj.ItemArray[14].ToString(),
                    CompanyCode3  = rowobj.ItemArray[15].ToString(),
                    //CompanyCode3 = User.CompanyCode3 ?? "",
                    CreateTime = DateTime.Now,
                };
                bll.Add(model);

                if (result.IsSuccess)
                {
                    result.Msg = "导入成功!";
                }
            }
        }
        catch (Exception ex)
        {
            result.IsSuccess = false;
            result.Msg       = ex.Message;
        }
        Response.Write(result.ToJsonString());
        Response.ContentType = "application/json";
        Response.End();
    }