Example #1
0
        protected void btnUpload_Click(object sender, EventArgs e)
        {
            string result = "";

            if (this.txtFraUpload.PostedFile.FileName == "")
            {
                JscriptMsg("请选择上传文件", "", "Error");
                return;
            }
            DataSet ds   = new DataSet();
            string  path = "/upload/excel/";

            #region 解决360获取绝对路径导致出错的问题
            string   AbsolutePath = this.txtFraUpload.PostedFile.FileName;
            string[] pathList     = new string[] { };

            pathList     = AbsolutePath.Split('\\');
            AbsolutePath = pathList[pathList.Length - 1];
            #endregion

            string fileName = DateTime.Now.ToFileTime() + "_" + AbsolutePath;
            string FexName  = fileName.Substring(fileName.LastIndexOf(".") + 1);
            if (FexName != "xls" && FexName != "xlsx")
            {
                JscriptMsg("请上传Excel文件", "", "Error");
                return;
            }

            string filePath = Server.MapPath(path + fileName);

            this.txtFraUpload.SaveAs(filePath);
            int success = 0, error = 0;
            try
            {
                var excel = new Common.ExcelToData();
                ds = excel.GetExcelData(filePath);

                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    if (ds.Tables[0].Rows[i]["考生号"].ToString().Trim() == "")
                    {
                        result += "×第" + (i + 1).ToString() + "行添加失败,考生号不能为空;<br/>";
                        error++;
                        continue;
                    }

                    var __model = new BLL.CCOM.User_property().GetModel(" UP_CCOM_number='" + ds.Tables[0].Rows[i]["考生号"].ToString().Trim() + "'");
                    if (__model == null)
                    {
                        result += "×第" + (i + 1).ToString() + "行添加失败,考生号错误;<br/>";
                        error++;
                        continue;
                    }
                    long user_id = __model.User_id;

                    var model  = new Model.CCOM.Examination_subject_score();
                    var _model = new Model.CCOM.Examination_subject_score();
                    model = new BLL.CCOM.Examination_subject_score().GetModel(" Esn_id = " + id1 + " AND User_id=" + user_id + " AND Judge_id=" + id2);

                    _model.Esn_id           = Convert.ToInt32(id1);
                    _model.Judge_id         = Convert.ToInt32(id2);
                    _model.User_id          = user_id;
                    _model.Ess_score        = (ds.Tables[0].Rows[i]["科目成绩"].ToString().Trim() == "" ? 0 : Convert.ToDecimal(ds.Tables[0].Rows[i]["科目成绩"].ToString().Trim()));
                    _model.Ess_score_status = true;
                    _model.Ess_order_status = true;
                    bool isOK = false;
                    if (model != null)
                    {
                        _model.Ess_id = model.Ess_id;
                        isOK          = DoUpdate(_model);
                    }
                    else
                    {
                        isOK = DoAdd(_model);
                    }

                    if (isOK)
                    {
                        success++;
                    }
                    else
                    {
                        result += "×第" + (i + 1).ToString() + "行‘" + ds.Tables[0].Rows[i]["考生号"].ToString().Trim() + "’信息异常,导入失败。<br/>";
                        error++;
                    }
                }
            }
            catch (Exception ex)
            {
                ILog LOGGER = LogManager.GetLogger("quanquan");
                LOGGER.Debug("导入分数线异常" + ex.Message, ex);
                result = "导入分数线异常,请联系客服";
            }

            try
            {
                new Calculation().calculateSubjectXu(id1.ToString(), id2.ToString());
            }
            catch
            {
            }
            string divinfo = "<div class=\"alert alert-block alert-info fade in\">";
            divinfo += "<button data-dismiss=\"alert\" class=\"close\" type=\"button\">×</button>";
            divinfo += "<h4 class=\"alert-heading\">导入结果</h4>";
            divinfo += "<p>";
            if (success != ds.Tables[0].DefaultView.Count)
            {
                divinfo += "部分导入成功,您可以按照提示修改Excel并重新提交<br>";
            }
            else
            {
                divinfo += "全部导入成功,请您进入下一步确认导入信息<br>";
            }
            divinfo += "*共有" + ds.Tables[0].DefaultView.Count + "条数据,成功" + success + "条,失败" + error + "条;<br/>";
            if (result != "")
            {
                divinfo += "详细信息如下:<br><font color='red'>" + result;
            }
            divinfo           += "</font></p>";
            divinfo           += "</div>";
            this.lblError.Text = divinfo;

            //显示下一步
            if (success > 0)
            {
                this.btnSubmit.Visible = true;
            }
            //删除上传的文件
            File.Delete(filePath);
        }
        protected void btnUpload_Click(object sender, EventArgs e)
        {
            string result = "";

            if (this.txtFraUpload.PostedFile.FileName == "")
            {
                JscriptMsg("请选择上传文件", "", "Error");
                return;
            }
            DataSet ds   = new DataSet();
            string  path = "/upload/excel/";

            #region 解决360获取绝对路径导致出错的问题
            string   AbsolutePath = this.txtFraUpload.PostedFile.FileName;
            string[] pathList     = new string[] { };

            pathList     = AbsolutePath.Split('\\');
            AbsolutePath = pathList[pathList.Length - 1];
            #endregion

            string fileName = DateTime.Now.ToFileTime() + "_" + AbsolutePath;
            string FexName  = fileName.Substring(fileName.LastIndexOf(".") + 1);
            if (FexName != "xls" && FexName != "xlsx")
            {
                JscriptMsg("请上传Excel文件", "", "Error");
                return;
            }

            string filePath = Server.MapPath(path + fileName);

            this.txtFraUpload.SaveAs(filePath);
            int success = 0, error = 0;
            try
            {
                BLL.CCOM.Province PBll = new BLL.CCOM.Province();

                var excel = new Common.ExcelToData();
                ds = excel.GetExcelData(filePath);

                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    string _ProName = ds.Tables[0].Rows[i]["省份"].ToString().Trim();

                    var p_model = PBll.GetModel("Province_name='" + _ProName + "'");
                    if (p_model == null)
                    {
                        result += "×第" + (i + 1).ToString() + "行添加失败,该省份‘" + ds.Tables[0].Rows[i]["省份"].ToString().Trim() + "’不存在,请按照模板格式下拉选择;<br/>";
                        error++;
                        continue;
                    }

                    var model  = new Model.CCOM.Fractional_line();
                    var _model = new Model.CCOM.Fractional_line();

                    int Pro_id = p_model.Province_id;
                    model = new BLL.CCOM.Fractional_line().GetModel(" Period_id = " + period_id + " and Fl_Province=" + Pro_id);

                    _model.WenKeYiBen     = ((ds.Tables[0].Rows[i]["文科一本线"].ToString().Trim() == "") ? 0 : (Convert.ToDecimal(ds.Tables[0].Rows[i]["文科一本线"].ToString().Trim())));
                    _model.LiKeYiBen      = (ds.Tables[0].Rows[i]["理科一本线"].ToString().Trim() == "" ? 0 : Convert.ToDecimal(ds.Tables[0].Rows[i]["理科一本线"].ToString().Trim()));
                    _model.WenKeErBen     = (ds.Tables[0].Rows[i]["文科二本线"].ToString().Trim() == "" ? 0 : Convert.ToDecimal(ds.Tables[0].Rows[i]["文科二本线"].ToString().Trim()));
                    _model.LiKeErBen      = (ds.Tables[0].Rows[i]["理科二本线"].ToString().Trim() == "" ? 0 : Convert.ToDecimal(ds.Tables[0].Rows[i]["理科二本线"].ToString().Trim()));
                    _model.WenKeSanBen    = (ds.Tables[0].Rows[i]["文科三本线"].ToString().Trim() == "" ? 0 : Convert.ToDecimal(ds.Tables[0].Rows[i]["文科三本线"].ToString().Trim()));
                    _model.LiKeSanBen     = (ds.Tables[0].Rows[i]["理科三本线"].ToString().Trim() == "" ? 0 : Convert.ToDecimal(ds.Tables[0].Rows[i]["理科三本线"].ToString().Trim()));
                    _model.WenKeYiShuXian = (ds.Tables[0].Rows[i]["艺术类最低控制线(文科)"].ToString().Trim() == "" ? 0 : Convert.ToDecimal(ds.Tables[0].Rows[i]["艺术类最低控制线(文科)"].ToString().Trim()));
                    _model.LiKeYiShuXian  = (ds.Tables[0].Rows[i]["艺术类最低控制线(理科)"].ToString().Trim() == "" ? 0 : Convert.ToDecimal(ds.Tables[0].Rows[i]["艺术类最低控制线(理科)"].ToString().Trim()));
                    if (ds.Tables[0].Rows[i]["文科满分"].ToString().Trim() == "")
                    {
                        result += "×第" + (i + 1).ToString() + "行添加失败,文科满分不能为空;<br/>";
                        error++;
                        continue;
                    }
                    _model.WenKeZongFen = Convert.ToDecimal(ds.Tables[0].Rows[i]["文科满分"].ToString().Trim());
                    if (ds.Tables[0].Rows[i]["理科满分"].ToString().Trim() == "")
                    {
                        result += "×第" + (i + 1).ToString() + "行添加失败,理科满分不能为空;<br/>";
                        error++;
                        continue;
                    }
                    _model.LiKeZongFen = Convert.ToDecimal(ds.Tables[0].Rows[i]["理科满分"].ToString().Trim());

                    bool isOK = false;
                    if (model != null)
                    {
                        _model.Fl_id       = model.Fl_id;
                        _model.Period_id   = model.Period_id;
                        _model.Fl_Province = model.Fl_Province;
                        _model.Fl_addtime  = model.Fl_addtime;
                        isOK = DoUpdate(_model);
                    }
                    else
                    {
                        _model.Fl_Province = Pro_id;
                        _model.Period_id   = period_id;
                        _model.Fl_addtime  = DateTime.Now;
                        isOK = DoAdd(_model);
                    }

                    if (isOK)
                    {
                        success++;
                    }
                    else
                    {
                        result += "×第" + (i + 1).ToString() + "行‘" + ds.Tables[0].Rows[i]["省份"].ToString().Trim() + "’信息异常,导入失败。<br/>";
                        error++;
                    }
                }
                new Calculation().calculateFenShuXian();
            }
            catch (Exception ex)
            {
                ILog LOGGER = LogManager.GetLogger("quanquan");
                LOGGER.Debug("导入分数线异常" + ex.Message, ex);
                result = "导入分数线异常,请联系客服";
            }

            string divinfo = "<div class=\"alert alert-block alert-info fade in\">";
            divinfo += "<button data-dismiss=\"alert\" class=\"close\" type=\"button\">×</button>";
            divinfo += "<h4 class=\"alert-heading\">导入结果</h4>";
            divinfo += "<p>";
            if (success != ds.Tables[0].DefaultView.Count)
            {
                divinfo += "部分导入成功,您可以按照提示修改Excel并重新提交<br>";
            }
            else
            {
                divinfo += "全部导入成功,请您进入下一步确认导入信息<br>";
            }
            divinfo += "*共有" + ds.Tables[0].DefaultView.Count + "条数据,成功" + success + "条,失败" + error + "条;<br/>";
            if (result != "")
            {
                divinfo += "详细信息如下:<br><font color='red'>" + result;
            }
            divinfo           += "</font></p>";
            divinfo           += "</div>";
            this.lblError.Text = divinfo;

            //显示下一步
            if (success > 0)
            {
                this.btnSubmit.Visible = true;
            }
            //删除上传的文件
            File.Delete(filePath);
        }
