Exemplo n.º 1
0
        private void saveFormData(Infobasis.Data.DataEntity.Vendor vendor)
        {
            vendor.Name            = tbxName.Text.Trim();
            vendor.FullName        = tbxFullName.Text.Trim();
            vendor.Location        = tbxLocation.Text.Trim();
            vendor.Code            = tbxCode.Text.Trim();
            vendor.BankAccount     = tbxBandAccount.Text.Trim();
            vendor.BankAccountName = tbxBandAccountName.Text.Trim();
            vendor.PaymentNum      = Change.ToInt(tbxPaymentNum.Text);
            vendor.ERPAccount      = tbxERPAccount.Text.Trim();
            vendor.ERPPassword     = tbxERPAccountPwd.Text.Trim();
            vendor.OpenERPAccount  = tbxOpenERPAccount.Checked;
            vendor.BrandName       = tbxBrand.Text.Trim();

            vendor.VendorStatus = (VendorStatus)Enum.Parse(typeof(VendorStatus), DropDownVendorStatus.SelectedValue);

            vendor.MainMaterialTypeName = DropDownMainMaterialType.SelectedText;

            if (Infobasis.Web.Util.Change.ToInt(DropDownMainMaterialType.SelectedValue) > 0)
            {
                vendor.MainMaterialTypeID = Infobasis.Web.Util.Change.ToInt(DropDownMainMaterialType.SelectedValue);
            }

            vendor.MaterialTypeName = DropDownMaterialType.SelectedText;

            if (Infobasis.Web.Util.Change.ToInt(DropDownMaterialType.SelectedValue) > 0)
            {
                vendor.MaterialTypeID = Infobasis.Web.Util.Change.ToInt(DropDownMaterialType.SelectedValue);
            }

            if (Infobasis.Web.Util.Change.ToInt(DropDownProvince.SelectedValue) > 0)
            {
                vendor.ProvinceID   = Infobasis.Web.Util.Change.ToInt(DropDownProvince.SelectedValue);
                vendor.ProvinceName = DropDownProvince.SelectedText;
            }

            vendor.Remark         = tbxRemark.Text;
            vendor.SpellCode      = ChinesePinyin.GetPinyin(vendor.Name);
            vendor.FirstSpellCode = ChinesePinyin.GetFirstPinyin(vendor.Name);
            vendor.LogoPicPath    = logoImg.ImageUrl;
            vendor.CompanySize    = DropDownCompanySize.SelectedText;
            vendor.DisplayOrder   = Change.ToInt(tbxDisplayOrder.Text);
            vendor.IsActive       = vendor.VendorStatus == VendorStatus.Qualified || vendor.VendorStatus == VendorStatus.Temporary ? true : false;
        }
Exemplo n.º 2
0
        private void SaveItem()
        {
            int id  = GetQueryIntValue("id");
            int pid = GetQueryIntValue("pid");

            if (id > 0 && pid > 0)
            {
                Infobasis.Data.DataEntity.City city = DB.Citys.Find(id);
                city.Name           = tbxName.Text.Trim();
                city.Code           = ChinesePinyin.GetFirstPinyin(city.Name);
                city.IsActive       = tbxIsActive.Checked;
                city.DisplayOrder   = Change.ToInt(tbxDisplayOrder.Text);
                city.CreateDatetime = DateTime.Now;
            }
            else if (pid > 0)
            {
                Infobasis.Data.DataEntity.City item = new Infobasis.Data.DataEntity.City();
                item.ProvinceID         = pid;
                item.Name               = tbxName.Text.Trim();
                item.Code               = ChinesePinyin.GetFirstPinyin(item.Name);
                item.IsActive           = tbxIsActive.Checked;
                item.DisplayOrder       = Change.ToInt(tbxDisplayOrder.Text);
                item.LastUpdateDatetime = DateTime.Now;

                DB.Citys.Add(item);
            }
            else
            {
                Province item = new Province();
                item.Name               = tbxName.Text.Trim();
                item.Code               = ChinesePinyin.GetFirstPinyin(item.Name);
                item.IsActive           = tbxIsActive.Checked;
                item.LastUpdateDatetime = DateTime.Now;
                item.DisplayOrder       = Change.ToInt(tbxDisplayOrder.Text);
                DB.Provinces.Add(item);
            }
            DB.SaveChanges();
        }
