Example #1
0
        public dynamic SaveButtons(string id, JArray data)
        {
            var list = data.ToObject <List <SysButtonSelected> >();

            using (var db = new SysContext())
            {
                foreach (var item in list)
                {
                    if (item.Selected)
                    {
                        if (db.sys_menuButtonMap.Count(m => m.MenuCode == id && m.ButtonCode == item.ButtonCode) == 0)
                        {
                            db.sys_menuButtonMap.Add(new sys_menuButtonMap {
                                ButtonCode = item.ButtonCode, MenuCode = id
                            });
                        }
                    }
                    else
                    {
                        db.sys_menuButtonMap.Remove(m => m.MenuCode == id && m.ButtonCode == item.ButtonCode);
                    }
                }
                db.SaveChanges();
            }
            // 当保存简单的数据,不需要从数据库中重新刷新 UI 数据时,可以直接返回 true 表示保存成功
            // 否则,返回加载相同的数据集来自动更新客户端。
            return(true);
        }
Example #2
0
        public object Post(JArray data)
        {
            using (var db = new SysContext())
            {
                for (int i = 0; i < data.Count; i++)
                {
                    JObject       obj       = data[i] as JObject;
                    RowState      rowState  = (RowState)(int)obj["_row_state"];
                    sys_parameter parameter = obj.ToObject <sys_parameter>();
                    switch (rowState)
                    {
                    case RowState.Changed:
                        db.Entry(parameter).State = System.Data.Entity.EntityState.Modified;
                        break;

                    case RowState.New:
                        db.sys_parameter.Add(parameter);
                        break;

                    case RowState.Deleted:
                        db.Entry(parameter).State = System.Data.Entity.EntityState.Deleted;
                        break;
                    }
                }
                db.SaveChanges();
            }
            return(true);
        }
Example #3
0
        public string AddRule(Panasia.Gemini.FL.Models.ProcessModel model)
        {
            string Template_Info = model.Template_Info;
            string col_name      = model.col_name;
            string condition     = model.value;
            //decimal value = model.value;
            int    approveform_id = model.approveform_id;
            string Message        = "OK";

            try
            {
                fl_ApproveRules entity_fl_ApproveRules = new fl_ApproveRules();
                entity_fl_ApproveRules.FormID       = int.Parse(Template_Info.Substring(Template_Info.IndexOf("|") + 1));
                entity_fl_ApproveRules.Table_Name   = Template_Info.Substring(0, Template_Info.IndexOf("|"));
                entity_fl_ApproveRules.Col_Name     = col_name;
                entity_fl_ApproveRules.Condition    = condition;
                entity_fl_ApproveRules.ApproverID   = approveform_id;
                entity_fl_ApproveRules.CreatedUser  = LoginInfo.UserID;
                entity_fl_ApproveRules.ModifiedUser = LoginInfo.UserID;
                entity_fl_ApproveRules.ResetCreated();
                using (SysContext db = new SysContext())
                {
                    db.fl_ApproveRules.Add(entity_fl_ApproveRules);
                    db.SaveChanges();
                }
            }
            catch
            {
                Message = "Error";
            }
            return(Message);
        }
Example #4
0
        public object Post(JObject post)
        {
            var form = post["form"].ToObject <sys_user>();

            using (var db = new SysContext())
            {
                var dbForm = db.sys_user.Find(form.UserCode);
                if (dbForm == null)
                {
                    form.CreateDate   = DateTime.Now;
                    form.CreatePerson = (HttpContext.Current.Session["sys_user"] as sys_user).UserName;
                    db.sys_user.Add(form);
                }
                else
                {
                    dbForm.UserSeq       = form.UserSeq;
                    dbForm.UserName      = form.UserName;
                    dbForm.Description   = form.Description;
                    dbForm.Password      = form.Password;
                    dbForm.RoleName      = form.RoleName;
                    dbForm.OrganizeName  = form.OrganizeName;
                    dbForm.ConfigJSON    = form.ConfigJSON;
                    dbForm.IsEnable      = form.IsEnable;
                    dbForm.LoginCount    = form.LoginCount;
                    dbForm.LastLoginDate = form.LastLoginDate;
                    dbForm.UpdateDate    = form.UpdateDate = DateTime.Now;
                    dbForm.UpdatePerson  = form.UpdatePerson = (HttpContext.Current.Session["sys_user"] as sys_user).UserName;
                }
                db.SaveChanges();
            }
            return(new { success = true, form = form });
        }
Example #5
0
 public object Delete(string id)
 {
     using (var db = new SysContext())
     {
         db.sys_user.Remove(r => r.UserCode == id);
         db.SaveChanges();
     }
     return(true);
 }
Example #6
0
        public string EditTemplate(TemplateModel model)
        {
            int    TFDID               = model.TemplateID;
            int    TemplateID          = model.FormID;
            string template_Name       = model.FormName;
            string table_Name          = model.DataFrom;
            string template_FileName   = model.Template_FileName;
            string template_Url        = model.Template_Url;
            string templatedetail_Name = model.TemplateDetail_Name;
            string Message             = "OK";

            try
            {
                using (SysContext db = new SysContext())
                {
                    fl_FormTemplate entity_fl_FormTemplate = null;
                    if (TFDID != 0)
                    {
                        entity_fl_FormTemplate = db.fl_FormTemplate.Single(d => d.TemplateID == TFDID);
                        entity_fl_FormTemplate.Template_Name     = templatedetail_Name;
                        entity_fl_FormTemplate.Template_FileName = template_FileName;
                        entity_fl_FormTemplate.Template_Url      = template_Url;
                        entity_fl_FormTemplate.ModifiedUser      = LoginInfo.UserID;
                        entity_fl_FormTemplate.ModifiedTime      = DateTime.Now;
                        entity_fl_FormTemplate.ResetUpdated();
                    }
                    else
                    {
                        entity_fl_FormTemplate                   = new fl_FormTemplate();
                        entity_fl_FormTemplate.FormID            = TemplateID;
                        entity_fl_FormTemplate.Template_Name     = templatedetail_Name;
                        entity_fl_FormTemplate.Template_FileName = template_FileName;
                        entity_fl_FormTemplate.Template_Url      = template_Url;
                        entity_fl_FormTemplate.CreatedUser       = LoginInfo.UserID;
                        entity_fl_FormTemplate.ModifiedUser      = LoginInfo.UserID;
                        entity_fl_FormTemplate.ResetCreated();
                        db.fl_FormTemplate.Add(entity_fl_FormTemplate);
                    }

                    fl_Form entity_fl_Form = db.fl_Form.Single(t => t.FormID == entity_fl_FormTemplate.FormID);
                    entity_fl_Form.FormName     = template_Name;
                    entity_fl_Form.DataFrom     = table_Name;
                    entity_fl_Form.ModifiedUser = LoginInfo.UserID;
                    entity_fl_Form.ModifiedTime = DateTime.Now;
                    entity_fl_Form.ResetUpdated();

                    db.SaveChanges();
                }
            }
            catch
            {
                Message = "Error";
            }

            return(Message);
        }
