public bool CreateNewService(FuneralServiceModel newService) { int nextOrderNumber = GetNextOrderNumber(); using (var dbConnection = new SQLiteConnection(AppConfiguration.ConnectionString)) { dbConnection.Open(); string createNewServiceCommand = @"INSERT INTO 'FuneralServiceHistory' VALUES ( @OrderNumber, @OrderCreationYear, @OrderDate, @CustomerNames, @CustomerPhoneNumbers, @CustomerEmails, @CustomerAddresses, @ServiceDates, @ServicePlaces, @ServiceTypes, @ServiceDuration, @ServiceMusiciansCount, @ServiceMusicProgram, @DepartedInfo, @DepartedConfession, @DepartedRemainsType, @ServiceMusicianUnitPrices, @ServiceDiscountPercentage, @ServicePaymentAmount, @ServicePaymentType, @ServiceDescription )"; object queryParameters = new { OrderNumber = nextOrderNumber, OrderCreationYear = DateTime.Now.Year, newService.OrderDate, newService.CustomerNames, newService.CustomerPhoneNumbers, newService.CustomerEmails, newService.CustomerAddresses, newService.ServiceDates, newService.ServicePlaces, newService.ServiceTypes, newService.ServiceDuration, newService.ServiceMusiciansCount, newService.ServiceMusicProgram, newService.DepartedInfo, newService.DepartedConfession, newService.DepartedRemainsType, newService.ServiceMusicianUnitPrices, newService.ServiceDiscountPercentage, newService.ServicePaymentAmount, newService.ServicePaymentType, newService.ServiceDescription }; int affectedRows = dbConnection.Execute(createNewServiceCommand, queryParameters); return(affectedRows == 1); } }
public FuneralServiceModel GetExistingService(int orderNumber, int orderCreationYear) { using (var dbConnection = new SQLiteConnection(AppConfiguration.ConnectionString)) { dbConnection.Open(); string getExistingServiceQuery = @"SELECT FSH.OrderDate , FSH.CustomerNames , FSH.CustomerPhoneNumbers , FSH.CustomerEmails , FSH.CustomerAddresses , FSH.ServiceDates , FSH.ServicePlaces , FSH.ServiceTypes , FSH.ServiceDuration , FSH.ServiceMusiciansCount , FSH.ServiceMusicProgram, FSH.DepartedInfo , FSH.DepartedConfession , FSH.DepartedRemainsType , FSH.ServiceMusicianUnitPrices , FSH.ServiceDiscountPercentage , FSH.ServicePaymentAmount , FSH.ServicePaymentType , FSH.ServiceDescription FROM FuneralServiceHistory FSH WHERE FSH.OrderNumber = @OrderNumber AND OrderCreationYear = @OrderCreationYear"; object queryParameters = new { OrderNumber = orderNumber, OrderCreationYear = orderCreationYear }; FuneralServiceModel funeralService = dbConnection.QuerySingle <FuneralServiceModel>(getExistingServiceQuery, queryParameters); return(funeralService); } }
private void LoadFormDataForEditOrCopy() { if (_funeralServiceOperation == FuneralServiceOperation.Edit || _funeralServiceOperation == FuneralServiceOperation.Copy) { FuneralServiceModel funeralServiceModel = _funeralServiceRepository.GetExistingService(_selectedOrderNumber.Value, _selectedOrderCreationYear.Value); OrderDateTextBox.Text = funeralServiceModel.OrderDate.ToString(OrderDateFormat); CustomerNamesRichTextBox.Text = funeralServiceModel.CustomerNames; CustomerPhoneNumbersRichTextBox.Text = funeralServiceModel.CustomerPhoneNumbers; CustomerEmailsRichTextBox.Text = funeralServiceModel.CustomerEmails; CustomerAddressesRichTextBox.Text = funeralServiceModel.CustomerAddresses; ServiceDatesRichTextBox.Text = funeralServiceModel.ServiceDates; ServicePlacesRichTextBox.Text = funeralServiceModel.ServicePlaces; ServiceTypesRichTextBox.Text = funeralServiceModel.ServiceTypes; ServiceDurationRichTextBox.Text = funeralServiceModel.ServiceDuration; ServiceMusiciansCountRichTextBox.Text = funeralServiceModel.ServiceMusiciansCount; ServiceMusicProgramRichTextBox.Text = funeralServiceModel.ServiceMusicProgram; DepartedInfoRichTextBox.Text = funeralServiceModel.DepartedInfo; DepartedConfessionRichTextBox.Text = funeralServiceModel.DepartedConfession; DepartedRemainsTypeRichTextBox.Text = funeralServiceModel.DepartedRemainsType; ServiceMusicianUnitPricesRichTextBox.Text = funeralServiceModel.ServiceMusicianUnitPrices; ServiceDiscountPercentageRichTextBox.Text = funeralServiceModel.ServiceDiscountPercentage; ServicePaymentAmountRichTextBox.Text = funeralServiceModel.ServicePaymentAmount; ServicePaymentTypeRichTextBox.Text = funeralServiceModel.ServicePaymentType; ServiceDescriptionRichTextBox.Text = funeralServiceModel.ServiceDescription; } }
private void SaveFuneralServiceChangesButton_Click(object sender, EventArgs e) { var funeralServiceModel = new FuneralServiceModel { OrderDate = DateTime.ParseExact(OrderDateTextBox.Text, OrderDateFormat, CultureInfo.InvariantCulture), CustomerNames = CustomerNamesRichTextBox.Text, CustomerPhoneNumbers = CustomerPhoneNumbersRichTextBox.Text, CustomerEmails = CustomerEmailsRichTextBox.Text, CustomerAddresses = CustomerAddressesRichTextBox.Text, ServiceDates = ServiceDatesRichTextBox.Text, ServicePlaces = ServicePlacesRichTextBox.Text, ServiceTypes = ServiceTypesRichTextBox.Text, ServiceDuration = ServiceDurationRichTextBox.Text, ServiceMusiciansCount = ServiceMusiciansCountRichTextBox.Text, ServiceMusicProgram = ServiceMusicProgramRichTextBox.Text, DepartedInfo = DepartedInfoRichTextBox.Text, DepartedConfession = DepartedConfessionRichTextBox.Text, DepartedRemainsType = DepartedRemainsTypeRichTextBox.Text, ServiceMusicianUnitPrices = ServiceMusicianUnitPricesRichTextBox.Text, ServiceDiscountPercentage = ServiceDiscountPercentageRichTextBox.Text, ServicePaymentAmount = ServicePaymentAmountRichTextBox.Text, ServicePaymentType = ServicePaymentTypeRichTextBox.Text, ServiceDescription = ServiceDescriptionRichTextBox.Text }; bool success; string successMessage; if (_funeralServiceOperation == FuneralServiceOperation.Edit) { success = _funeralServiceRepository.UpdateExistingService(_selectedOrderNumber.Value, _selectedOrderCreationYear.Value, funeralServiceModel); successMessage = "Pakeitimai išsaugoti sėkmingai."; } else { success = _funeralServiceRepository.CreateNewService(funeralServiceModel); successMessage = "Naujas įrašas sukurtas sekmingai."; } if (success) { ShowInformationDialog(successMessage); this.Close(); } else { ShowErrorDialog("Nepavyko išsaugoti pakeitimų, bandykite dar kart!"); } }
public bool UpdateExistingService(int orderNumber, int orderCreationYear, FuneralServiceModel updatedService) { using (var dbConnection = new SQLiteConnection(AppConfiguration.ConnectionString)) { dbConnection.Open(); string updateExistingServiceCommand = @"UPDATE 'FuneralServiceHistory' SET OrderDate = @OrderDate, CustomerNames = @CustomerNames , CustomerPhoneNumbers = @CustomerPhoneNumbers , CustomerEmails = @CustomerEmails, CustomerAddresses = @CustomerAddresses, ServiceDates = @ServiceDates, ServicePlaces = @ServicePlaces, ServiceTypes = @ServiceTypes, ServiceDuration = @ServiceDuration, ServiceMusiciansCount = @ServiceMusiciansCount, ServiceMusicProgram = @ServiceMusicProgram, DepartedInfo = @DepartedInfo, DepartedConfession = @DepartedConfession, DepartedRemainsType = @DepartedRemainsType, ServiceMusicianUnitPrices = @ServiceMusicianUnitPrices, ServiceDiscountPercentage = @ServiceDiscountPercentage, ServicePaymentAmount = @ServicePaymentAmount, ServicePaymentType = @ServicePaymentType, ServiceDescription = @ServiceDescription WHERE OrderNumber = @OrderNumber AND OrderCreationYear = @OrderCreationYear"; object queryParameters = new { updatedService.OrderDate, updatedService.CustomerNames, updatedService.CustomerPhoneNumbers, updatedService.CustomerEmails, updatedService.CustomerAddresses, updatedService.ServiceDates, updatedService.ServicePlaces, updatedService.ServiceTypes, updatedService.ServiceDuration, updatedService.ServiceMusiciansCount, updatedService.ServiceMusicProgram, updatedService.DepartedInfo, updatedService.DepartedConfession, updatedService.DepartedRemainsType, updatedService.ServiceMusicianUnitPrices, updatedService.ServiceDiscountPercentage, updatedService.ServicePaymentAmount, updatedService.ServicePaymentType, updatedService.ServiceDescription, OrderNumber = orderNumber, OrderCreationYear = orderCreationYear }; int affectedRows = dbConnection.Execute(updateExistingServiceCommand, queryParameters); return(affectedRows == 1); } }