private string GetNewEntityJson(Institution_Staff entity, bool state)
 {
     try
     {
         Institution_Staff m = entity.ToJson().ToObject <Institution_Staff>();
         m.State = state;
         return(m.ToJson());
     }
     catch (Exception ex)
     {
         throw new Exception(ex.Message);
     }
 }
 private string GetNewEntityJson(Institution_Staff entity, string password)
 {
     try
     {
         Institution_Staff m = entity.ToJson().ToObject <Institution_Staff>();
         m.Password = password;
         return(m.ToJson());
     }
     catch (Exception ex)
     {
         throw new Exception(ex.Message);
     }
 }
 private string GetNewEntityJson(Institution_Staff entity, string fStaffName, string fSex, string fPositionId, string fDepartmentId, string fStoreId, string fPhone, string fEmail, string fAddress, string fDescription, string fState)
 {
     try
     {
         Institution_Staff m = entity.ToJson().ToObject <Institution_Staff>();
         m.StaffName    = fStaffName;
         m.NickName     = fStaffName;
         m.Sex          = fSex.ToByte();
         m.Name         = fStaffName;
         m.Phone        = fPhone;
         m.Email        = fEmail;
         m.Address      = fAddress;
         m.DepartmentID = fDepartmentId;
         m.PositionID   = fPositionId;
         m.StoreID      = fStoreId;
         m.Description  = fDescription;
         m.State        = fState.ToBool();
         return(m.ToJson());
     }
     catch (Exception ex)
     {
         throw new Exception(ex.Message);
     }
 }
        private bool UpdateStaff(string staffId)
        {
            try
            {
                string fStaffName    = GetFormValue("fStaffName");
                string fSex          = GetFormValue("fSex");
                string fPositionId   = GetFormValue("fPositionId");
                string fDepartmentId = GetFormValue("fDepartmentId");
                string fStoreId      = GetFormValue("fStoreId");
                string fPhone        = GetFormValue("fPhone");
                string fEmail        = GetFormValue("fEmail");
                string fAddress      = GetFormValue("fAddress");
                string fDescription  = GetFormValue("fDescription");
                string fState        = GetFormValue("fState");

                if (string.IsNullOrWhiteSpace(fStaffName))
                {
                    throw new Exception("员工姓名不能为空!");
                }
                if (fPhone.Length != 11)
                {
                    throw new Exception("手机号码长度错误!");
                }
                if (!Utility.IsMobilePhone(fPhone))
                {
                    throw new Exception("手机号码格式错误!");
                }
                var entity = StaffService.GetStaffPro(SystemID, CompanyID, staffId);
                if (entity == null)
                {
                    throw new Exception("员工工号不存在!");
                }
                Institution_Staff m = new Institution_Staff()
                {
                    SystemID               = entity.SystemID,
                    CompanyID              = entity.CompanyID,
                    StaffID                = entity.StaffID,
                    StaffName              = fStaffName,
                    UserName               = entity.UserName,
                    Password               = entity.Password,
                    NickName               = fStaffName,
                    HeadImgUrl             = entity.HeadImgUrl,
                    Name                   = fStaffName,
                    Sex                    = fSex.ToByte(),
                    BirthDate              = entity.BirthDate,
                    BirthPlace             = entity.BirthPlace,
                    Identification         = entity.Identification,
                    Education              = entity.Education,
                    Phone                  = fPhone,
                    QQ                     = entity.QQ,
                    Weixin                 = entity.Weixin,
                    Email                  = fEmail,
                    Address                = fAddress,
                    Wages                  = entity.Wages,
                    Probation              = entity.Probation,
                    StartWorkDate          = entity.StartWorkDate,
                    EndWorkDate            = entity.EndWorkDate,
                    SignContractDate       = entity.SignContractDate,
                    ExpirationContractDate = entity.ExpirationContractDate,
                    DepartmentID           = fDepartmentId,
                    DepartmentName         = entity.DepartmentName,
                    PositionID             = fPositionId,
                    PositionName           = entity.PositionName,
                    StoreID                = fStoreId,
                    StoreName              = entity.StoreName,
                    WarehouseID            = entity.WarehouseID,
                    WarehouseName          = entity.WarehouseName,
                    Description            = fDescription,
                    IsInit                 = entity.IsInit,
                    State                  = fState.ToBool(),
                    IsDel                  = entity.IsDel,
                    CreateDate             = entity.CreateDate
                };
                bool   result        = StaffService.UpdateStaffPro(m);
                string newEntityJson = GetNewEntityJson(entity, fStaffName, fSex, fPositionId, fDepartmentId, fStoreId, fPhone, fEmail, fAddress, fDescription, fState);
                TableOperationManager.Update(entity, newEntityJson, result);
                return(result);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
        private bool SaveStaff()
        {
            try
            {
                string fStaffId      = GetFormValue("fStaffId");
                string fStaffName    = GetFormValue("fStaffName");
                string fSex          = GetFormValue("fSex");
                string fPositionId   = GetFormValue("fPositionId");
                string fDepartmentId = GetFormValue("fDepartmentId");
                string fStoreId      = GetFormValue("fStoreId");
                string fPhone        = GetFormValue("fPhone");
                string fEmail        = GetFormValue("fEmail");
                string fAddress      = GetFormValue("fAddress");
                string fDescription  = GetFormValue("fDescription");
                string fState        = GetFormValue("fState");

                if (string.IsNullOrWhiteSpace(fStaffId))
                {
                    throw new Exception("员工工号不能为空!");
                }
                if (string.IsNullOrWhiteSpace(fStaffName))
                {
                    throw new Exception("员工姓名不能为空!");
                }
                if (fPhone.Length != 11)
                {
                    throw new Exception("手机号码长度错误!");
                }
                if (!Utility.IsMobilePhone(fPhone))
                {
                    throw new Exception("手机号码格式错误!");
                }

                string password = AlgorithmHelper.MD5(Utility.Right(fPhone, 8)).ToLower();
                var    entity   = new Institution_Staff()
                {
                    SystemID     = SystemID,
                    CompanyID    = CompanyID,
                    StaffID      = fStaffId,
                    StaffName    = fStaffName,
                    UserName     = fStaffId,
                    Password     = password,
                    NickName     = fStaffName,
                    Name         = fStaffName,
                    Sex          = fSex.ToByte(),
                    Phone        = fPhone,
                    Email        = fEmail,
                    Address      = fAddress,
                    DepartmentID = fDepartmentId,
                    PositionID   = fPositionId,
                    StoreID      = fStoreId,
                    WarehouseID  = "",
                    Description  = fDescription,
                    IsInit       = false,
                    State        = fState.ToBool(),
                    IsDel        = false,
                    CreateDate   = DateTime.Now
                };
                bool result = StaffService.SaveStaffPro(entity);
                TableOperationManager.Add(entity, result);
                return(result);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }