2018-10-18-CAR总结

aspx

body


    
车辆信息管理+新增车辆
车牌号码:
车辆名称:
        
        
<%-- gridview增加自动序号列 即使分页也会继续累积而不会重新排序 --%>
        
    

script

 

    

导入

车辆管理
    
    
    

    

    

    

    

    

    

    <%--    

    --%>
    
    

    

    

    

    

后台cs

namespace THMS.page.VehicleManagement
{
    public partial class VCM : MyBasePage
    {
        User_InfoBLL _User_InfoBLL = new User_InfoBLL();
        public override void VerifyRenderingInServerForm(Control control)
        { }
          protected void Page_Load(object sender, EventArgs e)
          {

              if (Request["Action"] != null)
              {
                  string returnMsg = string.Empty;
                  StringBuilder returngvwMsg = new StringBuilder();
                  switch (Request["Action"])
                  {
                      //页面加载
                      case "LoadInfo":
                          returnMsg = LoadInfo();
                          Response.Write(returnMsg);
                          break;
                      //车辆信息查询
                      case "Query":
                          returnMsg = QueryInfo(
                              Request["CarPlateNumber"].ToString(),
                              Request["CarName"].ToString());
                          Response.Write(returnMsg);
                          break;
                      case "Update"://string CarNewPlateNumber, string CarName, string CarOwnerName, string CarCarRegisterArea, string CarCarType, string CarCompanyId,string CarID
                          returnMsg = Update(
                              Request["CarPlateNumber"].ToString(),
                              Request["CarName"].ToString(),
                              Request["CarOwnerName"].ToString(),
                              Request["CarCarRegisterArea"].ToString(),
                              Request["CarCarType"].ToString(),
                              Request["CarCompanyId"].ToString(),
                              Request["CarID"].ToString());
                          Response.Write(returnMsg);
                          break;
                      case "Save":
                          returnMsg = Save(
                            //  Request["CarID"].ToString(),
                              Request["CarPlateNumber"].ToString(),
                              Request["CarName"].ToString(),
                              Request["CarOwnerName"].ToString(),
                              Request["CarCarRegisterArea"].ToString(),
                              Request["CarCarType"].ToString(),
                              Request["CarCompanyId"].ToString());
                          Response.Write(returnMsg);
                          break;
                      case "Delete":
                          returnMsg = Delete(Request["CarID"].ToString());
                          Response.Write(returnMsg);
                          break;
                  }
                  Response.ContentType = "text/xml";
                  Response.Expires = 0;
                  Response.Flush();
                  Response.End();
              }
              if (!IsPostBack)
              {
                  this.txtCompanyID.DataSource = _User_InfoBLL.GetCompanyList();
                  this.txtCompanyID.DataValueField = "Company_ID";
                  this.txtCompanyID.DataTextField = "Company_Name";
                  this.txtCompanyID.DataBind();

                  //将下拉列表框第一列设置为“请选择”
                  this.txtCompanyID.Items.Insert(0, new ListItem(Constants.Const_DropDownList_EnterItem, "0"));

              }
          }
          protected String LoadInfo()    //页面车辆加载
          {
              BLL.VehicleInfoManagement.CarInfoManaBLL GetCar = new BLL.VehicleInfoManagement.CarInfoManaBLL();
              DataTable ds = GetCar.QueryCarInfo("", "");
              if (ds != null && ds.Rows.Count > 0)
              {
                 this.CarInfoGDV.DataSource = null;
                 this.CarInfoGDV.DataSource = ds;
                 this.CarInfoGDV.DataBind();
                 return PagingMethod.RenderGridView(this.CarInfoGDV);
              }
            else
                  return "Empty";
          }
          protected string QueryInfo(string QCarPlateNumber, string QCarName)    //车辆查询
          {
              BLL.VehicleInfoManagement.CarInfoManaBLL GetCar = new BLL.VehicleInfoManagement.CarInfoManaBLL();
              DataTable ds = GetCar.QueryCarInfo(QCarPlateNumber, QCarName);
              if (ds.Rows.Count > 0)
              {
                  this.CarInfoGDV.DataSource = null;
                  this.CarInfoGDV.DataSource = ds;
                  this.CarInfoGDV.DataBind();
                  return PagingMethod.RenderGridView(this.CarInfoGDV);
              }
              else
                  return "Empty";
          }
          //保存新加车辆
          public string Save(string CarNewPlateNumber, string CarName, string CarOwnerName, string CarCarRegisterArea, string CarCarType, string CarCompanyId)   //车辆信息新增
          {
             
              BLL.VehicleInfoManagement.CarInfoManaBLL VCMBLL = new BLL.VehicleInfoManagement.CarInfoManaBLL();
              if (VCMBLL.GetCarInforByCarPlateNumber(CarNewPlateNumber))
              {
                  Log_InfoBLL.AddOperateAdd("车辆信息新增失败,车牌号码  【" + CarNewPlateNumber + "】已经存在!", this.Title);
                  return "Exit";
              }
              else
              {
                  if (VCMBLL.SaveCarInfoBLL(CarNewPlateNumber, CarName, CarOwnerName, CarCarRegisterArea, CarCarType, CarCompanyId))
                  {
                      Log_InfoBLL.AddOperateAdd("车辆信息新增成功,车牌号码  【" + CarNewPlateNumber + "】,车辆名称【" + CarName + "】", this.Title);
                      return "Success";
                  }
                  else
                  {
                      Log_InfoBLL.AddOperateAdd("车辆信息新增失败,车牌号码  【" + CarNewPlateNumber + "】,车辆名称【" + CarName + "】", this.Title);
                      return "Error";
                  }
              }
          }
          public string Update( string CarNewPlateNumber, string CarName, string CarOwnerName, string CarCarRegisterArea, string CarCarType, string CarCompanyId,string CarID)   //车辆信息更新
          {
              BLL.VehicleInfoManagement.CarInfoManaBLL VCMBLL = new BLL.VehicleInfoManagement.CarInfoManaBLL();
              if (!(CarID == "" || (!VCMBLL.SearchTheCarBLL(CarID, CarNewPlateNumber))))
              {
                  Log_InfoBLL.AddOperateEdit("车辆信息修改失败,车牌号码 【" + CarNewPlateNumber + "】已经存在!", this.Title);
                  return "Exit";
              }
              else
              {
                  DataTable dtOld = VCMBLL.GetOldCarInfoByCarId(CarID);
                  string strEditContent = GetEditCarContent(dtOld, CarNewPlateNumber, CarName, CarOwnerName, CarCarRegisterArea, CarCarType, CarCompanyId);

                  if (VCMBLL.UpdateCarInfoBLL(CarID, CarNewPlateNumber, CarName, CarOwnerName, CarCarRegisterArea, CarCarType, CarCompanyId))
                  {
                      Log_InfoBLL.AddOperateEdit(strEditContent, this.Title);
                      return "Success";
                  }
                  else
                  {
                      Log_InfoBLL.AddOperateEdit("车辆信息修改失败", this.Title);
                      return "Error";
                  }
              }
          }
          public string Delete(string CarPlateNumber)
          {
              BLL.VehicleInfoManagement.CarInfoManaBLL VCMBLL = new BLL.VehicleInfoManagement.CarInfoManaBLL();
              if (VCMBLL.DeleteCarInfoBLL(CarPlateNumber))
              {
                  Log_InfoBLL.AddOperateDelete("车辆信息删除成功,车牌号码   【" + CarPlateNumber + "】", this.Title);
                  return "Success";
              }
              else
              {
                  Log_InfoBLL.AddOperateDelete("车辆信息删除失败,车牌号码   【" + CarPlateNumber + "】", this.Title);
                  return "";
              }
          }
          //加载单位列表
          public string LoadCompanyItem()
          {
              DataTable CompanyItem = _User_InfoBLL.GetCompanyList();
              return CommonHelper.ToJson(CompanyItem);
          }
          public string GetEditCarContent(DataTable dtOld, string CarNewPlateNumber, string CarName, string CarOwnerName, string CarCarRegisterArea, string CarCarType, string CarCompanyId)
          {
              string strEditContent = "";

              if (dtOld != null && dtOld.Rows.Count > 0)
              {
                  strEditContent = "成功修改车辆信息";

                  if (dtOld.Rows[0]["Car_PlateNumber"].ToString().Trim() != CarNewPlateNumber.Trim())
                      strEditContent += ",车牌号码  从【" + dtOld.Rows[0]["Car_PlateNumber"].ToString().Trim() + "】变更为【" + CarNewPlateNumber.Trim() + "】";

                  if (dtOld.Rows[0]["Car_Name"].ToString().Trim() != CarName.Trim())
                      strEditContent += ",车辆名称 从【" + dtOld.Rows[0]["Car_Name"].ToString().Trim() + "】变更为【" + CarName.Trim() + "】";

                  if (dtOld.Rows[0]["Car_OwnerName"].ToString().Trim() != CarOwnerName.Trim())
                      strEditContent += ",车主姓名 从【" + dtOld.Rows[0]["Car_OwnerName"].ToString().Trim() + "】变更为【" + CarOwnerName.Trim() + "】";

                  if (dtOld.Rows[0]["Car_CarRegisterArea"].ToString().Trim() != CarCarRegisterArea.Trim())
                      strEditContent += ",车籍地 从【" + dtOld.Rows[0]["Car_CarRegisterArea"].ToString().Trim() + "】变更为【" + CarCarRegisterArea.Trim() + "】";

                  if (dtOld.Rows[0]["Car_CarType"].ToString().Trim() != CarCarType.Trim())
                      strEditContent += ",车辆类型 从【" + dtOld.Rows[0]["Car_CarType"].ToString().Trim() + "】变更为【" + CarCarType.Trim() + "】";

                  if (dtOld.Rows[0]["Car_CompanyId"].ToString().Trim() != CarCompanyId.Trim())
                      strEditContent += ",所属单位 从【" + dtOld.Rows[0]["Car_CompanyId"].ToString().Trim() + "】变更为【" + CarCompanyId.Trim() + "】";
              }

              return strEditContent;
          }
    }
}

