Exemplo n.º 1
0
        public static SelectResult <EmployeeInfoEditModel> GetEmployeeInfoByID(int id)
        {
            List <SqlParameter> paras = new List <SqlParameter>()
            {
                new SqlParameter("@ID", SqlDbType.NVarChar, 20),
            };

            paras[0].Value = id;
            string sql = @"SELECT EmployeeID,EmployeeName
 ,EmployeeGender
      ,CAST(BirthDate AS CHAR(10)) AS BirthDate
      ,ContactPhone
      ,ContactAddress
      ,CertificateTypeID
      ,CertificateCode
      ,CertificateOffice
      ,CAST(ValidStartTime AS CHAR(10)) AS ValidStartTime
      ,CAST(ValidEndTime AS CHAR(10)) AS ValidEndTime
      ,IsDriver
      ,DriveCode
      ,DriveTypeID
      ,DriveLicenseStateID
      ,IsCarrier
      ,EmergePhone
      ,CarrierCode
      ,StrucID
      ,Remark
      ,CAST(DriveCodeValidTime AS CHAR(10)) AS DriveCodeValidTime
  FROM dbo.EmployeeInfo
  WHERE ID=@ID";
            List <EmployeeInfoEditModel> list = ConvertToList <EmployeeInfoEditModel> .Convert(MSSQLHelper.ExecuteDataTable(CommandType.Text, sql, paras.ToArray()));

            EmployeeInfoEditModel data = null;
            string msg = string.Empty;

            if (list == null)
            {
                msg = PromptInformation.DBError;
            }
            else if (list.Count == 0)
            {
                msg = PromptInformation.NotExists;
            }
            else
            {
                data = list[0];
            }
            return(new SelectResult <EmployeeInfoEditModel>()
            {
                DataResult = data,
                Message = msg
            });
        }
Exemplo n.º 2
0
        public static OperationResult EditEmployeeInfo(EmployeeInfoEditModel model, int currentUserID)
        {
            List <SqlParameter> paras = new List <SqlParameter>()
            {
                new SqlParameter("@EmployeeName", SqlDbType.NVarChar, 50),
                new SqlParameter("@EmployeeGender", SqlDbType.Bit),
                new SqlParameter("@CertificateTypeID", SqlDbType.Int),
                new SqlParameter("@CertificateCode", SqlDbType.NVarChar, 20),
                new SqlParameter("@BirthDate", SqlDbType.Date),

                new SqlParameter("@CertificateOffice", SqlDbType.NVarChar, 50),
                new SqlParameter("@ValidStartTime", SqlDbType.Date),
                new SqlParameter("@ValidEndTime", SqlDbType.Date),
                new SqlParameter("@ContactPhone", SqlDbType.NVarChar, 20),
                new SqlParameter("@ContactAddress", SqlDbType.NVarChar, 200),

                new SqlParameter("@IsDriver", SqlDbType.Bit),
                new SqlParameter("@DriveCode", SqlDbType.NVarChar, 20),
                new SqlParameter("@DriveTypeID", SqlDbType.NVarChar, 20),
                new SqlParameter("@IsCarrier", SqlDbType.Bit),
                new SqlParameter("@EmergePhone", SqlDbType.NVarChar, 20),

                new SqlParameter("@DriveLicenseStateID", SqlDbType.Int),
                new SqlParameter("@Remark", SqlDbType.NVarChar, 500),
                new SqlParameter("@DriveCodeValidTime", SqlDbType.Date),
                new SqlParameter("@ID", SqlDbType.Int),
                new SqlParameter("@UpdateUser", SqlDbType.Int),

                new SqlParameter("@CarrierCode", SqlDbType.NVarChar, 20),
                new SqlParameter("@StrucID", SqlDbType.Int),
            };

            paras[0].Value = model.EmployeeName.Trim();
            paras[1].Value = model.EmployeeGender;
            paras[2].Value = model.CertificateTypeID;
            paras[3].Value = model.CertificateCode.Trim();
            if (string.IsNullOrEmpty(model.BirthDate))
            {
                paras[4].Value = DBNull.Value;
            }
            else
            {
                paras[4].Value = model.BirthDate;
            }

            if (string.IsNullOrEmpty(model.CertificateOffice))
            {
                paras[5].Value = DBNull.Value;
            }
            else
            {
                paras[5].Value = model.CertificateOffice.Trim();
            }
            if (string.IsNullOrEmpty(model.ValidStartTime))
            {
                paras[6].Value = DBNull.Value;
            }
            else
            {
                paras[6].Value = model.ValidStartTime;
            }
            if (string.IsNullOrEmpty(model.ValidEndTime))
            {
                paras[7].Value = DBNull.Value;
            }
            else
            {
                paras[7].Value = model.ValidEndTime;
            }
            paras[8].Value = model.ContactPhone.Trim();
            paras[9].Value = model.ContactAddress.Trim();

            paras[10].Value = model.IsDriver;
            if (string.IsNullOrEmpty(model.DriveCode))
            {
                paras[11].Value = DBNull.Value;
            }
            else
            {
                paras[11].Value = model.DriveCode.Trim();
            }
            paras[12].Value = model.DriveTypeID;
            paras[13].Value = model.IsCarrier;
            if (string.IsNullOrEmpty(model.EmergePhone))
            {
                paras[14].Value = DBNull.Value;
            }
            else
            {
                paras[14].Value = model.EmergePhone.Trim();
            }

            paras[15].Value = model.DriveLicenseStateID;
            if (string.IsNullOrWhiteSpace(model.Remark))
            {
                paras[16].Value = DBNull.Value;
            }
            else
            {
                paras[16].Value = model.Remark;
            }
            if (string.IsNullOrWhiteSpace(model.DriveCodeValidTime))
            {
                paras[17].Value = DBNull.Value;
            }
            else
            {
                paras[17].Value = model.DriveCodeValidTime;
            }
            paras[18].Value = model.ID;
            paras[19].Value = currentUserID;

            if (string.IsNullOrWhiteSpace(model.CarrierCode))
            {
                paras[20].Value = DBNull.Value;
            }
            else
            {
                paras[20].Value = model.CarrierCode.Trim();
            }
            paras[21].Value = model.StrucID;

            #region  SQL
            string sql = @"UPDATE dbo.EmployeeInfo
      SET EmployeeName = @EmployeeName ,
          EmployeeGender = @EmployeeGender ,
          BirthDate = @BirthDate ,
          ContactPhone = @ContactPhone ,
          ContactAddress = @ContactAddress ,
          CertificateTypeID = @CertificateTypeID ,
          CertificateCode = @CertificateCode ,
          CertificateOffice = @CertificateOffice ,
          ValidStartTime = @ValidStartTime ,
          ValidEndTime = @ValidEndTime ,
          IsDriver = @IsDriver ,
          DriveCode = @DriveCode ,
          DriveTypeID = @DriveTypeID ,
          DriveLicenseStateID = @DriveLicenseStateID ,
          IsCarrier = @IsCarrier ,
          EmergePhone = @EmergePhone ,
          Remark = @Remark ,
          UpdateUser = @UpdateUser ,
          UpdateTime = GetDate() ,
          DriveCodeValidTime = @DriveCodeValidTime  ,
          CarrierCode = @CarrierCode ,
          StrucID = @StrucID 
        WHERE  ID = @ID ";
            #endregion


            int    result = MSSQLHelper.ExecuteNonQuery(CommandType.Text, sql, paras.ToArray());
            string msg    = string.Empty;
            switch (result)
            {
            case 1:
                msg = PromptInformation.OperationSuccess;
                break;

            case 0:
                msg = PromptInformation.NotExists;
                break;

            case -1:
                msg = PromptInformation.DBError;
                break;
            }
            return(new OperationResult()
            {
                Success = result > 0,
                Message = msg
            });
        }
