Esempio n. 1
0
        public DBProcessResult ModifyVehicle(EMVehicleViewModel view)
        {
            DBProcessResult result = new DBProcessResult();
            try
            {
                IEMVehicleService service = new EMVehicleService();
                IEMVehicleLogService logService = new EMVehicleLogService();
                IdentityNoService noService = new IdentityNoService();
                IEMGpsTypeService gpsTypeService = new EMGpsTypeService();

                EMVehicle entity = ConvertHelper.ConvertObj<EMVehicleViewModel, EMVehicle>(view);
                EMVehicle oldEntity = service.Select(view.VehicleCode);
                entity.ExpireTime = oldEntity.ExpireTime;
                entity.InstallTime = oldEntity.InstallTime;
                entity.CreateTime = oldEntity.CreateTime;
                entity.IsStop = oldEntity.IsStop;
                EMGpsType gpsTypeEntity = gpsTypeService.Get(entity.GPSTypeID);
                entity.GPSTypeName = gpsTypeEntity.TypeName;
                //如果设备号改变,要重新获取GPSCode,添加和修改日志
                if (entity.DeviceNo != oldEntity.DeviceNo)
                {
                    bool bo = service.IsExist(view.DeviceNo);
                    if (bo != true)
                    {

                        EnumGPSCodeRule codeType = (EnumGPSCodeRule)gpsTypeEntity.GPSCodeRule;

                        entity.GPSCode = GetGPSCodeHelper.GetGPSCode(gpsTypeEntity.PrefixCode, codeType, entity.SIMNo, entity.DeviceNo);
                        if (entity.DeviceNo.Length == gpsTypeEntity.MachineCodeLength)
                        {
                            //修改上一个日志
                            DateTime now = DateTime.Now;
                            EMVehicleLog lastLog = logService.GetLast(entity.VehicleCode);
                            if (lastLog != null)
                            {
                                lastLog.EndDate = now;
                                logService.Update(lastLog);
                            }

                            //新增一个日志
                            EMVehicleLog vehicleLog = new EMVehicleLog()
                            {
                                BeginDate = now,
                                LogID = noService.GetVehicleLogID(),
                                DeviceNo = entity.DeviceNo,
                                EndDate = null,
                                GPSCode = entity.GPSCode,
                                GPSTypeID = entity.GPSTypeID,
                                InitMileage = entity.InitMileage,
                                LicenceNumber = entity.LicenceNumber,
                                Operator = view.UserName,
                                SIMNo = entity.SIMNo,
                                TenantCode = entity.TenantCode,
                                GroupID = entity.GroupID,
                                VehicleCode = entity.VehicleCode
                            };
                            logService.Insert(vehicleLog);

                            entity.InstallTime = DateTime.Now;
                            service.Update(entity);
                            result.IsSuccess = true;
                        }
                        else
                        {
                            result.IsSuccess = false;
                            result.Message = "GPS设备号长度,不在指定范围内,请重新填写!";
                        }
                    }
                    else
                    {
                        result.IsSuccess = false;
                        result.Message = "GPS设备号已存在,请重新填写!";
                    }
                }
                else
                {
                    service.Update(entity);
                    result.IsSuccess = true;
                }
            }
            catch (Exception ex)
            {
                result.IsSuccess = false;
                result.Message = ex.Message;
            }
            return result;
        }