Example #7
0
 public object Delete(string id)
 {
     using (var db = new SysContext())
     {
         db.sys_organizeRoleMap.Remove(r => r.OrganizeCode == id);
         db.sys_userOrganizeMap.Remove(u => u.OrganizeCode == id);
         db.sys_organize.Remove(o => o.OrganizeCode == id);
         db.SaveChanges();
         return(true);
     }
 }
Example #8
0
        public object SaveButtons(string id, JObject data)
        {
            using (var db = new SysContext())
            {
                db.sys_roleMenuMap.Remove(r => r.RoleCode == id);
                JArray menuArray = data["menus"] as JArray;
                for (int i = 0; i < menuArray.Count; i++)
                {
                    db.sys_roleMenuMap.Add(new sys_roleMenuMap
                    {
                        RoleCode = id,
                        MenuCode = (string)menuArray[i]
                    });
                }

                JArray dataArray = data["datas"] as JArray;
                if (dataArray != null)
                {
                    db.sys_rolePermissionMap.Remove(r => r.RoleCode == id);
                    for (int i = 0; i < dataArray.Count; i++)
                    {
                        var PermissionCode = (string)dataArray[i];
                        db.sys_rolePermissionMap.Add(new sys_rolePermissionMap
                        {
                            RoleCode       = id,
                            PermissionCode = PermissionCode
                        });
                    }
                }

                JArray buttonArray = data["buttons"] as JArray;
                if (buttonArray != null)
                {
                    db.sys_roleMenuButtonMap.Remove(r => r.RoleCode == id);
                    for (int i = 0; i < buttonArray.Count; i++)
                    {
                        var item       = (JObject)buttonArray[i];
                        var ButtonCode = (string)item["ButtonCode"];
                        var MenuCode   = (string)item["MenuCode"];
                        db.sys_roleMenuButtonMap.Add(new sys_roleMenuButtonMap
                        {
                            RoleCode   = id,
                            ButtonCode = ButtonCode,
                            MenuCode   = MenuCode
                        });
                    }
                }

                db.SaveChanges();
            }
            return(true);
        }
Example #9
0
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var data = _context.Menus.First(k => k.FID == id);

            _context.Menus.Remove(data);
            _context.SaveChanges();
            return(RedirectToAction("Index"));
        }
Example #10
0
        public void SaveMembers(string id, JArray data)
        {
            var oldList = Members(id);

            using (var db = new SysContext())
            {
                for (int i = 0; i < data.Count; i++)
                {
                    string item = (string)data[i];

                    if (!oldList.Remove(s => s.Value == item))
                    {
                        var d = item.Split('.');
                        if (d[0] == "user")
                        {
                            db.sys_userRoleMap.Add(new sys_userRoleMap {
                                RoleCode = id,
                                UserCode = d[1]
                            });
                        }
                        else
                        {
                            db.sys_organizeRoleMap.Add(new sys_organizeRoleMap
                            {
                                RoleCode     = id,
                                OrganizeCode = d[1]
                            });
                        }
                        // New Item
                    }
                }

                foreach (var delItem in oldList)
                {
                    var d    = delItem.Value.Split('.');
                    var code = d[1];
                    if (d[0] == "user")
                    {
                        db.sys_userRoleMap.Remove(u => u.RoleCode == id && u.UserCode == code);
                    }
                    else
                    {
                        db.sys_organizeRoleMap.Remove(u => u.RoleCode == id && u.OrganizeCode == code);
                    }
                }

                db.SaveChanges();
            }
        }
Example #11
0
        public object Types(JArray array)
        {
            using (var db = new SysContext())
            {
                for (int i = 0; i < array.Count; i++)
                {
                    var          row_state = (RowState)(int)array[i]["_row_state"];
                    sys_codeType codeType  = array[i].ToObject <sys_codeType>();
                    switch (row_state)
                    {
                    case RowState.Changed:
                        var oldCodeType = db.sys_codeType.Find(codeType.CodeType);
                        oldCodeType.CodeTypeName = codeType.CodeTypeName;
                        oldCodeType.Seq          = codeType.Seq;
                        oldCodeType.Description  = codeType.Description;
                        oldCodeType.UpdateDate   = DateTime.Now;
                        oldCodeType.UpdatePerson = User.Identity.GetUserInfo().UserName;
                        break;

                    case RowState.New:
                        codeType.CreateDate   = DateTime.Now;
                        codeType.CreatePerson = User.Identity.GetUserInfo().UserName;
                        db.sys_codeType.Add(codeType);
                        break;

                    case RowState.Deleted:
                        db.sys_code.Remove(r => r.CodeType == codeType.CodeType);
                        db.sys_codeType.Remove(r => r.CodeType == codeType.CodeType);
                        break;
                    }
                }

                // 记录操作日志
                db.sys_log.Add(new sys_log
                {
                    UserCode = User.Identity.Name,
                    UserName = User.Identity.GetUserInfo().UserName,
                    Position = Request.RequestUri.PathAndQuery,
                    Target   = "字典数据",
                    Type     = "修改",
                    Message  = array.ToString(),
                    Date     = DateTime.Now,
                });

                db.SaveChanges();
            }
            return(Types());
        }