Example #3
0
        protected void btnUpload_Click(object sender, EventArgs e)
        {
            string result = "";

            if (this.txtUserUpload.PostedFile.FileName == "")
            {
                JscriptMsg("请选择上传文件", "", "Error");
                return;
            }
            DataSet ds   = new DataSet();
            string  path = "../../../upload/excel/";

            #region 解决360获取绝对路径导致出错的问题
            string   AbsolutePath = this.txtUserUpload.PostedFile.FileName;
            string[] pathList     = new string[] { };

            pathList     = AbsolutePath.Split('\\');
            AbsolutePath = pathList[pathList.Length - 1];
            #endregion

            string fileName = DateTime.Now.ToFileTime() + "_" + AbsolutePath;
            string FexName  = fileName.Substring(fileName.LastIndexOf(".") + 1);
            if (FexName != "xls" && FexName != "xlsx")
            {
                JscriptMsg("请上传Excel文件", "", "Error");
                return;
            }

            string filePath = Server.MapPath(path + fileName);

            this.txtUserUpload.SaveAs(filePath);
            int success = 0, error = 0;
            try
            {
                var excel = new Common.ExcelToData();
                ds     = excel.GetExcelData(filePath);
                result = ImportDataItem(ds, ref success, ref error);
            }
            catch (Exception ex)
            {
                LOGGER.Debug(ex.Message, ex);
                result = "导入发生异常情况,请联系客服";
            }
            string divinfo = "<div class=\"alert alert-block alert-info fade in\">";
            divinfo += "<button data-dismiss=\"alert\" class=\"close\" type=\"button\">×</button>";
            divinfo += "<h4 class=\"alert-heading\">导入结果</h4>";
            divinfo += "<p>";
            if (success != ds.Tables[0].DefaultView.Count)
            {
                divinfo += "部分导入成功!<br>";
            }
            else
            {
                divinfo += "全部导入成功!<br>";
            }
            divinfo += "*共有" + ds.Tables[0].DefaultView.Count + "条数据,成功" + success + "条,失败" + error + "条;<br/>";
            if (result != "")
            {
                divinfo += "详细信息如下:<br><font color='red'>" + result;
            }
            divinfo           += "</font></p>";
            divinfo           += "</div>";
            this.lblError.Text = divinfo;
            File.Delete(filePath);
        }