Exemplo n.º 3
0
        private void SaveItem()
        {
            int companyID = UserInfo.Current.CompanyID;

            Infobasis.Data.DataEntity.User item = new Infobasis.Data.DataEntity.User();
            item.Name              = tbxName.Text.Trim();
            item.Password          = PasswordUtil.CreateDbPassword(tbxPassword.Text.Trim());
            item.ChineseName       = tbxRealName.Text.Trim();
            item.EmployeeSpellCode = ChinesePinyin.GetPinyin(tbxRealName.Text.Trim());
            item.FirstSpellCode    = ChinesePinyin.GetFirstPinyin(tbxRealName.Text.Trim());
            item.Email             = tbxEmail.Text.Trim();
            item.Remark            = tbxRemark.Text.Trim();
            item.Enabled           = cbxEnabled.Checked;
            item.CreateDatetime    = DateTime.Now;
            item.CompanyID         = companyID;
            item.UserType          = UserType.Employee;

            // 添加所有角色
            if (ddbRoles.Values != null)
            {
                item.UserPermissionRoles = new List <UserPermissionRole>();
                foreach (var roleID in ddbRoles.Values)
                {
                    item.UserPermissionRoles.Add(new UserPermissionRole()
                    {
                        UserID           = item.ID,
                        CompanyID        = companyID,
                        PermissionRoleID = Change.ToInt(roleID),
                        CreateDatetime   = DateTime.Now
                    });
                }
            }

            DB.Users.Add(item);
            DB.SaveChanges();
        }