Example #12
0
        public bool ResetPassword(JObject data)
        {
            var userCode = (string)data["UserCode"];

            using (var db = new SysContext())
            {
                var user = db.sys_user.Find(userCode);
                if (user != null)
                {
                    user.Password = "******";
                    db.SaveChanges();
                    return(true);
                }
            }
            return(false);
        }
Example #13
0
 public bool UserRole(String UserCode, JArray data)
 {
     using (var db = new SysContext())
     {
         db.sys_userRoleMap.Remove(u => u.UserCode == UserCode);
         for (var i = 0; i < data.Count; i++)
         {
             db.sys_userRoleMap.Add(new sys_userRoleMap {
                 UserCode = UserCode, RoleCode = (string)data[i]
             });
         }
         db.SaveChanges();
         //return db.Database.SqlQuery<string>("select OrganizeCode from sys_userOrganizeMap where UserCode = @UserCode", new System.Data.SqlClient.SqlParameter("@UserCode", UserCode)).ToArray();
     }
     return(true);
 }
Example #14
0
        public string DeleteRule()
        {
            string Message = "OK";

            try
            {
                using (SysContext db = new SysContext())
                {
                    db.fl_ApproveRules.Remove(db.fl_ApproveRules.Find(int.Parse(Request["id"])));
                    db.SaveChanges();
                }
            }
            catch
            {
                Message = "Error";
            }
            return(Message);;
        }
Example #15
0
        public object Post(JObject data)
        {
            string _id = data.Value <string>("_id");
            var    org = data.ToObject <sys_organize>();

            using (var db = new SysContext())
            {
                if (string.IsNullOrEmpty(_id))
                {
                    db.sys_organize.Add(org);
                }
                else
                {
                    var organize = db.sys_organize.Find(_id);
                    DynamicData.Copy(org, organize, data);
                }
                db.SaveChanges();
            }
            return(true);
        }
Example #16
0
        public object Post(JArray data)
        {
            using (var db = new SysContext())
            {
                for (int i = 0; i < data.Count; i++)
                {
                    JObject  obj      = data[i] as JObject;
                    RowState rowState = (RowState)(int)obj["_row_state"];
                    sys_code code     = obj.ToObject <sys_code>();
                    switch (rowState)
                    {
                    case RowState.Changed:
                        db.Entry(code).State = System.Data.Entity.EntityState.Modified;
                        break;

                    case RowState.New:
                        db.sys_code.Add(code);
                        break;

                    case RowState.Deleted:
                        db.Entry(code).State = System.Data.Entity.EntityState.Deleted;
                        break;
                    }
                }

                // 记录操作日志
                db.sys_log.Add(new sys_log
                {
                    UserCode = User.Identity.Name,
                    UserName = User.Identity.GetUserInfo().UserName,
                    Position = Request.RequestUri.PathAndQuery,
                    Target   = "字典分类数据",
                    Type     = "修改",
                    Message  = data.ToString(),
                    Date     = DateTime.Now,
                });
                db.SaveChanges();
            }
            return(true);
        }
Example #17
0
        public string UpdateCompanys()
        {
            var    FormID   = Convert.ToInt32(Request["FromID"]);
            var    Companys = Request["Companys"];
            string Message  = "OK";

            using (SysContext db = new SysContext())
            {
                try {
                    var form = db.fl_Form.FirstOrDefault(f => f.FormID.Equals(FormID));
                    form.Companys = Companys;
                    form.ResetUpdated();
                    db.SaveChanges();
                }
                catch (Exception e)
                {
                    Message = "Error";
                }
            }

            return(Message);
        }
Example #18
0
        public JsonResult ModifyPassword(ModifyPasswordModel model)
        {
            string msg = ""; bool success;

            using (var db = new SysContext())
            {
                var oldUser = db.sys_user.Find(model.UserCode);
                if (oldUser != null && model.oldPassword == oldUser.Password)
                {
                    oldUser.Password = model.newPassword;
                    db.SaveChanges();
                    msg     = "修改成功";
                    success = true;
                }
                else
                {
                    success = false;
                    msg     = "原密码不正确";
                }
            }
            return(Json(new { success, msg }, JsonRequestBehavior.AllowGet));
        }
Example #19
0
        public object Post(JArray array)
        {
            using (var db = new SysContext())
            {
                for (int i = 0; i < array.Count; i++)
                {
                    var      row_state = (RowState)(int)array[i]["_row_state"];
                    sys_user user      = array[i].ToObject <sys_user>();
                    switch (row_state)
                    {
                    case RowState.Changed:
                        var oldUser = db.sys_user.Find(user.UserCode);
                        oldUser.UserName     = user.UserName;
                        oldUser.Mobile       = user.Mobile;
                        oldUser.Description  = user.Description;
                        oldUser.IsEnable     = user.IsEnable;
                        oldUser.UpdateDate   = DateTime.Now;
                        oldUser.UpdatePerson = User.Identity.GetUserInfo().UserName;
                        break;

                    case RowState.New:
                        user.CreateDate   = DateTime.Now;
                        user.CreatePerson = User.Identity.GetUserInfo().UserName;
                        user.Password     = "******";
                        db.sys_user.Add(user);
                        break;

                    case RowState.Deleted:
                        db.sys_userRoleMap.Remove(r => r.UserCode == user.UserCode);
                        db.sys_userOrganizeMap.Remove(r => r.UserCode == user.UserCode);
                        db.sys_userSetting.Remove(r => r.UserCode == user.UserCode);
                        db.sys_user.Remove(r => r.UserCode == user.UserCode);
                        break;
                    }
                }
                db.SaveChanges();
            }
            return(Get(null));
        }