Exemplo n.º 3
0
        public ActionResult EditEmployeeInfo(EmployeeInfoEditModel model)
        {
            //if (model.CertificateTypeID == 1)
            //{
            //    bool isIDcard = IsIDcard(model.CertificateCode);
            //    if (!isIDcard)
            //    {
            //        ModelState.AddModelError("CertificateCode", DataAnnotations.IDcardError);
            //    }
            //}
            //if (model.IsDriver == true && string.IsNullOrEmpty(model.DriveCode))
            //{
            //    ModelState.AddModelError("DriveCode", DataAnnotations.NeedDriveCode);
            //}
            //if (model.IsDriver == true && string.IsNullOrEmpty(model.DriveCodeValidTime))
            //{
            //    ModelState.AddModelError("DriveCodeValidTime", DataAnnotations.MustInputDriveCodeValidTime);
            //}


            if (model.IsDriver == true && model.DriveLicenseStateID == 0)
            {
                ModelState.AddModelError("DriveLicenseStateID", DataAnnotations.MustInputDriveLicenseStateID);
            }
            //if (model.IsDriver == true && model.DriveTypeID.Equals("0"))
            //{
            //    ModelState.AddModelError("DriveTypeID", DataAnnotations.MustInputDriveTypeID);
            //}


            //if (model.IsCarrier == true && string.IsNullOrEmpty(model.EmergePhone))
            //{
            //    ModelState.AddModelError("EmergePhone", DataAnnotations.NeedEmergePhone);
            //}
            //if (model.IsCarrier == true && string.IsNullOrEmpty(model.CarrierCode))
            //{
            //    ModelState.AddModelError("CarrierCode", DataAnnotations.NeedCarrierCode);
            //}
            if (ModelState.IsValid)
            {
                var result = EmployeeInfoBLL.EditEmployeeInfo(model, base.CurrentUserID);
                base.DoLog(OperationTypeEnum.Edit, result, "EmployeeID:" + model.EmployeeID);
                return(Json(result));
            }
            else
            {
                model.CertificateTypeSelectList = new SelectList(EmployeeInfoBLL.GetCertificateTypes(), "CertificateTypeID", "CertificateTypeName");

                SelectList            driveLicenseStateSelectList = new SelectList(EmployeeInfoBLL.GetDriveLicenseStates(), "DriveLicenseStateID", "DriveLicenseStateName");
                List <SelectListItem> liDriveLicenseState         = new List <SelectListItem>();
                liDriveLicenseState.Add(new SelectListItem {
                    Text = DisplayText.PleaseSelect, Value = "0"
                });
                liDriveLicenseState.AddRange(driveLicenseStateSelectList);
                model.DriveLicenseStateSelectList = liDriveLicenseState;


                SelectList            driveTypeSelectList = new SelectList(EmployeeInfoBLL.GetDriveTypes(), "DriveTypeID", "DriveTypeName");
                List <SelectListItem> liDriveType         = new List <SelectListItem>();
                liDriveType.Add(new SelectListItem {
                    Text = DisplayText.PleaseSelect, Value = "0"
                });
                liDriveType.AddRange(driveTypeSelectList);
                model.DriveTypeSelectList = liDriveType;

                return(PartialView("_EditEmployeeInfo", model));
            }
        }