Example #1
0
        public string Add(string Name,string DeptID,string DeptName, string Professional, string ProfessionalName, string Tel)
        {
            ControllerContext.HttpContext.Request.ContentEncoding = Encoding.GetEncoding("UTF-8");
            ControllerContext.HttpContext.Response.ContentEncoding = Encoding.GetEncoding("UTF-8");
            ControllerContext.HttpContext.Response.Charset = "UTF-8";

            var model = new Headmaster();
            model.Id = Guid.NewGuid();

            model.Name = Name;
            if (!string.IsNullOrEmpty(DeptID))
            {
                model.DeptID = Convert.ToInt32(DeptID);
            }
            model.DeptName = DeptName;

            if (!string.IsNullOrEmpty(Professional))
            {
                model.Professional = Convert.ToInt32(Professional);
            }
            model.ProfessionalName = ProfessionalName;
            model.Tel = Tel;

            model.IsValid = true;
            model.CreateTime = System.DateTime.Now;
            //model.CreateId = CurrentUser.UserId;
            //model.CreateName = CurrentUser.UserName;
            unitOfWork.HeadmasterBLL.InsertEntity(model);
            unitOfWork.Save();
            return "";
        }
Example #2
0
        private string HeadmasterImport(DataTable dt, out string msg)
        {
            msg = "";
            try
            {

                if (dt != null)
                {
                    foreach (DataRow row in dt.Rows)
                    {
                        var name = row["姓名"].ToString();
                        var deptName = row["教研室"].ToString();

                       var res= unitOfWork.HeadmasterBLL.GetEntitys(m => m.Name == name && m.IsValid && m.DeptName == deptName);
                        if (res.Any()) //重复数据
                        {
                            continue;
                        }
                        var model = new Headmaster();
                        model.Id = Guid.NewGuid();
                        model.Name = name;
                        var pid = unitOfWork.SysCodeBLL.GetCodeFromName(row["专业"].ToString());
                        if (!string.IsNullOrEmpty(pid))
                        {
                            model.Professional = Convert.ToInt32(pid);
                        }
                        model.ProfessionalName = row["专业"].ToString();

                        var dept = unitOfWork.SysCodeBLL.GetCodeFromName(row["教研室"].ToString());
                        if (!string.IsNullOrEmpty(dept))
                        {
                            model.DeptID = Convert.ToInt32(dept);
                        }
                        model.DeptName =row["教研室"].ToString();
                        model.Tel = row["联系方式"].ToString();
                        model.IsValid = true;
                        model.CreateTime = DateTime.Now;
                        unitOfWork.HeadmasterBLL.InsertEntity(model);
                        unitOfWork.Save();
                    }
                }
            }
            catch (Exception ex)
            {
                msg = "导入异常:" + ex.Message;
                Log.Error("HeadmasterImport 异常:", ex);
            }
            return msg;
        }