BBL

namespace BLL.VehicleInfoManagement
{
    public class CarInfoManaBLL
    {
        #region

        /// 
        /// 直接加载车辆信息
        /// 
        /// true false
        public DataTable GetCarInfo()
        {
            Car_InforDAL GetCar = new Car_InforDAL();
            User_Info user = LoginHandler.CurrentUser;
            if (user.Company_ID == 0)
            {
                return GetCar.GetCarInfoDAL(user.User_ID.ToString(), "0");
            }
            else
            {
                return GetCar.GetCarInfoDAL(user.User_ID.ToString(), Role_InfoDAL.GetAllEneterIdsByCompanyID(user.Company_ID.ToString()));
            }
        }
        /// 
        /// 根据条件获取车辆信息
        /// 
        /// true false
        public DataTable QueryCarInfo(string QueryCarPlateNumber, string QueryCarName)
        {
            Car_InforDAL GetCar = new Car_InforDAL();
            User_Info user = LoginHandler.CurrentUser;
            if (user.Company_ID == 0)
            {
                return GetCar.QueryCarInfoDAL(user.User_ID.ToString(), "0", QueryCarPlateNumber, QueryCarName);
            }
            else
            {
                return GetCar.QueryCarInfoDAL(user.User_ID.ToString(), Role_InfoDAL.GetAllEneterIdsByCompanyID(user.Company_ID.ToString()), QueryCarPlateNumber, QueryCarName);
            }
        }
        /// 
        /// 当前用户下的下属车辆
        /// 
        /// true false
        public DataTable GetAllCompanyInfoByUserBLL()
        {
            Car_InforDAL GetCarInfo = new Car_InforDAL();
            User_Info user = LoginHandler.CurrentUser;
            if (user.Company_ID == 0)
            {
                return GetCarInfo.GetCarInfoByUserDAL(user.User_ID.ToString(), "0");
            }
            else
            {
                return GetCarInfo.GetCarInfoByUserDAL(user.User_ID.ToString(), Role_InfoDAL.GetAllEneterIdsByUserID(user.User_ID.ToString()));
            }
        }
        /// 
        /// 查询该车辆是否存在