Exemplo n.º 4
0
        private void SaveItem()
        {
            int    userID   = UserInfo.Current.ID;
            string userName = UserInfo.Current.ChineseName;

            int id = GetQueryIntValue("id");

            if (id > 0)
            {
                Infobasis.Data.DataEntity.Material material = DB.Materials.Find(id);
                material.Name      = tbxName.Text.Trim();
                material.Code      = tbxCode.Text.Trim();
                material.IsActive  = tbxIsActive.Checked;
                material.BrandName = tbxBrand.Text;
                if (Infobasis.Web.Util.Change.ToInt(tbxBrandHidden.Text) > 0)
                {
                    material.BrandID = Infobasis.Web.Util.Change.ToInt(tbxBrandHidden.Text);
                }

                material.Model    = tbxModel.Text;
                material.Spec     = tbxSpec.Text;
                material.UnitName = DropDownUnit.SelectedText;
                if (Infobasis.Web.Util.Change.ToInt(DropDownUnit.SelectedValue) > 0)
                {
                    material.UnitID = Infobasis.Web.Util.Change.ToInt(DropDownUnit.SelectedValue);
                }

                material.PurchasePrice         = Infobasis.Web.Util.Change.ToDecimal(tbxPurchasePrice.Text);
                material.SalePrice             = Infobasis.Web.Util.Change.ToDecimal(tbxSalePrice.Text);
                material.NoSalePrice           = tbxNoSalePrice.Checked;
                material.ReturnFactor          = Infobasis.Web.Util.Change.ToDecimal(tbxReturnFactor.Text);
                material.UpgradePrice          = Infobasis.Web.Util.Change.ToDecimal(tbxUpgradePrice.Text);
                material.CustomizationTypeName = DropDownCustomizationType.SelectedText;

                if (Infobasis.Web.Util.Change.ToInt(DropDownCustomizationType.SelectedValue) > 0)
                {
                    material.CustomizationTypeID = Infobasis.Web.Util.Change.ToInt(DropDownCustomizationType.SelectedValue);
                }

                material.EarningFactor        = Infobasis.Web.Util.Change.ToDecimal(tbxEarningFactor.Text);
                material.MainMaterialTypeName = DropDownMainMaterialType.SelectedText;

                if (Infobasis.Web.Util.Change.ToInt(DropDownMainMaterialType.SelectedValue) > 0)
                {
                    material.MainMaterialTypeID = Infobasis.Web.Util.Change.ToInt(DropDownMainMaterialType.SelectedValue);
                }

                material.MaterialTypeName = DropDownMaterialType.SelectedText;

                if (Infobasis.Web.Util.Change.ToInt(DropDownMaterialType.SelectedValue) > 0)
                {
                    material.MaterialTypeID = Infobasis.Web.Util.Change.ToInt(DropDownMaterialType.SelectedValue);
                }

                if (Infobasis.Web.Util.Change.ToInt(DropDownProvince.SelectedValue) > 0)
                {
                    material.ProvinceID   = Infobasis.Web.Util.Change.ToInt(DropDownProvince.SelectedValue);
                    material.ProvinceName = DropDownProvince.SelectedText;
                }


                material.BudgetTypeIDs   = string.Join(",", DropDownBoxBudgetType.Values);
                material.BudgetTypeNames = string.Join(",", CheckBoxListBudgetType.SelectedItemArray.Where(item => item.Selected).Select(item => item.Text).ToArray());

                material.RoomTypeIDs   = string.Join(",", DropDownBoxRoomType.Values);
                material.RoomTypeNames = string.Join(",", CheckBoxListRoomType.SelectedItemArray.Where(item => item.Selected).Select(item => item.Text).ToArray());

                material.Remark         = tbxRemark.Text;
                material.SpellCode      = ChinesePinyin.GetPinyin(material.Name);
                material.FirstSpellCode = ChinesePinyin.GetFirstPinyin(material.Name);
                material.PicPath        = materialImg.ImageUrl;

                if (Infobasis.Web.Util.Change.ToInt(ddbVendor.Value) > 0)
                {
                    material.VendorID   = Infobasis.Web.Util.Change.ToInt(ddbVendor.Value);
                    material.VendorName = ddbVendor.Text;
                }

                material.LastUpdateDatetime = DateTime.Now;
                material.LastUpdateByID     = userID;
                material.LastUpdateByName   = userName;
            }
            else
            {
                Infobasis.Data.DataEntity.Material material = new Infobasis.Data.DataEntity.Material();
                material.Name      = tbxName.Text.Trim();
                material.Code      = tbxCode.Text.Trim();
                material.IsActive  = tbxIsActive.Checked;
                material.BrandName = tbxBrand.Text;
                if (Infobasis.Web.Util.Change.ToInt(tbxBrandHidden.Text) > 0)
                {
                    material.BrandID = Infobasis.Web.Util.Change.ToInt(tbxBrandHidden.Text);
                }

                material.Model    = tbxModel.Text;
                material.Spec     = tbxSpec.Text;
                material.UnitName = DropDownUnit.SelectedText;
                if (Infobasis.Web.Util.Change.ToInt(DropDownUnit.SelectedValue) > 0)
                {
                    material.UnitID = Infobasis.Web.Util.Change.ToInt(DropDownUnit.SelectedValue);
                }

                material.PurchasePrice         = Infobasis.Web.Util.Change.ToDecimal(tbxPurchasePrice.Text);
                material.SalePrice             = Infobasis.Web.Util.Change.ToDecimal(tbxSalePrice.Text);
                material.NoSalePrice           = tbxNoSalePrice.Checked;
                material.ReturnFactor          = Infobasis.Web.Util.Change.ToDecimal(tbxReturnFactor.Text);
                material.UpgradePrice          = Infobasis.Web.Util.Change.ToDecimal(tbxUpgradePrice.Text);
                material.CustomizationTypeName = DropDownCustomizationType.SelectedText;

                if (Infobasis.Web.Util.Change.ToInt(DropDownCustomizationType.SelectedValue) > 0)
                {
                    material.CustomizationTypeID = Infobasis.Web.Util.Change.ToInt(DropDownCustomizationType.SelectedValue);
                }

                material.EarningFactor        = Infobasis.Web.Util.Change.ToDecimal(tbxEarningFactor.Text);
                material.MainMaterialTypeName = DropDownMainMaterialType.SelectedText;

                if (Infobasis.Web.Util.Change.ToInt(DropDownMainMaterialType.SelectedValue) > 0)
                {
                    material.MainMaterialTypeID = Infobasis.Web.Util.Change.ToInt(DropDownMainMaterialType.SelectedValue);
                }

                material.MaterialTypeName = DropDownMaterialType.SelectedText;

                if (Infobasis.Web.Util.Change.ToInt(DropDownMaterialType.SelectedValue) > 0)
                {
                    material.MaterialTypeID = Infobasis.Web.Util.Change.ToInt(DropDownMaterialType.SelectedValue);
                }

                if (Infobasis.Web.Util.Change.ToInt(DropDownProvince.SelectedValue) > 0)
                {
                    material.ProvinceID   = Infobasis.Web.Util.Change.ToInt(DropDownProvince.SelectedValue);
                    material.ProvinceName = DropDownProvince.SelectedText;
                }

                material.BudgetTypeIDs   = string.Join(",", DropDownBoxBudgetType.Values);
                material.BudgetTypeNames = string.Join(",", CheckBoxListBudgetType.SelectedItemArray.Where(item => item.Selected).Select(item => item.Text).ToArray());

                material.RoomTypeIDs   = string.Join(",", DropDownBoxRoomType.Values);
                material.RoomTypeNames = string.Join(",", CheckBoxListRoomType.SelectedItemArray.Where(item => item.Selected).Select(item => item.Text).ToArray());

                material.Remark         = tbxRemark.Text;
                material.SpellCode      = ChinesePinyin.GetPinyin(material.Name);
                material.FirstSpellCode = ChinesePinyin.GetFirstPinyin(material.Name);
                material.PicPath        = materialImg.ImageUrl;

                if (Infobasis.Web.Util.Change.ToInt(ddbVendor.Value) > 0)
                {
                    material.VendorID   = Infobasis.Web.Util.Change.ToInt(ddbVendor.Value);
                    material.VendorName = ddbVendor.Text;
                }

                material.CreateDatetime = DateTime.Now;
                material.CreateByID     = userID;
                material.CreateByName   = userName;
                DB.Materials.Add(material);
            }
            if (!string.IsNullOrEmpty(tbxBrand.Text))
            {
                if (!DB.Brands.Where(item => item.Name == tbxBrand.Text.Trim()).Any())
                {
                    Infobasis.Data.DataEntity.Brand brand = new Infobasis.Data.DataEntity.Brand();
                    brand.Code           = GenerateNum("brand");
                    brand.Name           = tbxBrand.Text.Trim();
                    brand.SpellCode      = Infobasis.Web.Util.ChinesePinyin.GetPinyin(brand.Name);
                    brand.FirstSpellCode = Infobasis.Web.Util.ChinesePinyin.GetFirstPinyin(brand.Name);
                    brand.IsActive       = true;
                    brand.CreateDatetime = DateTime.Now;

                    DB.Brands.Add(brand);
                }
            }
            DB.SaveChanges();
        }
