Exemple #1
0
        /// <summary>
        /// 保存兼职机构
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="type"></param>
        /// <param name="unitID"></param>
        /// <returns></returns>
        public static bool SaveSideline(B_WORKER_ORGANIZATION entity)
        {
            using (MainDataContext dbContext = new MainDataContext())
            {
                using (MainDataContext dsContext = new MainDataContext(AppConfig.ConnectionStringDispatch))
                {
                    if (entity.ID == 0)  //添加
                    {
                        var  list  = from a in dbContext.B_WORKER_ORGANIZATION select a.ID;
                        long total = list.LongCount();
                        if (total == 0)
                        {
                            entity.ID = 1;
                        }
                        else
                        {
                            entity.ID = dbContext.B_WORKER_ORGANIZATION.Max(a => a.ID) + 1;
                        }

                        dbContext.B_WORKER_ORGANIZATION.InsertOnSubmit(entity);
                    }
                    else
                    {
                        var model = dbContext.B_WORKER_ORGANIZATION.FirstOrDefault(b => b.ID == entity.ID);

                        //机构修改,更新B_WORKER_ROLE和Tperson
                        if (model.OrgID != entity.OrgID)
                        {
                            List <B_WORKER_ROLE> list = dbContext.B_WORKER_ROLE.Where(t => t.WorkerID == model.WorkerID &&
                                                                                      t.OrgID == model.OrgID).ToList();

                            foreach (B_WORKER_ROLE wr in list)
                            {
                                wr.OrgID = entity.OrgID;

                                if (!string.IsNullOrEmpty(wr.TPerson编码.Trim()))
                                {
                                    var tp = dsContext.TPerson.FirstOrDefault(t => t.编码 == wr.TPerson编码);

                                    B_ORGANIZATION unit = Organize.GetUnit(entity.OrgID);

                                    tp.单位编码 = unit.Type == (int)OrgType.Branch ? unit.编码 : "-1";
                                    tp.分站编码 = unit.Type == (int)OrgType.Station ? unit.编码 : AppConfig.GetStringConfigValue("VirtualCode");
                                }
                            }
                        }

                        model.OrgID    = entity.OrgID;
                        model.WorkerID = entity.WorkerID;
                        model.ParentID = entity.ParentID;
                        model.PostID   = entity.PostID;
                        model.Remark   = entity.Remark;
                        model.Type     = entity.Type;
                    }

                    dbContext.SubmitChanges();
                    dsContext.SubmitChanges();
                    return(true);
                }
            }
        }
Exemple #2
0
        public static bool SaveWorkerRole(B_WORKER_ROLE entity)
        {
            using (MainDataContext dbContext = new MainDataContext())
            {
                using (MainDataContext dsContext = new MainDataContext(AppConfig.ConnectionStringDispatch))
                {
                    try
                    {
                        //同步Tperson
                        if (!string.IsNullOrEmpty(entity.EmpNo))
                        {
                            B_WORKER       worker = GetWorkerById(entity.WorkerID);
                            B_ORGANIZATION unit   = Organize.GetUnit(entity.OrgID);

                            if (dsContext.TPerson.Count(t => t.编码 == entity.TPerson编码) == 0)
                            {
                                //string empNo = GetCoding();
                                IApplicationContext ctx     = ContextRegistry.GetContext();
                                IEncrypt            encrypt = ctx["Encrypt"] as IEncrypt;

                                TPerson person = new TPerson();
                                person.编码    = entity.TPerson编码;
                                person.单位编码  = unit.Type == (int)OrgType.Branch ? unit.编码 : "-1";
                                person.通话号码  = worker.Tel ?? string.Empty;
                                person.短信号码  = worker.Mobile ?? string.Empty;
                                person.分站编码  = unit.Type == (int)OrgType.Station ? unit.编码 : AppConfig.GetStringConfigValue("VirtualCode");
                                person.类型编码  = entity.RoleID;
                                person.姓名    = worker.Name;
                                person.工号    = entity.EmpNo;
                                person.口令    = new HashEncrypt().DESEncrypt(encrypt.Decrypt(worker.PassWord), "");
                                person.次操作时间 = DateTime.Now;
                                person.顺序号   = int.Parse(entity.TPerson编码);
                                person.是否有效  = true;

                                dsContext.TPerson.InsertOnSubmit(person);
                            }
                            else
                            {
                                var tp = dsContext.TPerson.FirstOrDefault(t => t.编码 == entity.TPerson编码);

                                tp.单位编码 = unit.Type == (int)OrgType.Branch ? unit.编码 : "-1";
                                tp.分站编码 = unit.Type == (int)OrgType.Station ? unit.编码 : AppConfig.GetStringConfigValue("VirtualCode");
                                tp.类型编码 = entity.RoleID;
                                tp.工号   = entity.EmpNo;
                            }
                        }

                        //人员
                        if (entity.ID == 0)
                        {
                            var  list  = from a in dbContext.B_WORKER_ROLE select a.ID;
                            long total = list.LongCount();
                            if (total == 0)
                            {
                                entity.ID = 1;
                            }
                            else
                            {
                                entity.ID = dbContext.B_WORKER_ROLE.Max(a => a.ID) + 1;
                            }

                            entity.EmpNo     = entity.EmpNo ?? string.Empty;
                            entity.TPerson编码 = entity.TPerson编码 ?? string.Empty;

                            dbContext.B_WORKER_ROLE.InsertOnSubmit(entity);
                        }
                        else
                        {
                            var model = dbContext.B_WORKER_ROLE.FirstOrDefault(b => b.ID == entity.ID);

                            model.OrgID     = entity.OrgID;
                            model.WorkerID  = entity.WorkerID;
                            model.RoleID    = entity.RoleID;
                            model.EmpNo     = entity.EmpNo ?? string.Empty;
                            model.ID        = entity.ID;
                            model.TPerson编码 = entity.TPerson编码 ?? string.Empty;
                        }

                        dbContext.SubmitChanges();
                        dsContext.SubmitChanges();
                        return(true);
                    }
                    catch (Exception ex)
                    {
                        Log4Net.LogError("SaveWorkerRole", ex.ToString());
                        return(false);
                    }
                }
            }
        }