        /// 
        /// true false
        public bool SearchTheCarBLL(string CarID, string CarNewPlateNumber)
        {
            Car_InforDAL SearchTheCar = new Car_InforDAL();
            return SearchTheCar.SearchTheCarDAL(CarID, CarNewPlateNumber);
        }

        /// 
        /// 保存新增车辆信息
        /// 
        /// true false
        public bool SaveCarInfoBLL(string CarPlateNumber, string CarName, string CarOwnerName, string CarCarRegisterArea, string CarCarType, string CarCompanyId)
        {
            Car_InforDAL SaveCarInfo = new Car_InforDAL();
            User_Info user = LoginHandler.CurrentUser;
            return SaveCarInfo.SaveCarInfoDAL(user.User_ID.ToString(), CarPlateNumber, CarName, CarOwnerName, CarCarRegisterArea, CarCarType, CarCompanyId);
        }
        /// 
        /// 更新车辆信息
        /// 
        /// true false
        public bool UpdateCarInfoBLL(string CarID, string CarPlateNumber, string CarName, string CarOwnerName, string CarCarRegisterArea, string CarCarType, string CarCompanyId)
        {
            Car_InforDAL SaveCarInfo = new Car_InforDAL();
            User_Info user = LoginHandler.CurrentUser;
            return SaveCarInfo.UpdateCarInfoDAL(user.User_ID.ToString(), CarID, CarPlateNumber, CarName, CarOwnerName, CarCarRegisterArea, CarCarType, CarCompanyId);
        }
        /// 
        /// 删除车辆信息
        /// 
        /// true false
        public bool DeleteCarInfoBLL(string CarPlateNumber)
        {
            Car_InforDAL DeleteCarInfo = new Car_InforDAL();
            return DeleteCarInfo.DeleteCarInfoDAL(CarPlateNumber);
        }
        public bool VilCarOfUser()
        {

            User_Info user = LoginHandler.CurrentUser;

            if (Role_InfoDAL.ExitSupper(user.User_ID.ToString()))
            {
                return true;
            }
            else if (Role_InfoDAL.ExitBusiness(user.User_ID.ToString()) || Role_InfoDAL.ExitMaintenance(user.User_ID.ToString()))
            {
                return true;
            }
            if (user.Company_ID != 0)
                return true;
            else return false;
        }
        public DataTable GetOldCarInfoByCarId(string CarID)
        {
            Car_InforDAL _Car_InfoDAL = new Car_InforDAL();
            return _Car_InfoDAL.GetOldCarInfoByCarId(CarID);
        }