Example #20
0
        public object Post(JArray array)
        {
            using (var db = new SysContext())
            {
                for (int i = 0; i < array.Count; i++)
                {
                    var      row_state = (RowState)(int)array[i]["_row_state"];
                    sys_role role      = array[i].ToObject <sys_role>();
                    switch (row_state)
                    {
                    case RowState.Changed:
                        var oldRole = db.sys_role.Find(role.RoleCode);
                        oldRole.RoleName     = role.RoleName;
                        oldRole.RoleCode     = role.RoleCode;
                        oldRole.RoleSeq      = role.RoleSeq;
                        oldRole.Description  = role.Description;
                        oldRole.UpdateDate   = DateTime.Now;
                        oldRole.UpdatePerson = User.Identity.GetUserInfo().UserName;
                        break;

                    case RowState.New:
                        role.CreateDate   = DateTime.Now;
                        role.CreatePerson = User.Identity.GetUserInfo().UserName;
                        db.sys_role.Add(role);
                        break;

                    case RowState.Deleted:
                        db.sys_organizeRoleMap.Remove(r => r.RoleCode == role.RoleCode);
                        db.sys_userRoleMap.Remove(r => r.RoleCode == role.RoleCode);
                        db.sys_roleMenuMap.Remove(r => r.RoleCode == role.RoleCode);
                        db.sys_role.Remove(db.sys_role.Find(role.RoleCode));
                        break;
                    }
                }
                db.SaveChanges();
            }
            return(Get());
        }
Example #21
0
        public JsonResult Delete(FileSerial obj)
        {
            //string fileIdText = obj.GetValue("fileId").ToString();
            //string serialText = obj.GetValue("serial").ToString();
            //int fileId = 0, serial = 0;
            //int.TryParse(fileIdText, out fileId);
            //int.TryParse(serialText, out serial);
            var fileId = obj.FileId;
            var serial = obj.Serial;

            if (fileId > 0 && serial > 0)
            {
                try
                {
                    using (var db = new SysContext())
                    {
                        var file = db.sys_file.Find(fileId, serial);
                        if (file != null)
                        {
                            var path = Server.MapPath("~" + file.Path);
                            if (System.IO.File.Exists(path))
                            {
                                System.IO.File.Delete(path);
                            }
                            db.sys_file.Remove(file);
                            db.SaveChanges();
                        }
                    }
                }
                catch { }
            }
            else
            {
                return(Json(false));
            }

            return(Json(true));
        }
Example #22
0
        public string DeleteEmployee()
        {
            string Message = "OK";

            try
            {
                using (SysContext db = new SysContext())
                {
                    int id = int.Parse(Request["id"]);
                    db.fl_Approver.Remove(db.fl_Approver.Find(id));
                    fl_ApproveRules rule = db.fl_ApproveRules.FirstOrDefault(r => r.ApproverID == id);
                    if (rule != null)
                    {
                        db.fl_ApproveRules.Remove(rule);
                    }
                    db.SaveChanges();
                }
            }
            catch
            {
                Message = "Error";
            }
            return(Message);
        }
Example #23
0
        public ActionResult SearchScheme(string pageCode, string method = "list")
        {
            var    user   = System.Web.HttpContext.Current.Session["sys_user"] as sys_user;
            var    sss    = new SysSerialServices();
            object result = null;

            using (var db = new SysContext())
            {
                switch (method)
                {
                case "list":
                    if (user == null)
                    {
                        result = db.sys_searchScheme.Where(s => s.PageCode == pageCode).OrderBy(s => s.Title).Select(s => new {
                            s.Id,
                            s.Title,
                            s.Data,
                            deleable = false
                        }).ToList();
                    }
                    else
                    {
                        result = db.sys_searchScheme.Where(s => s.PageCode == pageCode && (s.CompCode == null || s.CompCode == user.CompCode)).OrderBy(s => s.Title).Select(s => new {
                            s.Id,
                            s.Title,
                            s.Data,
                            deleable = s.CompCode == user.CompCode && s.UserCode == user.UserCode
                        }).ToList();
                    }
                    break;

                case "add":
                    if (user != null)
                    {
                        var ss = new sys_searchScheme
                        {
                            Id       = sss.GetNewSerial(db, "sys_searchScheme"),
                            CompCode = user.CompCode,
                            UserCode = user.UserCode,
                            PageCode = pageCode,
                            Title    = Request["title"],
                            Data     = Request["data"]
                        };
                        db.sys_searchScheme.Add(ss);
                        db.SaveChanges();
                        result = new { ss.Id, ss.Title, ss.Data, deleable = true };
                    }
                    break;

                case "del":
                    if (user != null)
                    {
                        var ss = db.sys_searchScheme.Find(int.Parse(Request["id"]));
                        if (ss != null && ss.CompCode == user.CompCode && ss.UserCode == user.UserCode)
                        {
                            db.Entry(ss).State = EntityState.Deleted;
                            db.SaveChanges();
                            result = true;
                        }
                    }
                    break;
                }
            }
            return(new JsonNetResult(result));
        }
