/// <summary> /// Сохранение заявки /// </summary> /// <param name="firstState">Передается если нужно чтобы заявка сохранилась с другим первым статусом</param> /// <returns></returns> public int Save(ClaimState firstState = null) { bool isNew = Id == 0; //if (State == null) State = ClaimState.GetFirstState(); //if (Admin == null) Admin = new EmployeeSm(); //if (Engeneer == null) Engeneer = new EmployeeSm(); if (Contract == null) { Contract = new Contract(); } else if (Contract.Id > 0) { IdContract = Contract.Id; } if (Contractor == null) { Contractor = new Contractor(); } else if (Contractor.Id > 0) { IdContractor = Contractor.Id; } if (Device == null) { Device = new Device(); } else if (Device.Id > 0) { IdDevice = Device.Id; } if (isNew && IdContractor > 0 && IsNullOrEmpty(ContractorName))//Загрузка названия контрагента из Эталон { Contractor = new Contractor(IdContractor); ContractorName = Contractor.Name; } if (isNew && String.IsNullOrEmpty(CurAdminSid)) { CurAdminSid = Device.GetCurServiceAdminSid(IdDevice, IdContract); } //string wtReplace = "%work_type%"; //if (Descr.IndexOf(wtReplace, StringComparison.Ordinal) > 0) //{ // var wt = new WorkType(IdWorkType); // Descr = Descr.Replace(wtReplace, $"{wt.SysName} ({wt.Name})"); //} if (isNew) { CurManagerSid = CurUserAdSid; if (IdDevice > 0) Device = new Device(IdDevice); } SqlParameter pId = new SqlParameter() { ParameterName = "id", SqlValue = Id, SqlDbType = SqlDbType.Int }; SqlParameter pIdContractor = new SqlParameter() { ParameterName = "id_contractor", SqlValue = IdContractor, SqlDbType = SqlDbType.Int }; SqlParameter pIdContract = new SqlParameter() { ParameterName = "id_contract", SqlValue = IdContract, SqlDbType = SqlDbType.Int }; SqlParameter pIdDevice = new SqlParameter() { ParameterName = "id_device", SqlValue = IdDevice, SqlDbType = SqlDbType.Int }; SqlParameter pContractorName = new SqlParameter() { ParameterName = "contractor_name", SqlValue = ContractorName, SqlDbType = SqlDbType.NVarChar }; SqlParameter pContractName = new SqlParameter() { ParameterName = "contract_number", SqlValue = ContractName, SqlDbType = SqlDbType.NVarChar }; SqlParameter pDeviceName = new SqlParameter() { ParameterName = "device_name", SqlValue = DeviceName, SqlDbType = SqlDbType.NVarChar }; //SqlParameter pIdAdmin = new SqlParameter() { ParameterName = "id_admin", SqlValue = Admin.Id, SqlDbType = SqlDbType.Int }; //SqlParameter pIdEngeneer = new SqlParameter() { ParameterName = "id_engeneer", SqlValue = Engeneer.Id, SqlDbType = SqlDbType.Int }; //Статус сохраняем отдельной процедурой так как надо хранить историю //SqlParameter pIdClaimState = new SqlParameter() { ParameterName = "id_claim_state", SqlValue = State.Id, SqlDbType = SqlDbType.Int }; SqlParameter pIdWorkType = new SqlParameter() { ParameterName = "id_work_type", SqlValue = IdWorkType, SqlDbType = SqlDbType.Int }; SqlParameter pCreatorAdSid = new SqlParameter() { ParameterName = "creator_sid", SqlValue = CurUserAdSid, SqlDbType = SqlDbType.VarChar }; SqlParameter pSpecialistSid = new SqlParameter() { ParameterName = "specialist_sid", SqlValue = SpecialistSid, SqlDbType = SqlDbType.VarChar }; SqlParameter pClientSdNum = new SqlParameter() { ParameterName = "client_sd_num", SqlValue = ClientSdNum, SqlDbType = SqlDbType.NVarChar }; SqlParameter pEngeneerSid = new SqlParameter() { ParameterName = "cur_engeneer_sid", SqlValue = CurEngeneerSid, SqlDbType = SqlDbType.VarChar }; SqlParameter pAdminSid = new SqlParameter() { ParameterName = "cur_admin_sid", SqlValue = CurAdminSid, SqlDbType = SqlDbType.VarChar }; SqlParameter pTechSid = new SqlParameter() { ParameterName = "cur_tech_sid", SqlValue = CurTechSid, SqlDbType = SqlDbType.VarChar }; SqlParameter pManagerSid = new SqlParameter() { ParameterName = "cur_manager_sid", SqlValue = CurManagerSid, SqlDbType = SqlDbType.VarChar }; SqlParameter pSerialNum = new SqlParameter() { ParameterName = "serial_num", SqlValue = Device.SerialNum, SqlDbType = SqlDbType.NVarChar }; SqlParameter pCurServiceIssueId = new SqlParameter() { ParameterName = "cur_service_issue_id", SqlValue = CurServiceIssueId, SqlDbType = SqlDbType.Int }; SqlParameter pIdServiceCame = new SqlParameter() { ParameterName = "id_service_came", SqlValue = IdServiceCame, SqlDbType = SqlDbType.Int }; DataTable dt = new DataTable(); //using (var conn = Db.Service.connection) //{ // if (conn.State == ConnectionState.Closed) conn.Open(); // using (SqlTransaction tran = conn.BeginTransaction()) // { // try // { //Если заявка уже сохранена то основная информаци не будет перезаписана dt = Db.Service.ExecuteQueryStoredProcedure("save_claim", pId, pIdContractor, pIdContract, pIdDevice, pContractorName, pContractName, pDeviceName, /*pIdAdmin, pIdEngeneer,*/ pCreatorAdSid, pIdWorkType, pSpecialistSid, pClientSdNum, pEngeneerSid, pAdminSid, pTechSid, pManagerSid, pSerialNum, pCurServiceIssueId, pIdServiceCame); int id = 0; if (dt.Rows.Count > 0) { int.TryParse(dt.Rows[0]["id"].ToString(), out id); } if (isNew) { Id = id; var st = firstState ?? ClaimState.GetFirstState(); SaveStateStep(st.Id, Descr); } Id = id; ////////Сохранение статуса заявки, может быть передан новый статус тогда сохраняем с новым статусом //////if (Id > 0) //////{ ////// int stateId = 0; ////// if (nextStateId.HasValue) ////// { ////// stateId = nextStateId.Value; ////// } ////// else ////// { ////// stateId = GetClaimCurrentState(Id).Id; ////// } ////// if (stateId > 0) SaveStateStep(stateId, sysDescr, saveStateInfo); //////} return Id; }
private void FillSelf(DataRow row, bool fillObj = false, bool fillNames = false) { Id = Db.DbHelper.GetValueIntOrDefault(row, "id"); IdClaim = Db.DbHelper.GetValueIntOrDefault(row, "id_claim"); IdClaim2ClaimState = Db.DbHelper.GetValueIntOrDefault(row, "id_claim2claim_state"); ProcessEnabled = Db.DbHelper.GetValueBool(row, "process_enabled"); DeviceEnabled = Db.DbHelper.GetValueBool(row, "device_enabled"); ZipClaim = Db.DbHelper.GetValueBoolOrNull(row, "zip_claim"); ZipClaimNumber = Db.DbHelper.GetValueString(row, "zip_claim_number"); CounterMono = Db.DbHelper.GetValueIntOrNull(row, "counter_mono"); CounterColor = Db.DbHelper.GetValueIntOrNull(row, "counter_color"); CounterTotal = Db.DbHelper.GetValueIntOrNull(row, "counter_total"); NoCounter = Db.DbHelper.GetValueBoolOrNull(row, "no_counter"); Descr = Db.DbHelper.GetValueString(row, "descr"); CounterUnavailable = Db.DbHelper.GetValueBoolOrNull(row, "counter_unavailable"); CounterDescr = Db.DbHelper.GetValueString(row, "counter_descr"); CreatorSid = Db.DbHelper.GetValueString(row, "creator_sid"); EngeneerSid = Db.DbHelper.GetValueString(row, "engeneer_sid"); AdminSid = Db.DbHelper.GetValueString(row, "admin_sid"); DeviceId = Db.DbHelper.GetValueIntOrDefault(row, "id_device"); WorkTypeId = Db.DbHelper.GetValueIntOrDefault(row, "id_work_type"); TimeOnWorkMinutes = Db.DbHelper.GetValueIntOrNull(row, "time_on_work_minutes"); ClientSdNum = Db.DbHelper.GetValueString(row, "client_sd_num"); DateCreate = Db.DbHelper.GetValueDateTimeOrDefault(row, "date_create"); if (fillNames) { Admin = new EmployeeSm(AdminSid); Engeneer = new EmployeeSm(EngeneerSid); Creator = new EmployeeSm(CreatorSid); } if (fillObj) { Device = new Device(DeviceId); WorkType = new WorkType(WorkTypeId); DeviceClassifierCaterory = new ClassifierCaterory(Device.ClassifierCategoryId); } }
private void FillSelf(DataRow row, bool loadObj = true, bool loadNames = false) { Sid = Db.DbHelper.GetValueString(row, "sid"); Id = Db.DbHelper.GetValueIntOrDefault(row, "id"); IdContractor = Db.DbHelper.GetValueIntOrDefault(row, "id_contractor"); IdContract = Db.DbHelper.GetValueIntOrDefault(row, "id_contract"); IdDevice = Db.DbHelper.GetValueIntOrDefault(row, "id_device"); ContractorName = Db.DbHelper.GetValueString(row, "contractor_name"); ContractName = Db.DbHelper.GetValueString(row, "contract_name"); DeviceName = Db.DbHelper.GetValueString(row, "device_name"); IdWorkType = Db.DbHelper.GetValueIntOrNull(row, "id_work_type"); SpecialistSid = Db.DbHelper.GetValueString(row, "specialist_sid"); DateCreate = Db.DbHelper.GetValueDateTimeOrDefault(row, "date_create"); DateStateChange = Db.DbHelper.GetValueDateTimeOrDefault(row, "date_state_change"); ClientSdNum = Db.DbHelper.GetValueString(row, "client_sd_num"); ChangerSid = Db.DbHelper.GetValueString(row, "changer_sid"); CurEngeneerSid = Db.DbHelper.GetValueString(row, "cur_engeneer_sid"); CurAdminSid = Db.DbHelper.GetValueString(row, "cur_admin_sid"); CurTechSid = Db.DbHelper.GetValueString(row, "cur_tech_sid"); CurManagerSid = Db.DbHelper.GetValueString(row, "cur_manager_sid"); CurServiceIssueId = Db.DbHelper.GetValueIntOrNull(row, "cur_service_issue_id"); IdServiceCame = Db.DbHelper.GetValueIntOrNull(row, "id_service_came"); IdState = Db.DbHelper.GetValueIntOrDefault(row, "id_claim_state"); Contractor = new Contractor() { Id = Db.DbHelper.GetValueIntOrDefault(row, "id_contractor"), Name = Db.DbHelper.GetValueString(row, "contractor_name"), FullName = Db.DbHelper.GetValueString(row, "contractor_full_name") }; Contract = new Contract() { Id = Db.DbHelper.GetValueIntOrDefault(row, "id_contract"), Number = Db.DbHelper.GetValueString(row, "contract_num") }; Device = new Device() { Id = Db.DbHelper.GetValueIntOrDefault(row, "id_device"), FullName = Db.DbHelper.GetValueString(row, "device_name"), SerialNum = Db.DbHelper.GetValueString(row, "device_serial_num"), ObjectName = Db.DbHelper.GetValueString(row, "object_name"), Address = Db.DbHelper.GetValueString(row, "address"), ContactName = Db.DbHelper.GetValueString(row, "contact_name"), Descr = Db.DbHelper.GetValueString(row, "c2d_comment"), CityName = Db.DbHelper.GetValueString(row, "city_name") }; Manager = new EmployeeSm() { AdSid = CurManagerSid , DisplayName = Db.DbHelper.GetValueString(row, "manager_name") }; Admin = new EmployeeSm() { AdSid = CurAdminSid, DisplayName = Db.DbHelper.GetValueString(row, "admin_name") }; Tech = new EmployeeSm() { AdSid = CurTechSid, DisplayName = Db.DbHelper.GetValueString(row, "tech_name") }; Engeneer = new EmployeeSm() { AdSid = CurEngeneerSid, DisplayName = Db.DbHelper.GetValueString(row, "engeneer_name") }; Specialist = new EmployeeSm() { AdSid = SpecialistSid, DisplayName = Db.DbHelper.GetValueString(row, "specialist_name") }; Changer = new EmployeeSm() { AdSid = ChangerSid, DisplayName = Db.DbHelper.GetValueString(row, "specialist_name") }; if (IdWorkType.HasValue && IdWorkType.Value > 0) WorkType = new WorkType() {Id= IdWorkType.Value, Name = Db.DbHelper.GetValueString(row, "work_type_name"), SysName = Db.DbHelper.GetValueString(row, "work_type_sys_name"), ZipInstall = Db.DbHelper.GetValueBool(row, "work_type_zip_install"), ZipOrder = Db.DbHelper.GetValueBool(row, "work_type_zip_order") }; State = new ClaimState() {Id=IdState, Name = Db.DbHelper.GetValueString(row, "claim_state_name"), SysName = Db.DbHelper.GetValueString(row, "claim_state_sys_name"), BackgroundColor = Db.DbHelper.GetValueString(row, "claim_state_background_color"), ForegroundColor = Db.DbHelper.GetValueString(row, "claim_state_foreground_color") }; if (loadObj) { Contractor = new Contractor(Contractor.Id); Contract = new Contract(Contract.Id); Device = new Device(Device.Id, Contract.Id); if (IdWorkType.HasValue && IdWorkType.Value > 0) WorkType = new WorkType(IdWorkType.Value); State = new ClaimState(Db.DbHelper.GetValueIntOrDefault(row, "id_claim_state")); } if (loadNames) { Manager = new EmployeeSm(CurManagerSid); Admin = new EmployeeSm(CurAdminSid); Tech = new EmployeeSm(CurTechSid); Engeneer = new EmployeeSm(CurEngeneerSid); Specialist = new EmployeeSm(SpecialistSid); Changer = new EmployeeSm(ChangerSid); } }
public static IEnumerable<Device> GetList(int? idContractor = null, string contractorName = null, int? idContract = null, string contractNumber = null, int? idDevice = null, string deviceName = null, string serialNum = null) { //if (idContractor.HasValue) contractorName = null; //if (idContract.HasValue) contractNumber = null; //if (idDevice.HasValue) deviceName = null; SqlParameter pId = new SqlParameter() { ParameterName = "id_contractor", SqlValue = idContractor, SqlDbType = SqlDbType.Int }; SqlParameter pName = new SqlParameter() { ParameterName = "contractor_name", SqlValue = contractorName, SqlDbType = SqlDbType.NVarChar }; SqlParameter pIdContract = new SqlParameter() { ParameterName = "id_contract", SqlValue = idContract, SqlDbType = SqlDbType.Int }; SqlParameter pContractNumber = new SqlParameter() { ParameterName = "contract_number", SqlValue = contractNumber, SqlDbType = SqlDbType.NVarChar }; SqlParameter pIdDevice = new SqlParameter() { ParameterName = "id_device", SqlValue = idDevice, SqlDbType = SqlDbType.Int }; SqlParameter pDeviceName = new SqlParameter() { ParameterName = "device_name", SqlValue = deviceName, SqlDbType = SqlDbType.NVarChar }; SqlParameter pSerialNum = new SqlParameter() { ParameterName = "serial_num", SqlValue = serialNum, SqlDbType = SqlDbType.NVarChar }; var dt = Db.UnitProg.ExecuteQueryStoredProcedure("get_device_list", pId, pName, pIdContract, pContractNumber, pIdDevice, pDeviceName, pSerialNum); var lst = new List<Device>(); foreach (DataRow row in dt.Rows) { var model = new Device(row); lst.Add(model); } return lst; }
private void FillSelf(DataRow row, bool loadObj = true) { Sid = Db.DbHelper.GetValueString(row, "sid"); Id = Db.DbHelper.GetValueIntOrDefault(row, "id"); IdContractor = Db.DbHelper.GetValueIntOrDefault(row, "id_contractor"); IdContract = Db.DbHelper.GetValueIntOrDefault(row, "id_contract"); IdDevice = Db.DbHelper.GetValueIntOrDefault(row, "id_device"); ContractorName = Db.DbHelper.GetValueString(row, "contractor_name"); ContractName = Db.DbHelper.GetValueString(row, "contract_name"); DeviceName = Db.DbHelper.GetValueString(row, "device_name"); //Admin = new EmployeeSm(Db.DbHelper.GetValueIntOrDefault(row, "id_admin")); //Engeneer = new EmployeeSm(Db.DbHelper.GetValueIntOrDefault(row, "id_engeneer")); IdWorkType = Db.DbHelper.GetValueIntOrNull(row, "id_work_type"); SpecialistSid = Db.DbHelper.GetValueString(row, "specialist_sid"); DateCreate = Db.DbHelper.GetValueDateTimeOrDefault(row, "date_create"); DateStateChange = Db.DbHelper.GetValueDateTimeOrDefault(row, "date_state_change"); ClientSdNum = Db.DbHelper.GetValueString(row, "client_sd_num"); ChangerSid = Db.DbHelper.GetValueString(row, "changer_sid"); CurEngeneerSid = Db.DbHelper.GetValueString(row, "cur_engeneer_sid"); CurAdminSid = Db.DbHelper.GetValueString(row, "cur_admin_sid"); CurTechSid = Db.DbHelper.GetValueString(row, "cur_tech_sid"); CurManagerSid = Db.DbHelper.GetValueString(row, "cur_manager_sid"); CurServiceIssueId = Db.DbHelper.GetValueIntOrNull(row, "cur_service_issue_id"); IdServiceCame = Db.DbHelper.GetValueIntOrNull(row, "id_service_came"); if (loadObj) { if (IdWorkType.HasValue && IdWorkType.Value > 0) WorkType = new WorkType(IdWorkType.Value); Specialist = new EmployeeSm(SpecialistSid); State = new ClaimState(Db.DbHelper.GetValueIntOrDefault(row, "id_claim_state")); Contractor = new Contractor() { Id = Db.DbHelper.GetValueIntOrDefault(row, "id_contractor") }; Contract = new Contract() { Id = Db.DbHelper.GetValueIntOrDefault(row, "id_contract") }; Device = new Device() { Id = Db.DbHelper.GetValueIntOrDefault(row, "id_device") }; } }
private void GetNames() { Contractor = new Contractor(Contractor.Id); Contract = new Contract(Contract.Id); Device = new Device(Device.Id); }
public static void CreateClaimUnitWork(int idClaim, string creatorSid) { var claim = new Claim(idClaim, true, true); var device = new Device(claim.IdDevice, claim.IdContract); var lastServiceSheet = claim.GetLastServiceSheet(); var zipItemList = lastServiceSheet.GetOrderedZipItemList(null); if (zipItemList.Any())//Если ЗИПа нет то заявка не создается { var zipClaim = new ZipClaim(); zipClaim.IdDevice = claim.IdDevice; zipClaim.SerialNum = claim.Device.SerialNum; zipClaim.DeviceModel = claim.Device.ModelName; zipClaim.Contractor = claim.ContractorName; zipClaim.IdCity = device.IdCity; zipClaim.City = device.CityName; zipClaim.Address = device.Address; zipClaim.Descr = "Заявка создана автоматически из системы Сервис"; zipClaim.Counter = lastServiceSheet.CounterMono; zipClaim.CounterColour = lastServiceSheet.CounterColor; zipClaim.IdContractor = claim.IdContractor; zipClaim.IdServiceEngeneer = UserUnitProg.GetUserId(lastServiceSheet.EngeneerSid); zipClaim.IdEngeneerConclusion = lastServiceSheet.DeviceEnabled ? 1 : 2; zipClaim.IdManager = claim.Contract.ManagerIdUnitProg; zipClaim.IdServiceAdmin = UserUnitProg.GetUserId(lastServiceSheet.AdminSid); zipClaim.ServiceDeskNum = claim.Id.ToString(); zipClaim.ObjectName = device.ObjectName; zipClaim.ContractNum = claim.Contract.Number; zipClaim.ContractType = claim.Contract.TypeName; zipClaim.ContractorSdNum = claim.ClientSdNum; zipClaim.ServiceIdServSheet = lastServiceSheet.Id.ToString(); zipClaim.ServiceIdClaim = claim.Id.ToString(); zipClaim.CurUserAdSid = creatorSid; zipClaim.SaveUnitProg(); if (zipItemList != null && zipItemList.Any()) { foreach (var item in zipItemList) { item.ClaimId = zipClaim.Id; item.CurUserAdSid = creatorSid; item.SaveUnitProg(); } } zipClaim.SetSendStateUnitProg(); lastServiceSheet.UnitProgZipClaimId = zipClaim.Id; lastServiceSheet.SaveUnitProgZipClaimId(); lastServiceSheet.CurUserAdSid = creatorSid; lastServiceSheet.SetOrderedZipItemListRealyOrdered(); } }