Exemplo n.º 5
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            string tel = tbxTel.Text.Trim();

            if (string.IsNullOrEmpty(tel))
            {
                Alert.ShowInTop("请输入联系电话");
                return;
            }
            if (DB.Clients.Where(item => item.Tel == tel).Any())
            {
                Alert.ShowInTop("客户已经存在");
                return;
            }
            btnSave.Enabled = false;
            Client client = new Client()
            {
                Name              = tbxProjectName.Text.Trim(),
                SpellCode         = ChinesePinyin.GetPinyin(tbxProjectName.Text.Trim()),
                FirstSpellCode    = ChinesePinyin.GetFirstPinyin(tbxProjectName.Text.Trim()),
                ProjectNo         = GenerateNum("C"),
                Gender            = ddlGender.SelectedValue,
                Email             = tbxEmail.Text,
                Tel               = tel,
                QQ                = tbxQQ.Text,
                WeChat            = tbxWeChat.Text,
                HousesName        = tbxHousesName.Text,
                HouseInfoID       = Infobasis.Web.Util.Change.ToInt(tbxHouseInfoID.Text.Trim()),
                SalesDeptID       = 0,
                BuiltupArea       = Infobasis.Web.Util.Change.ToDouble(tbxBuiltupArea.Text),
                Budget            = Infobasis.Web.Util.Change.ToDouble(tbxBudget.Text),
                ClientFromName    = DropDownClientFrom.SelectedValue,
                DecorationAddress = tbxDecorationAddress.Text,
                PackageName       = DropDownPackageName.SelectedValue,
                //ProvinceID = Infobasis.Web.Util.Change.ToInt(DropDownProvince.SelectedValue),
                DecorationStyleID   = Infobasis.Web.Util.Change.ToInt(DropDownDecorationStype.SelectedValue),
                DecorationStyleName = DropDownDecorationStype.SelectedText,

                DecorationTypeID   = Infobasis.Web.Util.Change.ToInt(DropDownDecorationType.SelectedValue),
                DecorationTypeName = DropDownDecorationType.SelectedText,

                HouseStructTypeID   = Infobasis.Web.Util.Change.ToInt(DropDownHouseType.SelectedValue),
                HouseStructTypeName = DropDownHouseType.SelectedText,

                DecorationColorID   = Infobasis.Web.Util.Change.ToInt(DropDownDecorationColor.SelectedValue),
                DecorationColorName = DropDownDecorationColor.SelectedText,

                //HouseUseTypeName = DropDownHouseUseType.SelectedValue,
                PlanStartDate = Infobasis.Web.Util.Change.ToDateTime(dpPlanStartDate.Text),
                PlanEndDate   = Infobasis.Web.Util.Change.ToDateTime(dpPlanEndDate.Text),

                ClientProjectStatus           = ClientProjectStatus.None,
                ClientProjectStatusUpdateDate = DateTime.Now,
                ClientTraceStatusID           = Infobasis.Web.Util.Change.ToInt(DropDownClientStatus.SelectedValue),
                ClientTraceStatusName         = DropDownClientStatus.SelectedText,

                DesignStatus   = DesignStatus.None,
                Remark         = tbxRemark.Text,
                CreateByID     = UserInfo.Current.ID,
                CreateByName   = UserInfo.Current.ChineseName,
                CreateDatetime = DateTime.Now
            };

            if (ddbDesignerDept.Value != null && Infobasis.Web.Util.Change.ToInt(ddbDesignerDept.Value) > 0)
            {
                client.DesignDeptID   = Infobasis.Web.Util.Change.ToInt(ddbDesignerDept.Value);
                client.DesignDeptName = ddbDesignerDept.Text;

                if (ddbDesigner.Value != null && Infobasis.Web.Util.Change.ToInt(ddbDesigner.Value) > 0)
                {
                    client.DesignUserID = Infobasis.Web.Util.Change.ToInt(ddbDesigner.Value);
                    if (client.DesignUserID > 0)
                    {
                        Infobasis.Data.DataEntity.User designUser = DB.Users.Find(client.DesignUserID);
                        client.DesignUserDisplayName    = designUser != null ? designUser.ChineseName : "";
                        client.AssignToDesignerDatetime = DateTime.Now;
                    }
                }
                else
                {
                    client.DesignUserID          = null;
                    client.DesignUserDisplayName = "";
                }
            }

            if (DropDownProvince.SelectedValue != null)
            {
                client.ProvinceID   = Infobasis.Web.Util.Change.ToInt(DropDownProvince.SelectedValue);
                client.ProvinceName = DropDownProvince.SelectedText;
            }
            else
            {
                client.ProvinceID   = null;
                client.ProvinceName = null;
            }

            if (DropDownBoxClientNeed.Values != null)
            {
                client.ClientNeedIDs  = string.Join(",", DropDownBoxClientNeed.Values);
                client.ClientNeedName = string.Join(",", DropDownBoxClientNeed.Values);
            }
            else
            {
                client.ClientNeedIDs  = "";
                client.ClientNeedName = "";
            }

            Infobasis.Data.DataEntity.ClientTrace clientTrace = new Infobasis.Data.DataEntity.ClientTrace()
            {
                ClientID        = client.ID,
                CreateByID      = UserInfo.Current.ID,
                UserID          = UserInfo.Current.ID,
                UserDisplayName = UserInfo.Current.ChineseName,
                TraceDesc       = client.ToString()
            };
            client.ClientTraces = new List <Infobasis.Data.DataEntity.ClientTrace>();
            client.ClientTraces.Add(clientTrace);
            DB.Clients.Add(client);
            if (SaveChanges())
            {
                ShowNotify("保存成功!");
                PageContext.RegisterStartupScript("refreshTopWindow();");
            }
            btnSave.Enabled = true;
        }