Example #24
0
        public JsonResult Upload()
        {
            string rootPath = Server.MapPath("~/Upload");
            string path     = Request.Form["path"];
            bool   replace  = bool.Parse(Request.Form["replace"]);

            if (!string.IsNullOrEmpty(path))
            {
                path = Fruit.Data.FruitExpression.Replace(path);
                var targetPath = Server.MapPath("~/Upload/" + path);
                if (!System.IO.Directory.Exists(targetPath))
                {
                    System.IO.Directory.CreateDirectory(targetPath);
                }
            }
            string saveDir    = rootPath;
            string fileIdText = Request.Form["fileId"];
            int    fileId     = 0;

            int.TryParse(fileIdText, out fileId);

            List <sys_file> files = new List <sys_file>();

            foreach (var file in Request.Files.GetMultiple("file"))
            {
                if (file.ContentLength > 1)
                {
                    var saveName = Guid.NewGuid().ToString() + System.IO.Path.GetExtension(file.FileName);
                    var savePath = System.IO.Path.Combine(rootPath, path, saveName);
                    file.SaveAs(savePath);
                    files.Add(new sys_file {
                        FileId = fileId, FileName = System.IO.Path.GetFileName(file.FileName), Path = "/Upload/" + path + "/" + saveName, CreateDate = DateTime.Now, CreatePerson = Fruit.Data.FruitExpression.Replace("{U.UserCode}")
                    });
                }
            }

            if (files.Count > 0)
            {
                // 需要进行保存操作
                using (var db = new SysContext())
                {
                    if (fileId == 0)
                    {
                        fileId = new SysSerialServices().GetNewSerial(db, "sys_file");
                    }
                    else if (replace)
                    {
                        db.Database.ExecuteSqlCommand("delete from sys_file where FileId = @FileId", new System.Data.SqlClient.SqlParameter("@FileId", fileId));
                    }
                    var serial = db.Database.SqlQuery <int>("select top 1 Serial from sys_file where FileId = @FileId order by Serial desc", new System.Data.SqlClient.SqlParameter("@FileId", fileId)).FirstOrDefault();
                    foreach (var file in files)
                    {
                        file.FileId = fileId;
                        file.Serial = ++serial;
                        db.sys_file.Add(file);
                    }
                    db.SaveChanges();
                }
            }

            return(Json(new { fileId, files }));
        }
        public ActionResult ImportCompany(FormCollection form)
        {
            HttpRequest        request     = System.Web.HttpContext.Current.Request;
            HttpFileCollection FileCollect = request.Files;
            DataSet            ds          = new DataSet();

            StringBuilder skipIndex  = new StringBuilder();
            StringBuilder rightIndex = new StringBuilder();
            StringBuilder errorIndex = new StringBuilder();
            ResultData    res        = new ResultData();

            if (FileCollect.Count > 0)
            {
                foreach (string str in FileCollect)
                {
                    #region 读取excel文件
                    ds = ReadExcel(str, ds, FileCollect);
                    //HttpPostedFile FileSave = FileCollect[str];  //用key获取单个文件对象HttpPostedFile
                    //string fileName = FileSave.FileName.Substring(FileSave.FileName.LastIndexOf("\\") + 1);
                    //string filePath = string.Format(HttpRuntime.AppDomainAppPath.ToString() + @"Upload");
                    //if (!Directory.Exists(filePath))
                    //{
                    //    Directory.CreateDirectory(filePath);
                    //}
                    //string Path = string.Format("{0}\\{1}_{2}", filePath, DateTime.Now.ToString("yyyyMMddHHmmss"), fileName);
                    //FileSave.SaveAs(Path);
                    //ds = th.ReadExlToDt(Path);
                    //System.IO.File.Delete(Path);
                    #endregion
                    #region 判断excel表中的数据是否存在
                    string[] cols = new string[] { "事业部", "公司名称", "简称", "负责人", "排序", "网址1", "网址2", "电话1", "电话2", "公司地址", "公司说明", "备注" };
                    for (int j = 0; j < cols.Length; j++)
                    {
                        if (!ds.Tables[0].Columns.Contains(cols[j]))
                        {
                            res.ErrorMessage = cols[j] + "列不存在!";
                            res.HasError     = false;
                            return(Json(res, "text/html;charset=utf-8", JsonRequestBehavior.AllowGet));
                        }
                    }
                    #endregion

                    int count = ds.Tables[0].Rows.Count;
                    using (var db = new SysContext())
                    {
                        for (int i = 0; i < count; i++)
                        {
                            #region 预处理
                            string buname, companyname, managerName;
                            int    sort = i + 1;
                            buname      = ds.Tables[0].Rows[i]["事业部"].ToString().Trim();
                            companyname = ds.Tables[0].Rows[i]["公司名称"].ToString().Trim();
                            managerName = ds.Tables[0].Rows[i]["负责人"].ToString().Trim();
                            #endregion

                            var oldCompany = (from com in db.hr_Companies where com.Name.Equals(companyname) && com.IsActive select com).ToList();
                            if (oldCompany.Count > 0)
                            {
                                skipIndex.Append((i + 1).ToString() + ',');
                            }
                            else
                            {
                                string managerID;
                                var    buid = (from bu in db.hr_BUs where bu.Name.Equals(buname) && bu.IsActive select bu.BUID.ToString()).ToList();
                                using (var dbe = new Panasia.Core.Sys.SysContext())
                                {
                                    var manager = (from ma in dbe.hr_Employees where ma.Name.Equals(managerName) && ma.IsActive select ma.EmployeeID.ToString()).ToList();
                                    managerID = manager.Count > 0 ? manager[0] : "";
                                }
                                #region 获取公司ID
                                db.Database.Connection.Open();
                                var cmd = db.Database.Connection.CreateCommand();
                                cmd.CommandText = "declare @demo varchar(max) exec dbo.sp_CreateSerialCode 'Company','C',6,@demo output select @demo";
                                var companyid = cmd.ExecuteScalar();
                                db.Database.Connection.Close();
                                #endregion
                                #region 将公司信息插入数据库并获取异常
                                try
                                {
                                    hr_Company company = new hr_Company
                                    {
                                        CompanyID   = companyid.ToString(),
                                        Name        = companyname,
                                        BUID        = buid.Count > 0 ? buid[0] : "",
                                        ManagerID   = managerID,
                                        SortID      = ds.Tables[0].Rows[i]["排序"].ToString() == "" ? sort : ds.Tables[0].Rows[i]["排序"].ToInt32(),
                                        IsActive    = true,
                                        JC          = ds.Tables[0].Rows[i]["简称"].ToString().Trim(),
                                        JM          = ds.Tables[0].Rows[i]["简称"].ToString().Trim().GetPYFirsts(),
                                        Url1        = ds.Tables[0].Rows[i]["网址1"].ToString().Trim(),
                                        Url2        = ds.Tables[0].Rows[i]["网址2"].ToString().Trim(),
                                        Tel1        = ds.Tables[0].Rows[i]["电话1"].ToString().Trim(),
                                        Tel2        = ds.Tables[0].Rows[i]["电话2"].ToString().Trim(),
                                        Address     = ds.Tables[0].Rows[i]["公司地址"].ToString().Trim(),
                                        Description = ds.Tables[0].Rows[i]["公司说明"].ToString().Trim(),
                                        Remark      = ds.Tables[0].Rows[i]["备注"].ToString().Trim()
                                    };
                                    company.ResetCreated();
                                    db.hr_Companies.Add(company);
                                    db.SaveChanges();
                                    rightIndex.Append((i + 1).ToString() + ',');
                                }
                                catch (Exception ex)
                                {
                                    errorIndex.Append((i + 1).ToString() + ',');
                                    res.ErrorMessage = skipIndex + ":" + rightIndex + ":" + errorIndex;
                                    res.HasError     = true;
                                    return(Json(res, "text/html;charset=utf-8", JsonRequestBehavior.AllowGet));
                                }
                                #endregion
                            }
                        }
                    }
                }
            }
            res.ErrorMessage = skipIndex + ":" + rightIndex + ":" + errorIndex;
            res.HasError     = true;
            return(Json(res, "text/html;charset=utf-8", JsonRequestBehavior.AllowGet));
        }
        public ActionResult ImportDept(FormCollection form)
        {
            HttpRequest        request     = System.Web.HttpContext.Current.Request;
            HttpFileCollection FileCollect = request.Files;
            DataSet            ds          = new DataSet();

            StringBuilder skipIndex  = new StringBuilder();
            StringBuilder rightIndex = new StringBuilder();
            StringBuilder errorIndex = new StringBuilder();
            ResultData    res        = new ResultData();

            if (FileCollect.Count > 0)
            {
                foreach (string str in FileCollect)
                {
                    ds = ReadExcel(str, ds, FileCollect);
                    #region 判断excel表中的数据是否存在
                    string[] cols = new string[] { "事业部", "公司", "部门", "子部门", "负责人", "排序", "备注" };
                    for (int j = 0; j < cols.Length; j++)
                    {
                        if (!ds.Tables[0].Columns.Contains(cols[j]))
                        {
                            res.ErrorMessage = cols[j] + "列不存在!";
                            res.HasError     = false;
                            return(Json(res, "text/html;charset=utf-8", JsonRequestBehavior.AllowGet));
                        }
                    }
                    #endregion
                    int count = ds.Tables[0].Rows.Count;
                    using (var db = new SysContext())
                    {
                        for (int i = 0; i < count; i++)
                        {
                            #region 预处理
                            string buname, companyname, managerName, deptName, parentName, managerID, parentID, deptid, companyid;
                            int    sort = i + 1;
                            buname      = ds.Tables[0].Rows[i]["事业部"].ToString().Trim();
                            companyname = ds.Tables[0].Rows[i]["公司"].ToString().Trim();
                            managerName = ds.Tables[0].Rows[i]["负责人"].ToString().Trim();
                            #region 获取负责人id
                            using (var dbe = new Panasia.Core.Sys.SysContext())
                            {
                                var manager = (from ma in dbe.hr_Employees where ma.Name.Equals(managerName) && ma.IsActive select ma.EmployeeID.ToString()).ToList();
                                managerID = manager.Count > 0 ? manager[0] : "";
                            }
                            #endregion

                            var company = (from com in db.hr_Companies where com.Name.Equals(companyname) && com.IsActive select com.CompanyID.ToString()).ToList();
                            var buid    = (from bu in db.hr_BUs where bu.Name.Equals(buname) && bu.IsActive select bu.BUID.ToString()).ToList();
                            #endregion
                            if (company.Count == 0)
                            {
                                res.ErrorMessage = companyname + "不存在!";
                                res.HasError     = false;
                                return(Json(res, "text/html;charset=utf-8", JsonRequestBehavior.AllowGet));
                            }
                            else
                            {
                                #region 判断部门存在则跳过
                                companyid = company[0];
                                var departments = new List <string>();
                                if (ds.Tables[0].Rows[i]["子部门"].ToString().Trim() == "")
                                {
                                    deptName    = ds.Tables[0].Rows[i]["部门"].ToString().Trim();
                                    departments = (from dept in db.hr_Depts where dept.Name.Equals(deptName) && dept.CompanyID.Equals(companyid) && dept.IsActive select dept.DeptID.ToString()).ToList();
                                }
                                else
                                {
                                    deptName   = ds.Tables[0].Rows[i]["子部门"].ToString().Trim();
                                    parentName = ds.Tables[0].Rows[i]["部门"].ToString().Trim();
                                    var parentid = (from dept1 in db.hr_Depts where dept1.Name.Equals(parentName) && dept1.IsActive select dept1.ParentID.ToString()).ToList().FirstOrDefault();
                                    departments = (from dept in db.hr_Depts where dept.Name.Equals(deptName) && dept.ParentID.Equals(parentid) && dept.IsActive select dept.DeptID).ToList();
                                }


                                if (departments.Count > 0)
                                {
                                    skipIndex.Append((i + 1).ToString() + ",");
                                }
                                #endregion
                                else
                                {
                                    #region 获取部门ID
                                    try
                                    {
                                        db.Database.Connection.Open();
                                        var cmd = db.Database.Connection.CreateCommand();
                                        cmd.CommandText = "declare @demo varchar(max) exec dbo.sp_CreateSerialCode 'Depart','D',6,@demo output select @demo";
                                        deptid          = cmd.ExecuteScalar().ToString();
                                        db.Database.Connection.Close();
                                    }
                                    catch (Exception ex)
                                    {
                                        res.ErrorMessage = "数据库操作出错";
                                        res.HasError     = false;
                                        return(Json(res, "text/html;charset=utf-8", JsonRequestBehavior.AllowGet));
                                    }

                                    #endregion
                                    if (ds.Tables[0].Rows[i]["子部门"].ToString().Trim() == "")
                                    {
                                        #region 新建没有父节点的部门
                                        try
                                        {
                                            hr_Department department = new hr_Department
                                            {
                                                DeptID      = deptid,
                                                Name        = ds.Tables[0].Rows[i]["部门"].ToString().Trim(),
                                                ManagerID   = managerID,
                                                ParentID    = "",
                                                CompanyID   = company[0],
                                                BUID        = buid.Count > 0?buid[0]:"",
                                                Description = ds.Tables[0].Rows[i]["备注"].ToString().Trim(),
                                                IsActive    = true,
                                                SortID      = sort
                                            };
                                            department.ResetCreated();
                                            db.hr_Depts.Add(department);
                                            db.SaveChanges();
                                            rightIndex.Append((i + 1).ToString() + ',');
                                        }
                                        catch (Exception ex)
                                        {
                                            errorIndex.Append((i + 1).ToString() + ',');
                                            res.ErrorMessage = skipIndex + ":" + rightIndex + ":" + errorIndex;
                                            res.HasError     = true;
                                            return(Json(res, "text/html;charset=utf-8", JsonRequestBehavior.AllowGet));
                                        }
                                        #endregion
                                    }
                                    else
                                    {
                                        #region 新建有父节点的部门
                                        try
                                        {
                                            deptName = ds.Tables[0].Rows[i]["部门"].ToString().Trim();
                                            var           parentid   = (from dept in db.hr_Depts where dept.Name.Equals(deptName) && dept.IsActive && dept.CompanyID.Equals(companyid) select dept.DeptID.ToString()).ToList();
                                            hr_Department department = new hr_Department
                                            {
                                                DeptID      = deptid,
                                                Name        = ds.Tables[0].Rows[i]["子部门"].ToString().Trim(),
                                                ManagerID   = managerID,
                                                ParentID    = parentid[0],
                                                CompanyID   = companyid,
                                                BUID        = buid.Count > 0?buid[0]:"",
                                                Description = ds.Tables[0].Rows[i]["备注"].ToString().Trim(),
                                                IsActive    = true,
                                                SortID      = sort
                                            };
                                            department.ResetCreated();
                                            db.hr_Depts.Add(department);
                                            db.SaveChanges();
                                            rightIndex.Append((i + 1).ToString() + ',');
                                        }
                                        catch (Exception ex)
                                        {
                                            errorIndex.Append((i + 1).ToString() + ',');
                                            res.ErrorMessage = skipIndex + ":" + rightIndex + ":" + errorIndex;
                                            res.HasError     = true;
                                            return(Json(res, "text/html;charset=utf-8", JsonRequestBehavior.AllowGet));
                                        }
                                        #endregion
                                    }
                                }
                            }
                        }
                    }
                    res.ErrorMessage = skipIndex + ":" + rightIndex + ":" + errorIndex;
                    res.HasError     = true;
                    return(Json(res, "text/html;charset=utf-8", JsonRequestBehavior.AllowGet));
                }
            }
            return(Json(res, "text/html;charset=utf-8", JsonRequestBehavior.AllowGet));
        }
Example #27
0
        public string AddEmployee(Panasia.Gemini.FL.Models.ProcessModel model)
        {
            bool   IsFuzzy             = model.IsFuzzy;
            string dept_id             = IsFuzzy ? "" : model.dept_id;
            string job_id              = IsFuzzy ? "" : model.job_id;
            string emp_id_emp          = IsFuzzy ? "" : model.emp_id_emp;
            int    emp_sort            = model.emp_sort;
            int    TemplateID          = model.FormID;
            int    FuzzyType           = IsFuzzy ? model.FuzzyType : 0;
            string CompanyID           = model.CompanyID;
            string Message             = "OK";
            string EmployeeIDCondition = model.hEmployeeIDCondition;
            string DeptIDCondition     = model.hDeptIDCondition;
            bool   IsGroupApprover     = model.IsGroupApprover;

            if (emp_id_emp == "333333" && model.hEmployeeIDCondition == null)
            {
                emp_id_emp = "";
            }
            if (dept_id == "222222" && model.hDeptIDCondition == null)
            {
                dept_id = "111111";
            }
            using (SysContext db = new SysContext())
            {
                try
                {
                    //bool isg = db.fl_Approver.Where(a => a.FormID == TemplateID && a.Employee_Sort == emp_sort).First().IsGroupApprover;
                    //if (isg == IsGroupApprover)
                    //{
                    fl_Approver entity_fl_Approve = new fl_Approver();
                    entity_fl_Approve.FormID              = TemplateID;
                    entity_fl_Approve.Employee_Sort       = emp_sort;
                    entity_fl_Approve.EmployeeID          = emp_id_emp == null ? "" : emp_id_emp;
                    entity_fl_Approve.DeptID              = dept_id;
                    entity_fl_Approve.JobID               = job_id;
                    entity_fl_Approve.IsFuzzy             = IsFuzzy;
                    entity_fl_Approve.FuzzyType           = FuzzyType;
                    entity_fl_Approve.TemplateID          = model.TemplateID;
                    entity_fl_Approve.CompanyID           = CompanyID;
                    entity_fl_Approve.DeptIDCondition     = DeptIDCondition;
                    entity_fl_Approve.EmployeeIDCondition = EmployeeIDCondition;
                    entity_fl_Approve.IsGroupApprover     = IsGroupApprover;
                    entity_fl_Approve.CreatedUser         = LoginInfo.UserID;
                    entity_fl_Approve.ModifiedUser        = LoginInfo.UserID;
                    entity_fl_Approve.ResetCreated();


                    db.fl_Approver.Add(entity_fl_Approve);
                    db.SaveChanges();
                    //}
                    //else
                    //{
                    //    Message = "同一次序必须选择相同的签核次序";
                    //}
                }
                catch
                {
                    Message = "Error";
                }
            }
            return(Message);
        }
