Beispiel #1
0
        private bool DoAdd()
        {
            bool result = false;

            Model.student model = new Model.student();
            BLL.student   bll   = new BLL.student();

            model.no       = txtNo.Text.Trim();
            model.name     = txtName.Text.Trim();
            model.school   = txtSchool.Text.Trim();
            model.score    = txtScore.Text.Trim();
            model.re_score = txtReScore.Text.Trim();
            model.attach   = txtAttach.Text.Trim();
            model.add_time = Utils.StrToDateTime(txtAddTime.Text.Trim());
            model.is_aca   = Utils.ObjectToStr(rblIsAca.SelectedValue);
            //该研究生已经存在
            if (bll.Exists(model.no))
            {
                JscriptMsg("编号不能重复!", string.Empty);
                return(result);
            }

            if (bll.Add(model) > 0)
            {
                Model.manager manModel = new Model.manager();
                BLL.manager   manBll   = new BLL.manager();
                //不存在用户则进行提前加
                if (!manBll.Exists(model.no))
                {
                    manModel.role_id   = 2;
                    manModel.role_type = new BLL.manager_role().GetModel(manModel.role_id).role_type;
                    manModel.is_lock   = 0;
                    manModel.user_name = model.no;
                    manModel.real_name = model.name;
                    //获得6位的salt加密字符串
                    manModel.salt = Utils.GetCheckCode(6);
                    //以随机生成的6位字符串做为密钥加密
                    manModel.password  = DESEncrypt.Encrypt(model.no + "123", manModel.salt);
                    manModel.real_name = model.name;
                    manModel.add_time  = DateTime.Now;
                    manBll.Add(manModel);
                }

                AddAdminLog(DTEnums.ActionEnum.Add.ToString(), "添加研究生" + model.name); //记录日志
                result = true;
            }
            return(result);
        }
Beispiel #2
0
        protected void btnImport_Click(object sender, EventArgs e)
        {
            StringBuilder errorMsg = new StringBuilder(); // 错误信息

            try
            {
                #region 1.获取Excel文件并转换为一个List集合


                // 1.1存放Excel文件到本地服务器
                string filePath = Server.MapPath(txtImgUrl.Text.Trim()); // 保存文件并获取文件路径

                // 单元格抬头
                // key:实体对象属性名称,可通过反射获取值
                // value:属性对应的中文注解
                Dictionary <string, string> cellheader = new Dictionary <string, string> {
                    { "No", "编号" },
                    { "Name", "姓名" },
                    { "School", "本科毕业院校" },
                    { "Score", "笔试成绩" },
                    { "ReScore", "复试成绩" },
                    { "IsAca", "是否为学术型研究生" },
                };

                // 1.2解析文件,存放到一个List集合里
                List <StudentEntity> enlist = ExcelHelper.ExcelToEntityList <StudentEntity>(cellheader, filePath, out errorMsg);

                #endregion
                var sucCount = 0;
                for (int i = 0; i < enlist.Count; i++)
                {
                    StudentEntity en          = enlist[i];
                    string        errorMsgStr = "第" + (i + 1) + "行数据检测异常:";
                    //未填写研究生编号
                    if (string.IsNullOrWhiteSpace(en.No))
                    {
                        continue;
                    }
                    Model.student model = new Model.student();
                    BLL.student   bll   = new BLL.student();
                    //该研究生已经存在
                    if (bll.Exists(en.No))
                    {
                        continue;
                    }
                    model.no       = en.No;
                    model.name     = en.Name;
                    model.school   = en.School;
                    model.score    = en.Score;
                    model.re_score = en.ReScore;
                    model.is_aca   = en.IsAca;
                    model.add_time = DateTime.Now;
                    bll.Add(model);
                    sucCount++;

                    Model.manager manModel = new Model.manager();
                    BLL.manager   manBll   = new BLL.manager();
                    //该用户已经存在
                    if (manBll.Exists(en.No))
                    {
                        continue;
                    }
                    manModel.role_id   = 2;
                    manModel.role_type = new BLL.manager_role().GetModel(manModel.role_id).role_type;
                    manModel.is_lock   = 0;
                    manModel.user_name = en.No;
                    manModel.real_name = en.Name;
                    //获得6位的salt加密字符串
                    manModel.salt = Utils.GetCheckCode(6);
                    //以随机生成的6位字符串做为密钥加密
                    manModel.password  = DESEncrypt.Encrypt(en.No + "123", manModel.salt);
                    manModel.real_name = en.Name;
                    manModel.add_time  = DateTime.Now;
                    manBll.Add(manModel);
                }
                //context.Response.Write("{\"status\": 1, \"msg\": \"导入成功!\"}");
                JscriptMsg("导入成功" + sucCount + "条", Utils.CombUrlTxt("student_list.aspx", "keywords={0}&property={1}",
                                                                     this.keywords, this.property));
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }