Esempio n. 1
0
        protected void Grid1_RowCommand(object sender, GridCommandEventArgs e)
        {
            int userID = GetSelectedDataKeyID(Grid1);

            Infobasis.Data.DataEntity.User user = DB.Users.Where(item => item.ID == userID).FirstOrDefault();
            string userName = user.Name;

            if (e.CommandName == "Delete")
            {
                // 在操作之前进行权限检查

                if (user.IsClientAdmin)
                {
                    Alert.ShowInTop("不能删除默认的系统管理员(admin)!");
                }
                else
                {
                    //DB.Users.Where(u => u.ID == userID).Delete();
                    if (!_repository.Delete(user, out msg))
                    {
                        Alert.ShowInTop("删除失败!");
                    }

                    BindGrid();
                }
            }
        }
Esempio n. 2
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            string inputUserNum = tbxEmployeeNum.Text.Trim();
            int    id           = GetQueryIntValue("id");

            Infobasis.Data.DataEntity.User user = DB.Users.Where(u => u.EmployeeCode == inputUserNum && u.ID != id).FirstOrDefault();

            if (user != null)
            {
                Alert.Show("用户员工编号 " + inputUserNum + " 已经存在!");
                return;
            }

            string inputUserName = tbxName.Text.Trim();

            Infobasis.Data.DataEntity.User userToName = DB.Users.Where(u => u.Name == inputUserName && u.ID != id).FirstOrDefault();

            if (userToName != null)
            {
                Alert.Show("用户 " + inputUserName + " 已经存在!");
                return;
            }

            SaveItem();
            BindGridAdjust();
            ShowNotify("保存成功!");

            PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference());
        }
        protected void btnSaveClose_Click(object sender, EventArgs e)
        {
            //PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference());
            int eeID = GetQueryIntValue("id");

            Infobasis.Data.DataEntity.User user = DB.Users
                                                  .Where(u => u.ID == eeID).FirstOrDefault();
            if (user == null)
            {
                // 参数错误,首先弹出Alert对话框然后关闭弹出窗口
                Alert.Show("参数错误!", String.Empty, ActiveWindow.GetHideReference());
                return;
            }

            int    newHireStatus  = Change.ToInt(DropDownChangeHireStatus.SelectedValue);
            string adjustItemName = "";

            if (user.HireStatus.HasValue && user.HireStatus.Value != newHireStatus)
            {
                user.HireStatus = newHireStatus;
                if (!string.IsNullOrEmpty(tbxRemark.Text))
                {
                    user.Remark = user.Remark + "," + tbxRemark.Text;
                }

                if (newHireStatus == 0)
                {
                    adjustItemName = "再入职";
                }
                else if (newHireStatus == 1)
                {
                    adjustItemName = "离职";
                }

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

                DB.EmployeeAdjusts.Add(eeAdjust);
            }

            SaveChanges();
            ShowNotify("修改成功");
            //PageContext.RegisterStartupScript(ActiveWindow.GetHideRefreshReference());
            PageContext.RegisterStartupScript("refreshTopWindow();" + ActiveWindow.GetHideRefreshReference());
        }
Esempio n. 4
0
        protected void btnSaveClose_Click(object sender, EventArgs e)
        {
            string inputUserName = tbxName.Text.Trim();

            Infobasis.Data.DataEntity.User user = DB.Users.Where(u => u.Name == inputUserName).FirstOrDefault();

            if (user != null)
            {
                Alert.Show("用户 " + inputUserName + " 已经存在!");
                return;
            }

            SaveItem();

            PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference());
        }
        private void LoadData()
        {
            //btnClose.OnClientClick = ActiveWindow.GetHideReference();
            int eeID = GetQueryIntValue("id");

            Infobasis.Data.DataEntity.User user = DB.Users
                                                  .Where(u => u.ID == eeID).FirstOrDefault();
            if (user == null)
            {
                // 参数错误,首先弹出Alert对话框然后关闭弹出窗口
                Alert.Show("参数错误!", String.Empty, ActiveWindow.GetHideReference());
                return;
            }
            labName.Text   = user.ChineseName;
            labEECode.Text = user.EmployeeCode;
            DropDownChangeHireStatus.SelectedValue = user.HireStatus.HasValue ? user.HireStatus.Value.ToString() : "0";
        }
Esempio n. 6
0
        // 超级管理员(admin)不可编辑,也不会检索出来
        protected void Grid1_PreRowDataBound(object sender, FineUIPro.GridPreRowEventArgs e)
        {
            Infobasis.Data.DataEntity.User user = e.DataItem as Infobasis.Data.DataEntity.User;

            FineUIPro.LinkButtonField deleteField = Grid1.FindColumn("deleteField") as FineUIPro.LinkButtonField;

            // 不能删除超级管理员
            if (user.IsClientAdmin)
            {
                deleteField.Enabled = false;
                deleteField.ToolTip = "不能删除管理员!";
            }
            else
            {
                deleteField.Enabled = true;
                deleteField.ToolTip = "删除";
            }
        }
Esempio n. 7
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();
        }
Esempio n. 8
0
        protected void materialImgUpload_FileSelected(object sender, EventArgs e)
        {
            if (materialImgUpload.HasFile)
            {
                int companyID = UserInfo.Current.CompanyID;
                int userID    = UserInfo.Current.ID;

                string fileOriginalName = materialImgUpload.ShortFileName;

                if (!ValidateFileType(fileOriginalName))
                {
                    ShowNotify("无效的文件类型!");
                    return;
                }

                string uploadPath = Global.UploadFolderPath;
                if (uploadPath.StartsWith("~") || uploadPath.StartsWith(".")) //相对路径
                {
                    uploadPath = HttpContext.Current.Server.MapPath(uploadPath + "/images/material/" + companyID.ToString());
                }
                else
                {
                    uploadPath = uploadPath + "/images/material/" + companyID;
                }

                string originalFolderPath  = Path.Combine(uploadPath, DateTime.Now.ToString("yyyyMM") + "/original");
                string thumbnailFolderPath = Path.Combine(uploadPath, DateTime.Now.ToString("yyyyMM") + "/thumbnail");

                bool folderExists = Directory.Exists(originalFolderPath);
                if (!folderExists)
                {
                    Directory.CreateDirectory(originalFolderPath);
                }

                folderExists = Directory.Exists(thumbnailFolderPath);
                if (!folderExists)
                {
                    Directory.CreateDirectory(thumbnailFolderPath);
                }

                string fileType             = fileOriginalName.Substring(fileOriginalName.LastIndexOf("."));
                string fileName             = DateTime.Now.Ticks.ToString();
                string fileOriginalSavePath = Path.Combine(originalFolderPath, fileName + fileType);

                materialImgUpload.SaveAs(fileOriginalSavePath);

                System.Drawing.Image originalImage = Infobasis.Web.Util.StreamHelper.ImagePath2Img(fileOriginalSavePath);
                string fileThumbnailSavePath       = Path.Combine(thumbnailFolderPath, fileName + fileType);
                System.Drawing.Image newImage      = ImageHelper.GetThumbNailImage(originalImage, 160, 160);
                newImage.Save(fileThumbnailSavePath);

                string savedPath = Global.UploadFolderVirualPath + "/images/material/" + companyID.ToString() + "/" + DateTime.Now.ToString("yyyyMM") + "/thumbnail/" + fileName + fileType;
                Infobasis.Data.DataEntity.User user = DB.Users.Find(userID);
                user.UserPortraitPath = savedPath;
                DB.SaveChanges();

                materialImg.ImageUrl = savedPath;

                // 清空文件上传组件(上传后要记着清空,否则点击提交表单时会再次上传!!)
                materialImgUpload.Reset();
            }
        }
Esempio n. 9
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;
        }
Esempio n. 10
0
        private void LoadData()
        {
            //btnClose.OnClientClick = ActiveWindow.GetHideReference();
            //btnClose.OnClientClick = "parent.removeActiveTab();";

            int id = GetQueryIntValue("id");

            if (id > 0)
            {
                Infobasis.Data.DataEntity.User user = DB.Users.Include("Department")
                                                      .Include("ReportsToUser")
                                                      .Include("JobRole")
                                                      .Include("UserPermissionRoles")
                                                      .Where(d => d.ID == id).FirstOrDefault();
                if (user != null)
                {
                    tbxName.Text            = user.ChineseName;
                    ddlGender.SelectedValue = user.Gender;
                    //ddlGender.Text = user.Gender;
                    tbxRemark.Text                  = user.Remark;
                    dpBirthDay.Text                 = user.DateOfBirth.ToString();
                    tbxTel.Text                     = user.MobileNumber;
                    tbxEmail.Text                   = user.Email;
                    tbxEmployeeNum.Text             = user.EmployeeCode;
                    ddlEmploymentType.SelectedValue = user.EmploymentType.ToString();

                    if (!string.IsNullOrEmpty(user.UserPortraitPath))
                    {
                        imgUserPortal.ImageUrl        = user.UserPortraitPath;
                        userPortraitUpload.ButtonText = "修改头像";
                    }
                    else
                    {
                        imgUserPortal.ImageUrl = Global.Default_User_Portrait_Path;
                    }

                    userPortraitUpload.Hidden = false;

                    ddlMarriage.SelectedValue = user.MaritalStatus;

                    ddlNation.SelectedValue   = user.Ethnic;
                    tbxUserName.Text          = user.Name;
                    tbxPassWord.Text          = user.Password;
                    tbxPassWord.Hidden        = true;
                    tbxUserName.Readonly      = true;
                    tbxPassWord.Readonly      = true;
                    tbxOnBoardDate.Text       = user.OnBoardDate.HasValue ? user.OnBoardDate.ToString() : null;
                    tbxBecomeRegularDate.Text = user.BecomeRegularDate.HasValue ? user.BecomeRegularDate.ToString() : null;

                    if (user.ReportsTo != null)
                    {
                        tbxReportToID.Text = user.ReportsTo.Value.ToString();
                        tbxReportTo.Text   = user.ReportsToUser.ChineseName;
                    }

                    if (user.Department != null)
                    {
                        ddbDept.Value = user.DepartmentID.ToString();
                        ddbDept.Text  = user.Department.Name;
                    }

                    if (user.UserPermissionRoles != null)
                    {
                        ddbRoles.Values = user.UserPermissionRoles.Select(item => item.PermissionRoleID.ToString()).ToArray();
                        ddbRoles.Text   = String.Join(",", DB.UserPermissionRoles.Where(item => item.UserID == id).Select(r => r.PermissionRole.Name).ToArray());
                    }

                    if (user.JobRole != null)
                    {
                        ddbTitles.Value = user.JobID.ToString();
                        ddbTitles.Text  = user.JobRole.Name;
                    }

                    ddlCertificates.SelectedValue = user.IDType;
                    tbxIDCardEdit.Text            = user.IDNumber;
                    ddlEducation.SelectedValue    = user.Education;
                    ddlNativePlace.SelectedValue  = user.NativePlace;
                    tbxNativePlace.Text           = user.MailAddress;
                }
            }

            BindGridAdjust();
            LoadFixPay();
            LoadBankInfo();
            LoadEducation();
            LoadEmployeement();
            LoadContract();
        }
Esempio n. 11
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();
        }
Esempio n. 12
0
        private void SaveItem()
        {
            int    userID   = UserInfo.Current.ID;
            string userName = UserInfo.Current.ChineseName;

            int id = GetQueryIntValue("id");

            Infobasis.Data.DataEntity.Vendor vendor = null;
            if (id > 0)
            {
                vendor = DB.Vendors.Find(id);
                saveFormData(vendor);
                vendor.LastUpdateDatetime = DateTime.Now;
                vendor.LastUpdateByID     = userID;
                vendor.LastUpdateByName   = userName;
            }
            else
            {
                vendor = new Infobasis.Data.DataEntity.Vendor();

                vendor.CreateDatetime = DateTime.Now;
                vendor.CreateByID     = userID;
                vendor.CreateByName   = userName;
                saveFormData(vendor);
                DB.Vendors.Add(vendor);
            }

            if (!string.IsNullOrEmpty(tbxERPAccount.Text) && !string.IsNullOrEmpty(tbxERPAccountPwd.Text) && tbxOpenERPAccount.Checked)
            {
                if (!DB.Users.Where(item => item.UserType == UserType.Vendor && item.Name == tbxERPAccount.Text.Trim()).Any())
                {
                    Infobasis.Data.DataEntity.User user = new Infobasis.Data.DataEntity.User();
                    user.Name              = tbxERPAccount.Text.Trim();
                    user.Password          = PasswordUtil.CreateDbPassword(tbxERPAccountPwd.Text.Trim());
                    user.EmployeeSpellCode = Infobasis.Web.Util.ChinesePinyin.GetPinyin(user.Name);
                    user.FirstSpellCode    = Infobasis.Web.Util.ChinesePinyin.GetFirstPinyin(user.Name);
                    user.Enabled           = true;
                    user.UserType          = UserType.Vendor;
                    user.CreateDatetime    = DateTime.Now;

                    DB.Users.Add(user);
                }
                else
                {
                    Infobasis.Data.DataEntity.User user = DB.Users.Where(u => u.UserType == UserType.Vendor && u.Name == tbxERPAccount.Text.Trim()).FirstOrDefault();
                    user.Password           = PasswordUtil.CreateDbPassword(tbxERPAccountPwd.Text.Trim());
                    user.Enabled            = true;
                    user.LastUpdateDatetime = DateTime.Now;
                }
            }
            else if (!string.IsNullOrEmpty(tbxERPAccount.Text) && !string.IsNullOrEmpty(tbxERPAccountPwd.Text) && !tbxOpenERPAccount.Checked)
            {
                Infobasis.Data.DataEntity.User user = DB.Users.Where(u => u.UserType == UserType.Vendor && u.Name == tbxERPAccount.Text.Trim()).FirstOrDefault();
                if (user != null)
                {
                    user.Password           = PasswordUtil.CreateDbPassword(tbxERPAccountPwd.Text.Trim());
                    user.Enabled            = false;
                    user.LastUpdateDatetime = DateTime.Now;
                }
            }
            DB.SaveChanges();
        }