        public bool GetCarInforByCarPlateNumber(string Car_PlateNumber)
        {
            Car_InforDAL _Car_InfoDAL = new Car_InforDAL();
            return _Car_InfoDAL.GetCarInforByCarPlateNumber(Car_PlateNumber);

        }
        #endregion
    }
}

DAL

namespace DAL
{
    public class Car_InforDAL
    {
        #region
        /// 
        /// 直接加载车辆信息
        /// 
        /// true false
        public DataTable GetCarInfoDAL(string strUserId, string strCarIDs)
        {
            try
            {
                string strAddSql = "";
                if (Role_InfoDAL.ExitSupper(strUserId))
                {
                    strAddSql = " select a.*,b.Company_Name as Conpany_Name from dbo.Car_Infor a left join Company_Info b on a.Car_CompanyId=b.Company_ID order by UPDATED_DATE desc, CREATED_DATE DESC";
                    return DBCommon.GetDataTable(strAddSql);
                }
                else
                {
                    if (strCarIDs == "0")
                    {
                        DataTable ds = new DataTable();
                        return ds;
                    }
                    else
                    {
                        strAddSql = " select a.*,b.Company_Name as Conpany_Name from dbo.Car_Infor a left join Company_Info b on a.Car_CompanyId=b.Company_ID where a.Car_ID in ('" + strCarIDs + "') order by UPDATED_DATE desc, CREATED_DATE DESC";
                        return DBCommon.GetDataTable(strAddSql);
                    }
                }
            }
            catch (Exception ex)
            {
                throw new ApplicationException(ex.Message);
            }
        }
        /// 
        /// 根据条件获取车辆信息
        /// 
        /// true false
        public DataTable QueryCarInfoDAL(string strUserId, string strCarIDs, string QueryCarPlateNumber, string QueryCarName)
        {
            try
            {
                StringBuilder sb = new StringBuilder();
                sb.Append(" select a.*,b.Company_Name as Conpany_Name from dbo.Car_Infor a left join Company_Info b on a.Car_CompanyId=b.Company_ID");
                sb.Append(" where 1=1 ");
                if (QueryCarPlateNumber != "")
                    sb.Append(" and a.Car_PlateNumber like '%" + QueryCarPlateNumber + "%'");
                if (QueryCarName != "")
                    sb.Append(" and a.Car_Name like '%" + QueryCarName + "%'");
                if (Role_InfoDAL.ExitSupper(strUserId))
                {
                }
                else if (Role_InfoDAL.ExitBusiness(strUserId) || Role_InfoDAL.ExitMaintenance(strUserId))
                {
                   
                }
                else
                {
                    if (strCarIDs == "0")
                    {
                        DataTable ds = new DataTable();
                        return ds;
                    }
                    else
                    {
                        sb.Append(" and a.Company_ID in ('" + strCarIDs + "')");
                    }
                }
                return DBCommon.GetDataTable(sb.ToString());
            }
            catch (Exception ex)
            {
                throw new ApplicationException(ex.Message);
            }
        }
        #region     
        /// 
        /// 当前用户下的下属车辆
        /// 
        /// true false
        public DataTable GetCarInfoByUserDAL(string strUserId, string strConpanyIDBystrUserId)
        {
            try
            {
                string strAddSql = "";
                if (Role_InfoDAL.ExitSupper(strUserId))
                {
                    strAddSql = " select Car_ID,Car_Name from Car_Infor order by Car_Name";
                    return DBCommon.GetDataTable(strAddSql);
                }
                else if (Role_InfoDAL.ExitBusiness(strUserId) || Role_InfoDAL.ExitMaintenance(strUserId))
                {
                    

                    strAddSql = " select Car_ID,Car_Name from Car_Infor order by Car_Name";
                    return DBCommon.GetDataTable(strAddSql);
                }
                else
                {
                    if (strConpanyIDBystrUserId == "0")
                    {
                        DataTable ds = new DataTable();
                        return ds;
                    }
                    else
                    {
                        strAddSql = "select Car_ID,Car_Name from Car_Infor where Car_ID in ('" + strConpanyIDBystrUserId + "') order by Car_Name";
                        return DBCommon.GetDataTable(strAddSql);
                    }
                }
            }
            catch (Exception ex)
            {
                throw new ApplicationException(ex.Message);
            }
        }
        #endregion

        /// 
        /// 查询该车辆是否存在

        /// 
        /// true false
        public bool SearchTheCarDAL(string CarID, string CarNewPlateNumber)
        {
            string sql = "select * from Car_Infor where Car_ID<>'" + CarID + "' and Car_PlateNumber='" + CarNewPlateNumber + "'";
            return DBCommon.ExecuteNumber(sql) > 0;
        }
        /// 
        /// 保存新增车辆信息
        /// 
        /// true false
        public bool SaveCarInfoDAL(string strUserId, string CarPlateNumber, string CarName, string CarOwnerName, string CarCarRegisterArea, string CarCarType, string CarCompanyId)
        {
            try
            {
                string ddTime = DateTime.Now.ToString();
                StringBuilder strSql = new StringBuilder();
                strSql.Append("insert into dbo.Car_Infor (Car_PlateNumber,Car_Name,Car_OwnerName,Car_CarRegisterArea,");
                strSql.Append("Car_CarType,Car_CompanyId) values ( ");
                strSql.Append("'" + CarPlateNumber + "','" + CarName + "','" + CarOwnerName + "',");
                strSql.Append("'" + CarCarRegisterArea + "','" + CarCarType + "','" + CarCompanyId + "')");
                string sql = strSql.ToString();
                return DBCommon.ExecuteNonQuery(sql);

            }
            catch (Exception ex)
            {
                throw new ApplicationException(ex.Message);
            }
        }
        /// 
        /// 更新车辆信息
        /// 
        /// true false
        public bool UpdateCarInfoDAL(string strUserId, string CarID, string CarPlateNumber, string CarName, string CarOwnerName, string CarCarRegisterArea, string CarCarType, string CarCompanyId)
        {
            try
            {
                string ddTime = DateTime.Now.ToString();
                StringBuilder strSql = new StringBuilder();
                strSql.Append("update dbo.Car_Infor set Car_PlateNumber='" + CarPlateNumber + "',Car_OwnerName='" + CarOwnerName + "',Car_Name='" + CarName + "', ");
                strSql.Append("Car_CarRegisterArea='" + CarCarRegisterArea + "',Car_CarType='" + CarCarType + "',Car_CompanyId='" + CarCompanyId + "' ");
                strSql.Append("where Car_ID='" + CarID + "'");
                string sql = strSql.ToString();
                return DBCommon.ExecuteNonQuery(sql);
            }
            catch (Exception ex)
            {
                throw new ApplicationException(ex.Message);
            }
        }
        /// 
        /// 删除车辆信息
        /// 
        /// true false
        public bool DeleteCarInfoDAL(string CarID)
        {
            string sql = "delete from Car_Infor where Car_ID='" + CarID + "'";
            return DBCommon.ExecuteNonQuery(sql);
        }
        #endregion
        public DataTable GetCarInfoList(string CarIDS)
        {
            string strSql = "select Car_ID,Car_Name from Car_Infor where Car_ID in ('" + CarIDS + "') order by Car_Name";
            return DBCommon.GetDataTable(strSql);
        }
        public DataTable GetCarInfoById(string CarID)
        {
            string strSql = "select * from Car_Infor where Car_ID = '" + CarID + "'";
            return DBCommon.GetDataTable(strSql);
        }
        public DataTable GetCarInfoList()
        {
            string strSql = "select Car_ID,Car_Name from Car_Infor order by Car_Name";
            return DBCommon.GetDataTable(strSql);
        }
        public DataTable GetOldCarInfoByCarId(string CarID)
        {
            string strSql = "select * from Car_Infor where Car_ID = '" + CarID + "'";
            return DBCommon.GetDataTable(strSql);
        }
        public bool GetCarInforByCarPlateNumber(string Car_PlateNumber)
        {
            string strSql = "select count(0) from Car_Infor where Car_PlateNumber='" + Car_PlateNumber + "'";
            string strCount= DBCommon.GetFirstRowCol(strSql);
            if (strCount == "0")
                return false;
            else
                return true;
        }
        public DataTable GetCompanyInfoListByBusinessMaintenance(string strUserIDsandCarIDs)
        {
            string strSql = "select Car_ID,Car_Name from Car_Infor where 1=1 ";

            if (strUserIDsandCarIDs != "")
            {
                string[] UserIDandCarIDs = strUserIDsandCarIDs.Split('|');

                if (UserIDandCarIDs[1] != null && UserIDandCarIDs[1] != "")
                {
                    strSql += " and Car_ID in ('" + UserIDandCarIDs[1] + "')";
                }
            }

            strSql += " order by Car_Name";


            return DBCommon.GetDataTable(strSql);
        }

    }

}

你可能感兴趣的:(2018-10-18-CAR总结)