Esempio n. 2
0
        public DBProcessResult AddVehicle(EMVehicleViewModel view)
        {

            DBProcessResult result = new DBProcessResult();
            try
            {
                EMVehicleService service = new EMVehicleService();
                EHistoryDataStoreConfigService configService = new EHistoryDataStoreConfigService();
                EMGpsTypeService gpsTypeService = new EMGpsTypeService();
                EMVehicleLogService logService = new EMVehicleLogService();
                IdentityNoService noService = new IdentityNoService();

                bool licenceNumberIsExist = service.IsExist(view.TenantCode, view.LicenceNumber);
                if (licenceNumberIsExist)
                {
                    result.IsSuccess = false;
                    result.Message = "已经有相同车牌号的车辆";
                    return result;
                }

                EMVehicle entity = ConvertHelper.ConvertObj<EMVehicleViewModel, EMVehicle>(view);
                EMGpsType gpsTypeEntity = gpsTypeService.Get(entity.GPSTypeID);
                Logger.Info("code line 290: gpsTypeService.Get(entity.GPSTypeID)");
                entity.GPSTypeName = gpsTypeEntity.TypeName;

                bool bo = service.IsExist(view.DeviceNo);
                if (bo != true)
                {
                    //新增车辆历史数据配置
                    string tableName = GetTableNameByCondition(gpsTypeEntity.PrefixCode);
                    EHisotryDataStoreTables table = configService.GetHistoryTable(tableName);
                    Logger.Info("code line 299: configService.GetHistoryTable(tableName)");
                    if (table == null)
                    {
                        result.IsSuccess = false;
                        result.Message = string.Format("找不到对应的历史数据表[{0}],请联系DBA!", tableName);
                        return result;
                    }

                    //新增车辆
                    EnumGPSCodeRule codeType = (EnumGPSCodeRule)gpsTypeEntity.GPSCodeRule;
                    entity.GPSCode = GetGPSCodeHelper.GetGPSCode(gpsTypeEntity.PrefixCode, codeType, entity.SIMNo, entity.DeviceNo);

                    if (entity.DeviceNo.Length == gpsTypeEntity.MachineCodeLength)
                    {
                        entity.CreateTime = DateTime.Now;
                        entity.InstallTime = DateTime.Now;
                        GetVehicleGroupID(entity);    //客户管理中新增车辆时,没有车辆组,默认增加到顶级车辆组
                        service.Insert(entity);

                        EHistoryDataStoreConfig configEntity = new EHistoryDataStoreConfig();
                        configEntity.CreateDate = DateTime.Now;
                        configEntity.Enable = true;
                        configEntity.StoreTable = table;
                        configEntity.VehicleCode = entity.VehicleCode;
                        configService.Insert(configEntity);

                        //新增车辆Log
                        EMVehicleLog vehicleLog = new EMVehicleLog()
                        {
                            BeginDate = DateTime.Now,
                            LogID = noService.GetVehicleLogID(),
                            DeviceNo = entity.DeviceNo,
                            EndDate = null,
                            GPSCode = entity.GPSCode,
                            GPSTypeID = entity.GPSTypeID,
                            InitMileage = entity.InitMileage,
                            LicenceNumber = entity.LicenceNumber,
                            Operator = view.UserName,
                            SIMNo = entity.SIMNo,
                            TenantCode = entity.TenantCode,
                            VehicleCode = entity.VehicleCode,
                            GroupID = entity.GroupID,
                        };
                        logService.Insert(vehicleLog);
                        view.VehicleCode = entity.VehicleCode;
                        result.IsSuccess = true;
                    }
                    else
                    {
                        result.IsSuccess = false;
                        result.Message = "GPS设备号长度,不在指定范围内,请重新填写!";
                    }
                }
                else
                {
                    result.IsSuccess = false;
                    result.Message = "设备号已存在,请重新填写!";
                }
            }
            catch (Exception ex)
            {
                result.IsSuccess = false;
                result.Message = ex.Message;
                Logger.Info(ex.StackTrace + "【" + ex.Message + "】");
            }
            return result;
        }
        public DBProcessResult<int> AddVehicleOperateTran(EMVehicle entity, string sUserName)
        {
            DBProcessResult<int> result = new DBProcessResult<int>();
            try
            {
                VehicleDAL ve = new VehicleDAL();
                IdentityNoService noService = new IdentityNoService();
                bool isLiceNum = ve.IsLicenceNumber(entity.TenantCode, entity.LicenceNumber);
                if (isLiceNum)
                {
                    result.IsSuccess = false;
                    result.Message = "已经有相同车牌号的车辆";
                    result.ReturnValue = -1;
                    return result;
                }
                EMGpsType gpsTypeEntity = ve.GetGpsTypeByGpsTypeId(entity.GPSTypeID);
                entity.GPSTypeName = gpsTypeEntity.TypeName;
                bool isDev = ve.IsDeviceNo(entity.DeviceNo);
                if (isDev != true)
                {
                    //新增车辆历史数据配置
                    string tableName = GetTableNameByCondition(gpsTypeEntity.PrefixCode);
                    EHisotryDataStoreTables table = ve.GetHistoryTable(tableName);

                    if (table == null)
                    {
                        result.IsSuccess = false;
                        result.Message = string.Format("找不到对应的历史数据表[{0}],请联系DBA!", tableName);
                        result.ReturnValue = -1;
                        return result;
                    }
                    //新增车辆
                    EnumGPSCodeRule codeType = (EnumGPSCodeRule)gpsTypeEntity.GPSCodeRule;
                    entity.GPSCode = GetGPSCodeHelper.GetGPSCode(gpsTypeEntity.PrefixCode, codeType, entity.SIMNo, entity.DeviceNo);

                    if (entity.DeviceNo.Length == gpsTypeEntity.MachineCodeLength)
                    {
                        GetVehicleGroupID(entity);    //客户管理中新增车辆时,没有车辆组,默认增加到顶级车辆组
                        
                        EHistoryDataStoreConfig configEntity = new EHistoryDataStoreConfig();
                        configEntity.RecordID = Guid.NewGuid();
                        configEntity.CreateDate = DateTime.Now;
                        configEntity.Enable = true;
                        configEntity.StoreTable = table;
                        configEntity.VehicleCode = entity.VehicleCode;
                       
                        //新增车辆Log
                        EMVehicleLog vehicleLog = new EMVehicleLog()
                        {
                            BeginDate = DateTime.Now,
                            LogID = noService.GetVehicleLogID(),
                            DeviceNo = entity.DeviceNo,
                            EndDate = null,
                            GPSCode = entity.GPSCode,
                            GPSTypeID = entity.GPSTypeID,
                            InitMileage = entity.InitMileage,
                            LicenceNumber = entity.LicenceNumber,
                            Operator = sUserName,
                            SIMNo = entity.SIMNo,
                            TenantCode = entity.TenantCode,
                            VehicleCode = entity.VehicleCode,
                            GroupID = entity.GroupID
                        };
                        var res = ve.AddVehicleOperTrans(entity, configEntity, vehicleLog);

                        result.IsSuccess = res.State;
                        result.Message = res.Msg;
                        result.ReturnValue = new VehicleDAL().SelectCount(entity.TenantCode.ToString());
                    }
                    else
                    {
                        result.IsSuccess = false;
                        result.Message = string.Format(@"GPS设备号长度为{0},请重新填写!", gpsTypeEntity.MachineCodeLength);
                        result.ReturnValue = -1;
                    }
                }
                else
                {
                    result.IsSuccess = false;
                    result.Message = "设备号已存在,请重新填写!";
                    result.ReturnValue = -1;
                }
            }
            catch (Exception ex)
            {
                result.IsSuccess = false;
                result.Message = ex.Message;
                result.ReturnValue = -1;
                Logger.Error("VehicleManagerWCFService.AddVehicleOperateTran(EMVehicle entity, string sUserName);" + ex.Message, ex);
            }
            return result;
            
        }
        public DBProcessResult AddVehicleOperate(EMVehicle entity, string sUserName)
        {
            DBProcessResult result = new DBProcessResult();
            try
            {
                VehicleDAL ve = new VehicleDAL();
                IdentityNoService noService = new IdentityNoService();
                bool isLiceNum = ve.IsLicenceNumber(entity.TenantCode, entity.LicenceNumber);
                if (isLiceNum)
                {
                    result.IsSuccess = false;
                    result.Message = "已经有相同车牌号的车辆";
                    return result;
                }

                //EMVehicle entity = ConvertHelper.ConvertObj<EMVehicleViewModel, EMVehicle>(view);
                EMGpsType gpsTypeEntity = ve.GetGpsTypeByGpsTypeId(entity.GPSTypeID);
                entity.GPSTypeName = gpsTypeEntity.TypeName;
                bool isDev = ve.IsDeviceNo(entity.DeviceNo);
                if (isDev != true)
                {
                    //新增车辆历史数据配置
                    string tableName = GetTableNameByCondition(gpsTypeEntity.PrefixCode);
                    EHisotryDataStoreTables table = ve.GetHistoryTable(tableName);
                    
                    if (table == null)
                    {
                        result.IsSuccess = false;
                        result.Message = string.Format("找不到对应的历史数据表[{0}],请联系DBA!", tableName);
                        return result;
                    }
                    //新增车辆
                    EnumGPSCodeRule codeType = (EnumGPSCodeRule)gpsTypeEntity.GPSCodeRule;
                    entity.GPSCode = GetGPSCodeHelper.GetGPSCode(gpsTypeEntity.PrefixCode, codeType, entity.SIMNo, entity.DeviceNo);

                    if (entity.DeviceNo.Length == gpsTypeEntity.MachineCodeLength)
                    {
                        GetVehicleGroupID(entity);    //客户管理中新增车辆时,没有车辆组,默认增加到顶级车辆组
                        Logger.Info("新增车辆: " + entity.LicenceNumber + "开始");
                        ve.AddVehicle(entity);
                        Logger.Info("新增车辆: " + entity.LicenceNumber + "结束");

                        EHistoryDataStoreConfig configEntity = new EHistoryDataStoreConfig();
                        configEntity.RecordID = Guid.NewGuid();
                        configEntity.CreateDate = DateTime.Now;
                        configEntity.Enable = true;
                        configEntity.StoreTable = table;
                        configEntity.VehicleCode = entity.VehicleCode;
                        Logger.Info("新增车辆 gps_historydatastoreconfig: " + configEntity.StoreTable.TableName + "开始");
                        ve.AddHistoryDataStoreConfig(configEntity);
                        Logger.Info("新增车辆 gps_historydatastoreconfig: " + configEntity.StoreTable.TableName + "结束");

                        //新增车辆Log
                        EMVehicleLog vehicleLog = new EMVehicleLog()
                        {
                            BeginDate = DateTime.Now,
                            LogID = noService.GetVehicleLogID(),
                            DeviceNo = entity.DeviceNo,
                            EndDate = null,
                            GPSCode = entity.GPSCode,
                            GPSTypeID = entity.GPSTypeID,
                            InitMileage = entity.InitMileage,
                            LicenceNumber = entity.LicenceNumber,
                            Operator = sUserName,
                            SIMNo = entity.SIMNo,
                            TenantCode = entity.TenantCode,
                            VehicleCode = entity.VehicleCode,
                            GroupID = entity.GroupID,
                        };
                        Logger.Info("新增车辆 movo_vehiclelog: " + configEntity.StoreTable.TableName + "开始");
                        ve.AddVehicleLog(vehicleLog);
                        Logger.Info("新增车辆 movo_vehiclelog: " + configEntity.StoreTable.TableName + "结束");

                        result.IsSuccess = true;
                    }
                    else
                    {
                        result.IsSuccess = false;
                        result.Message = string.Format(@"GPS设备号长度为{0},请重新填写!", gpsTypeEntity.MachineCodeLength);
                    }
                }
                else
                {
                    result.IsSuccess = false;
                    result.Message = "设备号已存在,请重新填写!";
                }
            }
            catch (Exception ex)
            {
                result.IsSuccess = false;
                result.Message = ex.Message;
                Logger.Info("新增车辆:" + ex.StackTrace + "【" + ex.Message + "】");
            }
            return result;
            
          
        }
