//Crystal View DataSourch public DataTable CristalReportDataSourch(Telerik.Windows.Controls.RadGridView radgridview, DataTable tempDataTable, Variables.OperationTrypes oprationType) { string txtline = string.Empty; NecessaryFunction necessaryElement = new NecessaryFunction(); GridViewExportOptions exportOption = new GridViewExportOptions(); exportOption.Format = ExportFormat.Text; string fileNameWithPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "DATA_EXPORT.txt"); necessaryElement.CreateTextFile(fileNameWithPath); FileStream fileStream = new FileStream(fileNameWithPath, FileMode.OpenOrCreate, FileAccess.Write); radgridview.Export((Stream)fileStream, exportOption); fileStream.Close(); fileStream.Dispose(); StreamReader txtReader = new StreamReader(fileNameWithPath); while ((txtline=txtReader.ReadLine())!=null) { char[] delimiterChars = { ' ', '"', '\t' }; String[] columnData = txtline.Split(delimiterChars,StringSplitOptions.RemoveEmptyEntries); if (oprationType.Equals(Variables.OperationTrypes.Sales)) { tempDataTable.Rows.Add(columnData[0].Trim(), columnData[1].Trim(), columnData[2].Trim(), columnData[3].Trim()); } else if (oprationType.Equals(Variables.OperationTrypes.InvPurDebCre)) { tempDataTable.Rows.Add(columnData[0].Trim(), columnData[3].Trim(), columnData[4].Trim(), columnData[5].Trim(), columnData[6].Trim(), columnData[7].Trim(), columnData[8].Trim(), columnData[9].Trim(), columnData[11].Trim(), columnData[10].Trim()); } } txtReader.Close(); txtReader.Dispose(); necessaryElement.DeleteFile(fileNameWithPath); return tempDataTable; }
//Conform Password Change private void conformPasswordChange(object sender, System.Windows.RoutedEventArgs e) { NecessaryFunction necessaryElement = new NecessaryFunction(); if (DatabaseSettingtextboxPassword.Password.Length.Equals(DatabaseSettingtextboxConformPassword.Password.Length)) { if (necessaryElement.PasswordIs(DatabaseSettingtextboxPassword.Password, DatabaseSettingtextboxConformPassword.Password)) { DatabaseSettingPasswordError.Foreground=Brushes.ForestGreen; DatabaseSettingPasswordError.Text=Variables.ERROR_MESSAGES[1,2]; } else { DatabaseSettingPasswordError.Foreground = Brushes.Red; DatabaseSettingPasswordError.Text = Variables.ERROR_MESSAGES[0, 6]; } } else { DatabaseSettingPasswordError.Text = string.Empty; } }
//Return Product Sales Save Button Click private void ReturnProductSalesButtonSaveClick(object sender, System.Windows.RoutedEventArgs e) { this.ReturnProductSalesButtonSave.IsEnabled = false; Mouse.OverrideCursor = Cursors.Wait; DataSetPetunia tempDataSet = new DataSetPetunia(); try { if (GridViewInvoice.Count > 0) { double paymentAmountIs = new NecessaryFunction().ComaSpriter(this.ReturnProductSalesNumberBoxPaymentAmountCreditOrDebit.Text); string creditAmountIs = this.ReturnProductSalesLabelCreditAmount.Text; foreach (InvoiceItems returnproductItems in GridViewInvoice) { tempDataSet.PetuniaCommonUse.Rows.Add(returnproductItems.ProductID, new PetuniaNecessaryFunction().DateFromRadDatePicker(this.ReturnProductSalesDateAndTime), returnproductItems.Quantity, returnproductItems.Rate, returnproductItems.Amount, this.ReturnProductSalesComboBoxName.Text, this.ReturnProductSalesLabelInvoiceNumber.Text, creditAmountIs, paymentAmountIs); paymentAmountIs = 0; creditAmountIs = "0"; if (this.ReturnProductSalesRadioButtonCash.IsChecked.Equals(true)) { if (operationType.Equals(Variables.OperationTrypes.PurchaseReturn) ? new AccountClass().PurchaseReturn(tempDataSet.PetuniaCommonUse, TransactionType.Cash, new DBQueres(new MySqlNaceassaryElement().DatabaseOperation), new DatabaseRead(new MySqlNaceassaryElement().DataReader)) : new AccountClass().SalesReturn(tempDataSet.PetuniaCommonUse, TransactionType.Cash, new DBQueres(new MySqlNaceassaryElement().DatabaseOperation), new DatabaseRead(new MySqlNaceassaryElement().DataReader))) { throw new SuccessfullException(Variables.ERROR_MESSAGES[0, 11]); } else { throw new PetuniaException(Variables.ERROR_MESSAGES[0, 3]); } } else if (this.ReturnProductSalesRadioButtonCreditOrDebit.IsChecked.Equals(true)) { if (this.ReturnProductSalesComboBoxName.Text != string.Empty && this.ReturnProductSalesNumberBoxPaymentAmountCreditOrDebit.Text != string.Empty) { if (operationType.Equals(Variables.OperationTrypes.PurchaseReturn) ? new AccountClass().PurchaseReturn(tempDataSet.PetuniaCommonUse, TransactionType.Credit, new DBQueres(new MySqlNaceassaryElement().DatabaseOperation), new DatabaseRead(new MySqlNaceassaryElement().DataReader)) : new AccountClass().SalesReturn(tempDataSet.PetuniaCommonUse, TransactionType.debt, new DBQueres(new MySqlNaceassaryElement().DatabaseOperation), new DatabaseRead(new MySqlNaceassaryElement().DataReader))) { throw new SuccessfullException(Variables.ERROR_MESSAGES[0, 11]); } else { throw new PetuniaException(Variables.ERROR_MESSAGES[0, 3]); } } else { throw new PetuniaException(Variables.ERROR_MESSAGES[0, 5]); } } } } else { throw new PetuniaException(Variables.ERROR_MESSAGES[0, 14]); } } catch (SuccessfullException success) { Mouse.OverrideCursor = null; Microsoft.Windows.Controls.MessageBox.Show(success.Message, Variables.ERROR_MESSAGES[0, 0], MessageBoxButton.OK, MessageBoxImage.Information); } catch (Exception error) { Mouse.OverrideCursor = null; Microsoft.Windows.Controls.MessageBox.Show(error.Message, Variables.ERROR_MESSAGES[0, 0], MessageBoxButton.OK, MessageBoxImage.Stop); } finally { tempDataSet.Dispose(); Mouse.OverrideCursor = null; this.ReturnProductSalesButtonSave.IsEnabled = true; } }
//Should Be error //Invoice Save private void InvoiceSpritButtonSaveClick(object sender, System.Windows.RoutedEventArgs e) { this.InvoiceButtonSaveAndPrint.IsEnabled = false; DataSetPetunia commonDataUse = new DataSetPetunia(); try { if (GridViewInvoice.Count > 0) { double paymentAmount = new NecessaryFunction().ComaSpriter(this.InvoiceNumberBoxPaidAmount.Text); string creditAmount = this.InvoieLabelCreditAmount.Text; MessageBoxResult messageBoxResult = Microsoft.Windows.Controls.MessageBox.Show(Variables.ERROR_MESSAGES[1, 14], Variables.ERROR_MESSAGES[0, 0], MessageBoxButton.YesNo, MessageBoxImage.Question); Mouse.OverrideCursor = Cursors.Wait; if (messageBoxResult.Equals(MessageBoxResult.Yes)) { foreach (InvoiceItems tempInvoiceItem in GridViewInvoice) { commonDataUse.PetuniaCommonUse.Rows.Add(tempInvoiceItem.ProductID, new PetuniaNecessaryFunction().DateFromRadDatePicker(this.InvoiceDateTimePicker), tempInvoiceItem.Quantity, tempInvoiceItem.Rate, tempInvoiceItem.Amount, "NONE", this.InvoiceTextBoxIssueName.Text, invoiceNumber, paymentAmount, this.InvoiceComboBoxDebtorName.Text, creditAmount); paymentAmount = 0; creditAmount = "0"; if (this.InvoiceRadioButtonCash.IsChecked.Equals(true)) { if (new AccountClass().Sales(commonDataUse.PetuniaCommonUse, TransactionType.Cash, new DBQueres(new MySqlNaceassaryElement().DatabaseOperation), new DatabaseRead(new MySqlNaceassaryElement().DataReader))) { throw new SuccessfullException(Variables.ERROR_MESSAGES[0, 11]); } else { throw new PetuniaException(Variables.ERROR_MESSAGES[0, 3]); } } else if (this.InvoiceRadioButtonDebtor.IsChecked.Equals(true)) { if (this.InvoiceComboBoxDebtorName.Text != string.Empty && this.InvoiceNumberBoxPaidAmount.Text != string.Empty && this.InvoieLabelCreditAmount.Text != string.Empty && Convert.ToDouble(this.InvoieLabelCreditAmount.Text) >= 0) { if (new AccountClass().Sales(commonDataUse.PetuniaCommonUse, TransactionType.Credit, new DBQueres(new MySqlNaceassaryElement().DatabaseOperation), new DatabaseRead(new MySqlNaceassaryElement().DataReader))) { throw new SuccessfullException(Variables.ERROR_MESSAGES[0, 11]); } else { throw new PetuniaException(Variables.ERROR_MESSAGES[0, 3]); } } else { throw new PetuniaException(Variables.ERROR_MESSAGES[0, 5]); } } else if (this.InvoiceRadioButtonCheck.IsChecked.Equals(true)) { if (new AccountClass().Sales(commonDataUse.PetuniaCommonUse, TransactionType.check, new DBQueres(new MySqlNaceassaryElement().DatabaseOperation), new DatabaseRead(new MySqlNaceassaryElement().DataReader))) { throw new SuccessfullException(Variables.ERROR_MESSAGES[0, 11]); } else { throw new PetuniaException(Variables.ERROR_MESSAGES[0, 3]); } } else { throw new PetuniaException(Variables.ERROR_MESSAGES[0, 13]); } } } } else { throw new PetuniaException(Variables.ERROR_MESSAGES[0, 14]); } } catch (SuccessfullException success) { GridViewInvoice.Clear(); Mouse.OverrideCursor = null; Microsoft.Windows.Controls.MessageBox.Show(success.Message, Variables.ERROR_MESSAGES[0, 0], MessageBoxButton.OK, MessageBoxImage.Information); } catch (Exception error) { Mouse.OverrideCursor = null; Microsoft.Windows.Controls.MessageBox.Show(error.Message, Variables.ERROR_MESSAGES[0, 0], MessageBoxButton.OK, MessageBoxImage.Stop); } finally { Mouse.OverrideCursor = null; this.InvoiceButtonSaveAndPrint.IsEnabled = true; commonDataUse.Dispose(); } }
//check database string private void DatabaseSettingConnectButtonClick(object sender, System.Windows.RoutedEventArgs e) { MySqlNaceassaryElement mysqlNecessaryFunction = new MySqlNaceassaryElement(); NecessaryFunction necessaryElement = new NecessaryFunction(); this.DatabaseSettingConnectButton.IsEnabled = false; if (DatabaseSettingtextboxUsername.Text != string.Empty && DatabaseSettingtextboxPassword.Password != string.Empty && DatabaseSettingtextboxConformPassword.Password != string.Empty && DatabaseSettingtextboxHostIP.Text != string.Empty && DatabaseSettingtextboxPortNumber.Text != string.Empty && DatabaseSettingtextboxPortNumber.Text != string.Empty && DatabaseSettingtextboxDatabaseName.Text != string.Empty && necessaryElement.PasswordIs(DatabaseSettingtextboxPassword.Password, DatabaseSettingtextboxConformPassword.Password)) { if (mysqlNecessaryFunction.ConnectToMysql(this.DatabaseSettingtextboxDatabaseName.Text,this.DatabaseSettingtextboxHostIP.Text,this.DatabaseSettingtextboxPortNumber.Text,this.DatabaseSettingtextboxUsername.Text,this.DatabaseSettingtextboxConformPassword.Password)) { Properties.Settings.Default.DatabaseServerip = this.DatabaseSettingtextboxHostIP.Text; Properties.Settings.Default.DatabasePortNumber = this.DatabaseSettingtextboxPortNumber.Text; Properties.Settings.Default.DarabaseDefultDatabase = this.DatabaseSettingtextboxDatabaseName.Text; Properties.Settings.Default.DatabaseUserName = this.DatabaseSettingtextboxUsername.Text; Properties.Settings.Default.DatabasePassword = DatabaseSettingtextboxConformPassword.Password; Properties.Settings.Default.Save(); Microsoft.Windows.Controls.MessageBox.Show(ProcestaVariables.Variables.ERROR_MESSAGES[0, 8], ProcestaVariables.Variables.ERROR_MESSAGES[0, 0], MessageBoxButton.OK, MessageBoxImage.Information); System.Windows.Forms.Application.Restart(); Application.Current.Shutdown(); } else { Microsoft.Windows.Controls.MessageBox.Show(ProcestaVariables.Variables.ERROR_MESSAGES[0, 1], ProcestaVariables.Variables.ERROR_MESSAGES[0, 0], MessageBoxButton.OK, MessageBoxImage.Error); this.DatabaseSettingConnectButton.IsEnabled = true; } } else { Microsoft.Windows.Controls.MessageBox.Show(ProcestaVariables.Variables.ERROR_MESSAGES[0, 1] + Environment.NewLine + ProcestaVariables.Variables.ERROR_MESSAGES[0, 7], ProcestaVariables.Variables.ERROR_MESSAGES[0, 0], MessageBoxButton.OK, MessageBoxImage.Stop); this.DatabaseSettingConnectButton.IsEnabled = true; } }