Example #28
0
        public string AddEmployee(Panasia.Gemini.FL.Models.ProcessModel model)
        {
            bool   IsFuzzy             = model.IsFuzzy;
            string dept_id             = IsFuzzy ? "" : model.dept_id;
            string job_id              = IsFuzzy ? "" : model.job_id;
            string emp_id_emp          = IsFuzzy ? "" : model.emp_id_emp;
            int    emp_sort            = model.emp_sort;
            int    TemplateID          = model.FormID;
            int    FuzzyType           = IsFuzzy ? model.FuzzyType : 0;
            string CompanyID           = model.CompanyID;
            string Message             = "OK";
            string EmployeeIDCondition = model.hEmployeeIDCondition;
            string DeptIDCondition     = model.hDeptIDCondition;
            bool   IsGroupApprover     = model.IsGroupApprover;
            string Approverid          = model.Approverid;
            string Approver            = model.Approver;

            if (emp_id_emp == "333333" && model.hEmployeeIDCondition == null)
            {
                emp_id_emp = "";
            }
            if (dept_id == "222222" && model.hDeptIDCondition == null)
            {
                dept_id = "111111";
            }
            using (SysContext db = new SysContext())
            {
                try
                {
                    //bool isg = db.fl_Approver.Where(a => a.FormID == TemplateID && a.Employee_Sort == emp_sort).First().IsGroupApprover;
                    //if (isg == IsGroupApprover)
                    //{
                    if (string.IsNullOrEmpty(Approverid))
                    {
                        fl_Approver entity_fl_Approve = new fl_Approver();
                        entity_fl_Approve.FormID              = TemplateID;
                        entity_fl_Approve.Employee_Sort       = emp_sort;
                        entity_fl_Approve.EmployeeID          = emp_id_emp == null ? "" : emp_id_emp;
                        entity_fl_Approve.DeptID              = dept_id;
                        entity_fl_Approve.JobID               = job_id;
                        entity_fl_Approve.IsFuzzy             = IsFuzzy;
                        entity_fl_Approve.FuzzyType           = FuzzyType;
                        entity_fl_Approve.TemplateID          = model.TemplateID;
                        entity_fl_Approve.CompanyID           = CompanyID;
                        entity_fl_Approve.DeptIDCondition     = DeptIDCondition;
                        entity_fl_Approve.EmployeeIDCondition = EmployeeIDCondition;
                        entity_fl_Approve.IsGroupApprover     = IsGroupApprover;
                        entity_fl_Approve.CreatedUser         = LoginInfo.UserID;
                        entity_fl_Approve.ModifiedUser        = LoginInfo.UserID;
                        entity_fl_Approve.ResetCreated();


                        db.fl_Approver.Add(entity_fl_Approve);
                        db.SaveChanges();
                    }
                    else
                    {
                        string[] Approverids = Approverid.Split(',');
                        foreach (var arr in Approverids)
                        {
                            int         aid               = int.Parse(arr.ToString());
                            fl_Approver fl_Approve        = db.fl_Approver.Single(a => a.ApproverID == aid);
                            fl_Approver entity_fl_Approve = new fl_Approver();
                            entity_fl_Approve.FormID              = int.Parse(model.form_id);
                            entity_fl_Approve.Employee_Sort       = fl_Approve.Employee_Sort;
                            entity_fl_Approve.EmployeeID          = fl_Approve.EmployeeID;
                            entity_fl_Approve.DeptID              = fl_Approve.DeptID;
                            entity_fl_Approve.JobID               = fl_Approve.JobID;
                            entity_fl_Approve.IsFuzzy             = fl_Approve.IsFuzzy;
                            entity_fl_Approve.FuzzyType           = fl_Approve.FuzzyType;
                            entity_fl_Approve.TemplateID          = fl_Approve.TemplateID;
                            entity_fl_Approve.CompanyID           = fl_Approve.CompanyID;
                            entity_fl_Approve.DeptIDCondition     = fl_Approve.DeptIDCondition;
                            entity_fl_Approve.EmployeeIDCondition = fl_Approve.EmployeeIDCondition;
                            entity_fl_Approve.IsGroupApprover     = fl_Approve.IsGroupApprover;
                            entity_fl_Approve.CreatedUser         = fl_Approve.CreatedUser;
                            entity_fl_Approve.ModifiedUser        = fl_Approve.ModifiedUser;
                            entity_fl_Approve.ResetCreated();

                            db.fl_Approver.Add(entity_fl_Approve);
                            db.SaveChanges();
                        }
                        if (!string.IsNullOrEmpty(Approver))
                        {
                            string[] Approvers = Approver.Split('|');
                            foreach (var arr in Approvers)
                            {
                                string[]    fl_Approves       = arr.Replace("undefined", "").Split(',');
                                fl_Approver entity_fl_Approve = new fl_Approver();
                                entity_fl_Approve.FormID              = int.Parse(model.form_id);
                                entity_fl_Approve.Employee_Sort       = int.Parse(fl_Approves[5].ToString());
                                entity_fl_Approve.EmployeeID          = fl_Approves[4];
                                entity_fl_Approve.DeptID              = fl_Approves[2];
                                entity_fl_Approve.JobID               = fl_Approves[3];
                                entity_fl_Approve.IsFuzzy             = false;
                                entity_fl_Approve.FuzzyType           = 1;
                                entity_fl_Approve.TemplateID          = int.Parse(fl_Approves[0].ToString());
                                entity_fl_Approve.CompanyID           = fl_Approves[1];
                                entity_fl_Approve.DeptIDCondition     = fl_Approves[6];
                                entity_fl_Approve.EmployeeIDCondition = fl_Approves[7];
                                entity_fl_Approve.IsGroupApprover     = bool.Parse(fl_Approves[8].ToString());
                                entity_fl_Approve.CreatedUser         = LoginInfo.UserID;
                                entity_fl_Approve.ModifiedUser        = LoginInfo.UserID;
                                entity_fl_Approve.ResetCreated();

                                db.fl_Approver.Add(entity_fl_Approve);
                                db.SaveChanges();
                            }
                        }
                    }
                    //}
                    //else
                    //{
                    //    Message = "同一次序必须选择相同的签核次序";
                    //}
                }
                catch
                {
                    Message = "Error";
                }
            }
            return(Message);
        }