Esempio n. 5
0
        /// <summary>
        ///添加movo_vehiclelog 
        /// </summary>
        /// <param name="vlog"></param>
        /// <returns></returns>
        public bool AddVehicleLog(EMVehicleLog vlog)
        {
            string sCmdText = string.Format(@"insert into movo_vehiclelog(LogID,VehicleCode,LicenceNumber,GroupID,GPSTypeID,DeviceNo,SIMNo,GPSCode,TenantCode,BeginDate,EndDate,Operator,InitMileage)
values(@LogID,@VehicleCode,@LicenceNumber,@GroupID,@GPSTypeID,@DeviceNo,@SIMNo,@GPSCode,@TenantCode,@BeginDate,@EndDate,@Operator,@InitMileage)");
            MySqlParameter[] cmdParams = new MySqlParameter[] {
                    new MySqlParameter("LogID",vlog.LogID),
                    new MySqlParameter("VehicleCode",vlog.VehicleCode),
                    new MySqlParameter("LicenceNumber",vlog.LicenceNumber),
                    new MySqlParameter("GroupID",vlog.GroupID),
                    new MySqlParameter("GPSTypeID",vlog.GPSTypeID),
                    new MySqlParameter("DeviceNo",vlog.DeviceNo),
                    new MySqlParameter("SIMNo",vlog.SIMNo),
                    new MySqlParameter("GPSCode",vlog.GPSCode),
                    new MySqlParameter("TenantCode",vlog.TenantCode),
                    new MySqlParameter("BeginDate",vlog.BeginDate),
                    new MySqlParameter("EndDate",vlog.EndDate),
                    new MySqlParameter("Operator",vlog.Operator),
                    new MySqlParameter("InitMileage",vlog.InitMileage)
                  
                };
            int ri = MySqlDB.ExecuteNonQuery(CommandType.Text, sCmdText, cmdParams);
            if (ri > 0)
            {
                return true;
            }
            return false;
        }
Esempio n. 6
0
        /// <summary>
        /// 采用事物添加车辆(movo_vehicle,gps_historydatastoreconfig,movo_vehiclelog)
        /// </summary>
        /// <param name="ve"></param>
        /// <param name="conf"></param>
        /// <param name="vlog"></param>
        /// <returns></returns>
        public ResultEntity AddVehicleOperTrans(EMVehicle ve, EHistoryDataStoreConfig conf, EMVehicleLog vlog)
        {
            ResultEntity res = new ResultEntity();

            MySqlConnection con = new MySqlConnection(MySqlDB.ConnString);
            con.Open();
            MySqlTransaction trans = con.BeginTransaction();
            MySqlCommand cmd = con.CreateCommand();
            cmd.Transaction = trans;
            try
            {
                cmd.CommandText = string.Format(@" insert into movo_vehicle(VehicleCode,LicenceNumber,GroupID,GPSTypeID,DeviceNo,SIMNo,GPSCode,TenantCode,InitMileage,ExpireTime,InstallTime,IsStop,CreateTime,IconType,GPSTypeName)
 values(@VehicleCode,@LicenceNumber,@GroupID,@GPSTypeID,@DeviceNo,@SIMNo,@GPSCode,@TenantCode,@InitMileage,@ExpireTime,@InstallTime,@IsStop,@CreateTime,@IconType,@GPSTypeName)");
                cmd.Parameters.AddRange(new MySqlParameter[] {
                    new MySqlParameter("VehicleCode", ve.VehicleCode ),
                    new MySqlParameter("LicenceNumber", ve.LicenceNumber),
                    new MySqlParameter("GroupID", ve.GroupID),
                    new MySqlParameter("GPSTypeID", ve.GPSTypeID),
                    new MySqlParameter("DeviceNo", ve.DeviceNo),
                    new MySqlParameter("SIMNo", ve.SIMNo),
                    new MySqlParameter("GPSCode", ve.GPSCode),
                    new MySqlParameter("TenantCode", ve.TenantCode),
                    new MySqlParameter("InitMileage",ve.InitMileage ),
                    new MySqlParameter("ExpireTime", ve.ExpireTime),
                    new MySqlParameter("InstallTime", ve.InstallTime),
                    new MySqlParameter("IsStop", ve.IsStop),
                    new MySqlParameter("CreateTime", ve.CreateTime),
                    new MySqlParameter("IconType", ve.IconType),
                    new MySqlParameter("GPSTypeName", ve.GPSTypeName)
                });
                int veCount = cmd.ExecuteNonQuery();
                cmd.Parameters.Clear();
                if (veCount < 1)
                {
                    trans.Rollback();
                    res.State = false;
                    res.Msg = "车辆表【movo_vehicle】新增失败";
                    return res;
                }

                cmd.CommandText = string.Format(@"insert into gps_historydatastoreconfig(RecordID,VehicleCode,StoreTable,Enable,CreateDate,remark)
 values(@RecordIDconf,@VehicleCodeconf,@StoreTableconf,@Enableconf,@CreateDateconf,@remarkconf)");
                cmd.Parameters.AddRange(new MySqlParameter[] {
                    new MySqlParameter("RecordIDconf", conf.RecordID),
                    new MySqlParameter("VehicleCodeconf", conf.VehicleCode),
                    new MySqlParameter("StoreTableconf", conf.StoreTable.RecordID),
                    new MySqlParameter("Enableconf", conf.Enable),
                    new MySqlParameter("CreateDateconf", conf.CreateDate),
                    new MySqlParameter("remarkconf", conf.Remark)
                   
                });
                int confCount = cmd.ExecuteNonQuery();
                cmd.Parameters.Clear();
                if (confCount < 1)
                {
                    trans.Rollback();
                    res.State = false;
                    res.Msg = "车辆历史数据配置表【gps_historydatastoreconfig】新增失败";
                    return res;
                }

                cmd.CommandText = string.Format(@"insert into movo_vehiclelog(LogID,VehicleCode,LicenceNumber,GroupID,GPSTypeID,DeviceNo,SIMNo,GPSCode,TenantCode,BeginDate,EndDate,Operator,InitMileage)
 values(@LogID,@VehicleCodelog,@LicenceNumberlog,@GroupIDlog,@GPSTypeIDlog,@DeviceNolog,@SIMNolog,@GPSCodelog,@TenantCodelog,@BeginDatelog,@EndDatelog,@Operatorlog,@InitMileagelog)");
                cmd.Parameters.AddRange(new MySqlParameter[] {
                    new MySqlParameter("LogID", vlog.LogID),
                    new MySqlParameter("VehicleCodelog", vlog.VehicleCode),
                    new MySqlParameter("LicenceNumberlog", vlog.LicenceNumber),
                    new MySqlParameter("GroupIDlog", vlog.GroupID),
                    new MySqlParameter("GPSTypeIDlog", vlog.GPSTypeID),
                    new MySqlParameter("DeviceNolog", vlog.DeviceNo),
                    new MySqlParameter("SIMNolog", vlog.SIMNo),
                    new MySqlParameter("GPSCodelog", vlog.GPSCode),
                    new MySqlParameter("TenantCodelog", vlog.TenantCode),
                    new MySqlParameter("BeginDatelog", vlog.BeginDate),
                    new MySqlParameter("EndDatelog", vlog.EndDate),
                    new MySqlParameter("Operatorlog", vlog.Operator),
                    new MySqlParameter("InitMileagelog", vlog.InitMileage)
                  
                });
                int logCount = cmd.ExecuteNonQuery();
                cmd.Parameters.Clear();

                if (logCount < 1)
                {
                    trans.Rollback();
                    res.State = false;
                    res.Msg = "车辆操作日志表【movo_vehiclelog】新增失败";
                    return res;
                }
                trans.Commit();
                res.State = true;
                res.Msg = "新增车辆成功";
            }
            catch (Exception ex)
            {
                trans.Rollback();
                res.State = false;
                res.Msg = "新增车辆失败," + ex.Message;
            }
            finally
            {
                con.Close();
            }
            return res;
        }