Exemplo n.º 6
0
        private void SaveItem()
        {
            int id = GetQueryIntValue("id");
            List <EmployeeAdjustItem> adjustItems = new List <EmployeeAdjustItem>();
            int companyID = UserInfo.Current.CompanyID;

            Infobasis.Data.DataEntity.User item = null;
            if (id == 0)
            {
                item = new Infobasis.Data.DataEntity.User();
                if (string.IsNullOrEmpty(tbxUserName.Text))
                {
                    item.Name = tbxTel.Text.Trim();
                }

                if (string.IsNullOrEmpty(tbxPassWord.Text))
                {
                    item.Password = PasswordUtil.CreateDbPassword(tbxPassWord.Text.Trim());
                }
                item.CreateDatetime = DateTime.Now;
                item.HireStatus     = 0;

                adjustItems.Add(EmployeeAdjustItem.Create);
            }
            else
            {
                item = DB.Users.Include("UserPermissionRoles").Where(u => u.ID == id).FirstOrDefault();
                item.LastUpdateByID     = UserInfo.Current.ID;
                item.LastUpdateByName   = UserInfo.Current.ChineseName;
                item.LastUpdateDatetime = DateTime.Now;

                if (item.EmploymentType != (ddlEmploymentType.SelectedValue != null ? Change.ToInt(ddlEmploymentType.SelectedValue) : 1))
                {
                    adjustItems.Add(EmployeeAdjustItem.EmploymentType);
                }

                if (Change.ValueIsChanged(item.ReportsTo, Change.ToInt(tbxReportToID.Text)))
                {
                    adjustItems.Add(EmployeeAdjustItem.ReportsTo);
                }

                if (Change.ValueIsChanged(item.JobID, Change.ToInt(ddbTitles.Value)))
                {
                    adjustItems.Add(EmployeeAdjustItem.Job);
                }

                if (Change.ValueIsChanged(item.DepartmentID, Change.ToInt(ddbDept.Value)))
                {
                    adjustItems.Add(EmployeeAdjustItem.Department);
                }

                if (item.OnBoardDate != Change.ToDateTime(tbxOnBoardDate.Text))
                {
                    adjustItems.Add(EmployeeAdjustItem.OnBoard);
                }
            }

            item.ChineseName       = tbxName.Text.Trim();
            item.EmployeeSpellCode = ChinesePinyin.GetFirstPinyin(tbxName.Text.Trim());
            item.EnglishName       = ChinesePinyin.GetPinyin(tbxName.Text.Trim());
            item.EmployeeCode      = tbxEmployeeNum.Text.Trim();
            item.Email             = tbxEmail.Text.Trim();
            item.Remark            = tbxRemark.Text.Trim();
            item.Enabled           = true;
            item.CompanyID         = companyID;
            item.UserType          = UserType.Employee;
            item.Gender            = ddlGender.SelectedValue;
            item.DateOfBirth       = Change.ToDateTime(dpBirthDay.Text);

            item.EmployeeCode   = tbxEmployeeNum.Text.Trim();
            item.EmploymentType = ddlEmploymentType.SelectedValue != null?Change.ToInt(ddlEmploymentType.SelectedValue) : 1;

            item.MaritalStatus = ddlMarriage.SelectedValue;
            item.Ethnic        = ddlNation.SelectedValue;
            item.OnBoardDate   = Change.ToDateTime(tbxOnBoardDate.Text);

            if (tbxBecomeRegularDate.Text != null)
            {
                item.BecomeRegularDate = Change.ToDateTime(tbxBecomeRegularDate.Text);
            }

            if (tbxReportToID.Text != null && Change.ToInt(tbxReportToID.Text) > 0)
            {
                item.ReportsTo = Change.ToInt(tbxReportToID.Text);
            }

            item.IDType       = ddlCertificates.SelectedValue;
            item.IDNumber     = tbxIDCardEdit.Text;
            item.Education    = ddlEducation.Text;
            item.NativePlace  = ddlNativePlace.SelectedValue;
            item.MailAddress  = tbxNativePlace.Text;
            item.MobileNumber = tbxTel.Text.Trim();

            // 添加角色
            int[] newEntityIDs = ddbRoles.Values != null?ddbRoles.Values.Select(r => Convert.ToInt32(r)).ToArray() : new int[1];

            if (item.UserPermissionRoles == null)
            {
                item.UserPermissionRoles = new List <UserPermissionRole>();
            }

            ICollection <UserPermissionRole> existEntities = DB.UserPermissionRoles.Where(up => up.UserID == item.ID).ToList();

            int[] tobeAdded   = newEntityIDs.Except(existEntities.Select(x => x.PermissionRoleID)).ToArray();
            int[] tobeRemoved = existEntities.Select(x => x.PermissionRoleID).Except(newEntityIDs).ToArray();

            foreach (int pid in tobeAdded)
            {
                UserPermissionRole newEntity = new UserPermissionRole()
                {
                    CompanyID        = companyID,
                    UserID           = item.ID,
                    PermissionRoleID = pid,
                    CreateDatetime   = DateTime.Now
                };
                //moduleRoleRepository.Insert(newEntity, out msg, false);
                item.UserPermissionRoles.Add(newEntity);
            }

            foreach (int pid in tobeRemoved)
            {
                var removeEntity = DB.UserPermissionRoles.Find(pid);
                item.UserPermissionRoles.Remove(removeEntity);
            }

            if (tobeAdded.Length > 0 || tobeRemoved.Length > 0)
            {
                adjustItems.Add(EmployeeAdjustItem.UserPermissionRole);
            }

            // 添加所有部门
            if (ddbDept.Value != null && Change.ToInt(ddbDept.Value) > 0)
            {
                item.DepartmentID = Change.ToInt(ddbDept.Value);
            }

            // 添加所有职称
            if (ddbTitles.Values != null && Change.ToInt(ddbTitles.Value) > 0)
            {
                item.JobID = Change.ToInt(ddbTitles.Value);
            }

            if (id == 0)
            {
                DB.Users.Add(item);
            }

            string adjustItemNames = "";

            if (adjustItems.Count == 0)
            {
                adjustItems.Add(EmployeeAdjustItem.Others);
            }

            foreach (var adjustItem in adjustItems)
            {
                adjustItemNames += ", " + EnumHelper.GetDescription(adjustItem);
            }

            EmployeeAdjust eeAdjust = new EmployeeAdjust()
            {
                UserID         = item.ID,
                AdjustItemName = adjustItemNames,
                AdjustDate     = DateTime.Now,
                AllChangeData  = item.ToString(),
                isAdjusted     = true,
                CreateByID     = UserInfo.Current.ID,
                CreateByName   = UserInfo.Current.ChineseName,
                CreateDatetime = DateTime.Now
            };

            DB.EmployeeAdjusts.Add(eeAdjust);

            SaveChanges();
        }