public void ComboBoxItemLoad(DevExpress.Xpf.Editors.ComboBoxEdit devComboBox, string query)
 {
     devComboBox.Items.Clear();
     DataTable tempDataTable = new DataTable();
     MySqlNaceassaryElement mysqlNecessaryFunction = new MySqlNaceassaryElement();
     tempDataTable = mysqlNecessaryFunction.DataReader(query);
     foreach (DataRow comboItems in tempDataTable.Rows)
     {
         devComboBox.Items.Add(comboItems[0]);
     }
 }
 //ProductID Finder
 public string ProductIDFinder(string companyName, string productName, string modelNumber)
 {
     DataTable tempDataTable = new MySqlNaceassaryElement().DataReader(string.Format("SELECT {0} FROM {1} WHERE {2}='{3}' AND {4}='{5}' AND {6}='{7}'", Variables.COLUMN_NAME[4], Variables.TABLE_NAME[11], Variables.COLUMN_NAME[7], companyName, Variables.COLUMN_NAME[10], productName, Variables.COLUMN_NAME[11], modelNumber));
     if (tempDataTable.Rows.Count > 0)
     {
         DataRow productIDDataRow = tempDataTable.Rows[0];
         return (string)productIDDataRow[0];
     }
     else
     {
         return "";
     }
 }
 //Debtors Creditors Account Info Viewer
 public void DebtorsCreditorsAccountInfoViewer(TextBlock contractPerson, TextBlock phone, TextBlock Email, TextBlock Address, TextBlock Amount, string userID)
 {
     DataTable temDataTable = new MySqlNaceassaryElement().DataReader(string.Format("SELECT * FROM {0},{1} WHERE {0}.{2}='{3}' AND {0}.{2}={1}.{2}", Variables.TABLE_NAME[10],Variables.TABLE_NAME[9], Variables.COLUMN_NAME[3], userID));
     if (temDataTable.Rows.Count > 0)
     {
         DataRow temDataRow = temDataTable.Rows[0];
         contractPerson.Text = temDataRow[4].ToString();
         phone.Text = temDataRow[2].ToString();
         Email.Text = temDataRow[3].ToString();
         Address.Text = temDataRow[5].ToString();
         Amount.Text = temDataRow[7].ToString();
     }
     temDataTable.Dispose();
 }
 //Sock info Quantity and Rate
 public void StockInfoLoad(TextBlock productID, TextBlock textBlockQuantity, TextBlock textBlockWaitAndAvarageRate, string ProductID)
 {
     DataTable tempDataTable = new MySqlNaceassaryElement().DataReader(string.Format("SELECT * FROM {0} WHERE {1} ='{2}'", Variables.TABLE_NAME[4], Variables.COLUMN_NAME[4], ProductID));
     if (tempDataTable.Rows.Count > 0)
     {
         DataRow tempDataRow = tempDataTable.Rows[0];
         productID.Text = Convert.ToString(tempDataRow[0]);
         textBlockQuantity.Text =Convert.ToString(tempDataRow[1]);
         textBlockWaitAndAvarageRate.Text = Convert.ToString(tempDataRow[2]);
     }
     else
     {
         return;
     }
 }
 //Debtor and Creditors Account Info Loader
 public bool DebtorAndCreditorAccountLoader(TextBlock amount, string userName)
 {
     DataTable tempDataTable = new MySqlNaceassaryElement().DataReader(string.Format("SELECT * FROM {0} WHERE {1}='{2}'", Variables.TABLE_NAME[9], Variables.COLUMN_NAME[3], userName));
     if (tempDataTable.Rows.Count > 0)
     {
         DataRow temDataRow = tempDataTable.Rows[0];
             amount.Text = temDataRow[1].ToString();
             tempDataTable.Dispose();
             return true;
     }
     else
     {
         tempDataTable.Dispose();
         return false;
     }
 }
 //Stock Info By Group
 public bool StockInfoByGroup(WrapPanel panelStockInfo, string query)
 {
     try
     {
         panelStockInfo.Children.Clear();
         DataTable tempDataTable = new MySqlNaceassaryElement().DataReader(query);
         foreach (DataRow tempDatRow in tempDataTable.Rows)
         {
             StockInfoByGroup tempStockInfoGroup = new StockInfoByGroup();
             tempStockInfoGroup.StockInfoGroupDataContext(tempDatRow);
             panelStockInfo.Children.Add(tempStockInfoGroup);
         }
         tempDataTable.Dispose();
         return true;
     }
     catch
     {
         return false;
     }
 }
 private void startupWorker(object sender, DoWorkEventArgs e)
 {
     Thread.Sleep(800);
     stratupWindowLogingMessages.AnimationText = "Connecting....";
     stratupBackgroundWorker.ReportProgress(1);
     Thread.Sleep(1000);
     MySqlNaceassaryElement.DatabaseConnectionInfo[0] = Properties.Settings.Default.DatabaseServerip;
     MySqlNaceassaryElement.DatabaseConnectionInfo[1] = Properties.Settings.Default.DatabasePortNumber;
     MySqlNaceassaryElement.DatabaseConnectionInfo[2] = "petunia2.0";
     MySqlNaceassaryElement.DatabaseConnectionInfo[3] = Properties.Settings.Default.DatabaseUserName;
     MySqlNaceassaryElement.DatabaseConnectionInfo[4] = Properties.Settings.Default.DatabasePassword;
        bool databaseConnectionTest;
     try
     {
          databaseConnectionTest = new MySqlNaceassaryElement().ConnectToMysql(Properties.Settings.Default.DarabaseDefultDatabase, Properties.Settings.Default.DatabaseServerip, Properties.Settings.Default.DatabasePortNumber, Properties.Settings.Default.DatabaseUserName, Properties.Settings.Default.DatabasePassword);
     }
     catch
     {
         databaseConnectionTest = false;
     }
     if (databaseConnectionTest)
     {
         stratupBackgroundWorker.ReportProgress(2);
         Thread.Sleep(1000);
         stratupWindowLogingMessages.AnimationText = "Loading....";
         stratupBackgroundWorker.ReportProgress(3);
         Thread.Sleep(2000);
         stratupBackgroundWorker.ReportProgress(4);
         Thread.Sleep(500);
         stratupBackgroundWorker.ReportProgress(5);
         Thread.Sleep(600);
     }
     else
     {
         stratupBackgroundWorker.ReportProgress(6);
     }
 }
 private void strtaupProcess(object sender, ProgressChangedEventArgs e)
 {
     if (e.ProgressPercentage.Equals(1))
     {
         stratupWindowLogingMessages.AnimationArrivalBegin = true;
     }
     else if (e.ProgressPercentage.Equals(2))
     {
         stratupWindowLogingMessages.AnimationLeaveBegin = true;
     }
     else if (e.ProgressPercentage.Equals(3))
     {
         stratupWindowLogingMessages.AnimationArrivalBegin = true;
     }
     else if (e.ProgressPercentage.Equals(4))
     {
         MySqlNaceassaryElement mysqlNecessaryFunction = new MySqlNaceassaryElement();
         MysqlBackupVariablesClass.MYSQL_CONNECTION_STRING[0] = Properties.Settings.Default.DatabaseServerip;
         MysqlBackupVariablesClass.MYSQL_CONNECTION_STRING[1]=Properties.Settings.Default.DatabasePortNumber;
         MysqlBackupVariablesClass.MYSQL_CONNECTION_STRING[2] = Properties.Settings.Default.DarabaseDefultDatabase;
         MysqlBackupVariablesClass.MYSQL_CONNECTION_STRING[3]=Properties.Settings.Default.DatabaseUserName;
         MysqlBackupVariablesClass.MYSQL_CONNECTION_STRING[4]=Properties.Settings.Default.DatabasePassword;
         new MysqlDataBackupRestoreClass().DataBaseRestore("Petunia2.0");
         new Variables().InitializeLoaclData();
         new AccountClass().StartupDataBaseChecker(new DBQueres(mysqlNecessaryFunction.DatabaseOperation), new DatabaseRead(mysqlNecessaryFunction.DataReader), new MysqlRowCounter(mysqlNecessaryFunction.MysqlRowsIs));
     }
     else if (e.ProgressPercentage.Equals(5))
     {
         stratupWindowLogingMessages.AnimationLeaveBegin = true;
     }
     else if (e.ProgressPercentage.Equals(6))
     {
         flagDatabaseError = true;
         Microsoft.Windows.Controls.MessageBox.Show(Variables.ERROR_MESSAGES[0, 1], Variables.ERROR_MESSAGES[0, 0], MessageBoxButton.OK, MessageBoxImage.Error);
         new WindowDataBaseSetting().ShowDialog();
         this.Close();
     }
 }
 //Edit NewProduct Update Button
 private void EditNewProductUpdateClick(object sender, System.Windows.RoutedEventArgs e)
 {
     this.EditNewProductButtonUpdate.IsEnabled = false;
     MySqlNaceassaryElement mysqlNecessaryFunction = new MySqlNaceassaryElement();
     try
     {
         MessageBoxResult tempDiglogBoxResult = Microsoft.Windows.Controls.MessageBox.Show(Variables.ERROR_MESSAGES[1, 11], Variables.ERROR_MESSAGES[0, 0], MessageBoxButton.YesNo, MessageBoxImage.Question);
         Mouse.OverrideCursor = Cursors.Wait;
         if (tempDiglogBoxResult.Equals(MessageBoxResult.Yes))
         {
             if (this.EditNewProductTextBoxCompanyName.Text != string.Empty && this.EditNewProductTextBoxProductName.Text != string.Empty && this.EditNewProductTextBoxModelNumber.Text != string.Empty && this.EditNewProductProductInfo.ModelNumberIs != string.Empty)
             {
                 if (mysqlNecessaryFunction.MysqlValueChecker(string.Format("SELECT * FROM {0} WHERE {1}='{2}' AND {3}='{4}' AND {5}='{6}'", Variables.TABLE_NAME[11], Variables.COLUMN_NAME[7], this.EditNewProductTextBoxCompanyName.Text, Variables.COLUMN_NAME[10], this.EditNewProductTextBoxProductName.Text, Variables.COLUMN_NAME[11], this.EditNewProductTextBoxModelNumber.Text)))
                 {
                     mysqlNecessaryFunction.DatabaseOperation(string.Format("UPDATE {0} SET {1}='{2}',{3}='{4}',{5}='{6}' WHERE {7}='{8}'", Variables.TABLE_NAME[11], Variables.COLUMN_NAME[7], this.EditNewProductTextBoxCompanyName.Text, Variables.COLUMN_NAME[10], this.EditNewProductTextBoxProductName.Text, Variables.COLUMN_NAME[11], this.EditNewProductTextBoxModelNumber.Text, Variables.COLUMN_NAME[4], this.EditNewProductLabelProductID.Text));
                     this.EditNewProductProductInfo.CompanyNameLoader();
                     throw new SuccessfullException(Variables.ERROR_MESSAGES[0, 11]);
                 }
                 else
                 {
                     throw new PetuniaException(Variables.ERROR_MESSAGES[0, 10]);
                 }
             }
             else
             {
                 throw new PetuniaException(Variables.ERROR_MESSAGES[0, 5]);
             }
         }
     }
     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
     {
         Mouse.OverrideCursor = null;
         mysqlNecessaryFunction.Dispose();
         this.EditNewProductButtonUpdate.IsEnabled = true;
     }
 }
 //Edit NewProduct Search Button
 private void EditNewProductSearchClick(object sender, System.Windows.RoutedEventArgs e)
 {
     this.EditNewProductButtonSearch.IsEnabled = false;
     Mouse.OverrideCursor = Cursors.Wait;
     string mysqlQuery = string.Empty;
     DataTable tempDataTable = new DataTable();
     try
     {
         if (EditNewProductRadioButtonByProductInfo.IsChecked.Equals(true))
         {
             if (this.EditNewProductProductInfo.CompanyNameIs != string.Empty && this.EditNewProductProductInfo.ProductNameIs != string.Empty && this.EditNewProductProductInfo.ModelNumberIs != string.Empty)
             {
                 mysqlQuery = string.Format("SELECT * FROM {0} WHERE {1}='{2}' AND {3}='{4}' AND {5}='{6}'", Variables.TABLE_NAME[11], Variables.COLUMN_NAME[7], this.EditNewProductProductInfo.CompanyNameIs, Variables.COLUMN_NAME[10], this.EditNewProductProductInfo.ProductNameIs, Variables.COLUMN_NAME[11], this.EditNewProductProductInfo.ModelNumberIs);
             }
             else
             {
                 throw new PetuniaException(Variables.ERROR_MESSAGES[0, 5]);
             }
         }
         if (EditNewProductRadioButtonByProductID.IsChecked.Equals(true))
         {
             if (EditNewProductTextBoxProductID.Text != string.Empty)
             {
                 mysqlQuery = string.Format("SELECT * FROM {0} WHERE {1}='{2}'", Variables.TABLE_NAME[11], Variables.COLUMN_NAME[4], new NecessaryFunction().SixDigitNumber(this.EditNewProductTextBoxProductID.Text));
             }
             else
             {
                 throw new PetuniaException(Variables.ERROR_MESSAGES[0, 5]);
             }
         }
         tempDataTable = new MySqlNaceassaryElement().DataReader(mysqlQuery);
         if (tempDataTable.Rows.Count > (0))
         {
             DataRow tempTableRow = tempDataTable.Rows[0];
             this.EditNewProductTextBoxCompanyName.Text = tempTableRow[2].ToString();
             this.EditNewProductTextBoxProductName.Text = tempTableRow[3].ToString();
             this.EditNewProductTextBoxModelNumber.Text = tempTableRow[4].ToString();
             this.EditNewProductTextBoxDescription.Text = tempTableRow[5].ToString();
             this.EditNewProductLabelProductID.Text = tempTableRow[0].ToString();
             this.EditNewProductButtonSearch.IsEnabled = true;
         }
         else
         {
             throw new PetuniaException(Variables.ERROR_MESSAGES[1, 10]);
         }
     }
     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;
         tempDataTable.Dispose();
         mysqlQuery = null;
         this.EditNewProductButtonSearch.IsEnabled = true;
     }
 }
 //Debtor Payment Search Button Click
 private void DebtorPaymentButtonSearchClick(object sender, System.Windows.RoutedEventArgs e)
 {
     this.DebtorsCredtorsPaymentButtonSearch.IsEnabled = false;
     Mouse.OverrideCursor = Cursors.Wait;
     try
     {
         if (this.DebtorsCredtorsPaymentTextBoxName.Text != string.Empty)
         {
             DataTable tempDataTable = new MySqlNaceassaryElement().DataReader(string.Format("SELECT * FROM {0} WHERE {1}='{2}' AND {3}='{4}'", Variables.TABLE_NAME[10], Variables.COLUMN_NAME[3], this.DebtorsCredtorsPaymentTextBoxName.Text, Variables.COLUMN_NAME[12], this.DebtorCredtorsPaymentLabelHeader.Text));
             if (tempDataTable.Rows.Count > 0)
             {
                 this.DebtorsCredtorsPaymentComboBoxName.Text = this.DebtorsCredtorsPaymentTextBoxName.Text;
                 tempDataTable.Dispose();
             }
             else
             {
                 tempDataTable.Dispose();
                 throw new PetuniaException(Variables.ERROR_MESSAGES[1, 8]);
             }
         }
         else
         {
             throw new PetuniaException(Variables.ERROR_MESSAGES[0, 5]);
         }
     }
     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.DebtorsCredtorsPaymentButtonSearch.IsEnabled = true;
     }
 }
 //Debtor Payment Payment Click
 private void DebtorPaymentButtonPamentClick(object sender, System.Windows.RoutedEventArgs e)
 {
     this.DebtorsCredtorsPaymentButtonPayment.IsEnabled = false;
     Mouse.OverrideCursor = Cursors.Wait;
     DataSetPetunia commonDataUse = new DataSetPetunia();
     bool debtors = false;
     try
     {
         if (this.DebtorsCredtorsPaymentComboBoxName.Text != string.Empty && this.DebtorsCredtorsPaymentNumberBoxPaymentAmount.Text != string.Empty)
         {
                 if (operationType.Equals(Variables.OperationTrypes.Debtors))
                 {
                     debtors = true;
                 }
                 DataTable tempadataTable = new MySqlNaceassaryElement().DataReader(string.Format("SELECT {0} FROM {1} WHERE {2}='{3}' ORDER BY {4}", Variables.COLUMN_NAME[4], Variables.TABLE_NAME[3], Variables.COLUMN_NAME[3], this.DebtorsCredtorsPaymentComboBoxName.Text, Variables.COLUMN_NAME[0]));
                 if (tempadataTable.Rows.Count > 0)
                 {
                     DataRow tempDataRow = tempadataTable.Rows[0];
                     commonDataUse.PetuniaCommonUse.Rows.Add(this.DebtorsCredtorsPaymentComboBoxName.Text, tempDataRow[0], new PetuniaNecessaryFunction().DateFromRadDatePicker(this.DebtorsCredtorsPaymentDateAndTimePicker), new NecessaryFunction().ComaSpriter(this.DebtorsCredtorsPaymentNumberBoxPaymentAmount.Text));
                     if (debtors ? new AccountClass().CreditorsAndDebtorsPayment(commonDataUse.PetuniaCommonUse, TransactionType.debt, new DatabaseRead(new MySqlNaceassaryElement().DataReader), new DBQueres(new MySqlNaceassaryElement().DatabaseOperation)) : new AccountClass().CreditorsAndDebtorsPayment(commonDataUse.PetuniaCommonUse, TransactionType.Credit, new DatabaseRead(new MySqlNaceassaryElement().DataReader), new DBQueres(new MySqlNaceassaryElement().DatabaseOperation)))
                     {
                         throw new SuccessfullException(Variables.ERROR_MESSAGES[0, 11]);
                     }
                     else
                     {
                         throw new PetuniaException(Variables.ERROR_MESSAGES[0, 2]);
                     }
                 }
                 else
                 {
                     throw new PetuniaException(Variables.ERROR_MESSAGES[0, 2]);
                 }
         }
         else
         {
             throw new PetuniaException(Variables.ERROR_MESSAGES[0, 2]);
         }
     }
     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
     {
         commonDataUse.Dispose();
         this.DebtorsCredtorsPaymentButtonPayment.IsEnabled = true;
         Mouse.OverrideCursor = null;
     }
 }
 //Edit Party Info User ID Select Index Change
 private void EditPartyInfoUserIDIndexChaged(object sender, System.Windows.RoutedEventArgs e)
 {
     Mouse.OverrideCursor = Cursors.Wait;
     DataTable tempDatatable = new DataTable();
     tempDatatable = new MySqlNaceassaryElement().DataReader(string.Format("SELECT * FROM {0} WHERE {1}='{2}'",Variables.TABLE_NAME[10],Variables.COLUMN_NAME[3],this.EditPartyInfoComboBoxUserID.Text));
     if (tempDatatable.Rows.Count > 0)
     {
         DataRow tempDataRow = tempDatatable.Rows[0];
         this.EditPartyInfoComboBoxAccountType.Text = tempDataRow[1].ToString();
         this.EditPartyInfoTextBoxControctPerson.Text = tempDataRow[4].ToString();
         this.EditParyInfoTextBoxPhoneNumber.Text = tempDataRow[2].ToString();
         this.EditPartyInfoTextBoxEmail.Text = tempDataRow[3].ToString();
         this.EditPartyInfoTextBoxAddress.Text = tempDataRow[5].ToString();
         tempDatatable.Dispose();
         Mouse.OverrideCursor = null;
         return;
     }
     else
     {
         tempDatatable.Dispose();
         Mouse.OverrideCursor = null;
         return;
     }
 }
 private void RechargeAmountComBoxBoxCompayNameSelectIndexChange(object sender, System.Windows.RoutedEventArgs e)
 {
     DataTable tempDataTable = new MySqlNaceassaryElement().DataReader(string.Format("SELECT {0} FROM {1} WHERE {2}='{3}'", Variables.COLUMN_NAME[1], Variables.TABLE_NAME[17], Variables.COLUMN_NAME[7], this.RechargeAmountComBoxBoxCompayName.Text));
     if (tempDataTable.Rows.Count>0)
     {
         this.RechargeAmountTextBlockStockAmount.Text = tempDataTable.Rows[0][0].ToString();
     }
 }
        //New Product Button Click
        private void NewProductCreateButton_Click(object sender, RoutedEventArgs e)
        {
            this.NewProductCreateButton.IsEnabled = false;
            Mouse.OverrideCursor = Cursors.Wait;
            MySqlNaceassaryElement mysqlNecessaryFunction = new MySqlNaceassaryElement();
            try
            {
                if (this.NewProductTextBoxCompanyName.Text != string.Empty && this.NewProductTextBoxProductName.Text != string.Empty && this.NewProductTextBoxModelNumber.Text != string.Empty && (this.NewProductTextBoxProductID.Text != string.Empty || this.NewProductCheckBoxAutoGenerate.IsChecked.Equals(true)))
                {

                    if (!this.NewProductCheckBoxAutoGenerate.IsChecked.Equals(true))
                    {
                        if (this.NewProductTextBoxProductID.Text != string.Empty)
                        {
                            if (!mysqlNecessaryFunction.MysqlValueChecker(string.Format("SELECT * FROM {0} WHERE {1}='{2}'", Variables.TABLE_NAME[11], Variables.COLUMN_NAME[4], this.NewProductTextBoxProductID.Text)))
                            {
                               throw new PetuniaException(Variables.ERROR_MESSAGES[0, 9]);
                            }
                        }
                        else
                        {
                            throw new PetuniaException(Variables.ERROR_MESSAGES[0, 5]);
                        }
                    }
                    else
                    {
                        this.NewProductTextBoxProductID.Text = mysqlNecessaryFunction.ProductIDIs(Variables.TABLE_NAME[11], Variables.COLUMN_NAME[4]);
                    }
                    this.NewProductTextBoxProductID.Text = new NecessaryFunction().SixDigitNumber(this.NewProductTextBoxProductID.Text);
                    if (!mysqlNecessaryFunction.MysqlValueChecker(string.Format("SELECT * FROM {0} WHERE {1}='{2}' AND {3}='{4}' AND {5}='{6}'", Variables.TABLE_NAME[11], Variables.COLUMN_NAME[7], this.NewProductTextBoxCompanyName.Text, Variables.COLUMN_NAME[10], this.NewProductTextBoxProductName.Text, Variables.COLUMN_NAME[11], this.NewProductTextBoxModelNumber.Text)) | !mysqlNecessaryFunction.DatabaseOperation(string.Format("SELECT * FROM {0} WHERE {1}='{2}'", Variables.TABLE_NAME[4], Variables.COLUMN_NAME[4], this.NewProductTextBoxProductID.Text)))
                    {
                        throw new PetuniaException(Variables.ERROR_MESSAGES[0, 10]);
                    }
                    else
                    {
                        if (mysqlNecessaryFunction.DatabaseOperation(string.Format("INSERT INTO {0} VALUES ('{1}','{2}','{3}','{4}','{5}','{6}')", Variables.TABLE_NAME[11], this.NewProductTextBoxProductID.Text, DateTime.Now.ToString("yyyy-MM-dd"), this.NewProductTextBoxCompanyName.Text, this.NewProductTextBoxProductName.Text, this.NewProductTextBoxModelNumber.Text, this.NewProductTextBoxDescription.Text)))
                        {
                            mysqlNecessaryFunction.DatabaseOperation(string.Format("INSERT INTO {0} VALUES ('{1}',0,0,0,NULL)", Variables.TABLE_NAME[4], this.NewProductTextBoxProductID.Text));
                            throw new SuccessfullException(Variables.ERROR_MESSAGES[0, 11]);
                        }
                        else
                        {
                            throw new PetuniaException(Variables.ERROR_MESSAGES[0, 2]);
                        }
                    }
                }
                else
                {
                    throw new PetuniaException(Variables.ERROR_MESSAGES[0, 5]);
                }
            }
            catch (SuccessfullException success)
            {
                Mouse.OverrideCursor = null;
                Microsoft.Windows.Controls.MessageBox.Show(success.Message, ProcestaVariables.Variables.ERROR_MESSAGES[0, 0], MessageBoxButton.OK, MessageBoxImage.Information);
            }
            catch (Exception error)
            {
                Mouse.OverrideCursor = null;
                Microsoft.Windows.Controls.MessageBox.Show(error.Message, ProcestaVariables.Variables.ERROR_MESSAGES[0, 0], MessageBoxButton.OK, MessageBoxImage.Stop);
            }
            finally
            {
                Mouse.OverrideCursor = null;
                this.NewProductCreateButton.IsEnabled = true;
                mysqlNecessaryFunction.Dispose();
            }
        }
        //New Party Create Button
        private void NewPartyCreateClick(object sender, System.Windows.RoutedEventArgs e)
        {
            this.NewParyButtonCreate.IsEnabled = false;
            Mouse.OverrideCursor = Cursors.Wait;
            MySqlNaceassaryElement mysqlNecessaryFunction = new MySqlNaceassaryElement();
            try
            {
                if (this.NewParyTextBoxUserID.Text != string.Empty && this.NewParyComboBoxAccountType.Text != string.Empty)
                {

                    if (mysqlNecessaryFunction.MysqlValueChecker(string.Format("SELECT * FROM {0} WHERE {1}='{2}'", Variables.TABLE_NAME[10], Variables.COLUMN_NAME[3], this.NewParyTextBoxUserID.Text)))
                    {
                        mysqlNecessaryFunction.DatabaseOperation(string.Format("INSERT {0} VALUES ('{1}','{2}','{3}','{4}','{5}','{6}')", Variables.TABLE_NAME[10], this.NewParyTextBoxUserID.Text, this.NewParyComboBoxAccountType.Text, this.NewPartyTextBoxPhoneNumber.Text, this.NewPartyTextBoxEmail.Text, this.NewPartyTextBoxContractPerson.Text, this.NewpartyTextBoxAddress.Text));
                        mysqlNecessaryFunction.DatabaseOperation(string.Format("INSERT INTO {0} VALUES ('{1}',0)", Variables.TABLE_NAME[9], this.NewParyTextBoxUserID.Text));
                        throw new SuccessfullException(Variables.ERROR_MESSAGES[0, 11]);
                    }
                    else
                    {
                        throw new PetuniaException(Variables.ERROR_MESSAGES[1, 5]);
                    }
                }
                else
                {
                    throw new PetuniaException(Variables.ERROR_MESSAGES[0, 5]);
                }
            }
            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.Error);
            }
            finally
            {
                mysqlNecessaryFunction.Dispose();
                this.NewParyButtonCreate.IsEnabled = true;
                Mouse.OverrideCursor = null;
            }
        }
 // Add stock Update Button
 private void AddStockUpdateClick(object sender, System.Windows.RoutedEventArgs e)
 {
     this.AddStockButtonAdd.IsEnabled = false;
     Mouse.OverrideCursor = Cursors.Wait;
     MySqlNaceassaryElement mysqlNecessaryFunction = new MySqlNaceassaryElement();
     DataSetPetunia commonUseDataSet = new DataSetPetunia();
     try
     {
         if (this.StockAddProductInfo.CompanyNameIs != string.Empty && this.StockAddProductInfo.ProductNameIs != string.Empty && this.StockAddProductInfo.ModelNumberIs != string.Empty && AddStockLabelProductIDInfo.Text != string.Empty && AddStockNumericUpDown.Value > 0 && AddStockTextBoxRate.Text != string.Empty && AddStockTextBoxInvoiceNUmber.Text != string.Empty && Convert.ToDouble(this.AddStockTextBoxRate.Text) > 0)
         {
             commonUseDataSet.PetuniaCommonUse.Rows.Add(this.AddStockLabelProductIDInfo.Text, new PetuniaNecessaryFunction().DateFromRadDatePicker(this.AddStockDatePicker), this.AddStockNumericUpDown.Value.ToString(), this.AddStockLabelRateInfo.Text, new NecessaryFunction().ComaSpriter(this.AddStockTextBoxRate.Text), this.AddStockLabelAmountNewInfo.Text, this.AddStockTextBoxInvoiceNote.Text, this.AddStockComboBoxCreditorsName.Text, this.AddStockTextBoxIssueName.Text, this.AddStockTextBoxInvoiceNUmber.Text, this.AddStockLabelCreditAmount.Text, new NecessaryFunction().ComaSpriter(this.AddStockTextBoxPaymentAmount.Text));
             if (this.AddStockRadioButtonCash.IsChecked.Equals(true))
             {
                 if (new AccountClass().Purchase(commonUseDataSet.PetuniaCommonUse, TransactionType.Cash, new DBQueres(mysqlNecessaryFunction.DatabaseOperation), new DatabaseRead(mysqlNecessaryFunction.DataReader)))
                 {
                     this.AddStockTextBoxInvoiceNUmber.Text = string.Empty;
                     throw new SuccessfullException(Variables.ERROR_MESSAGES[0, 11]);
                 }
                 else
                 {
                     throw new PetuniaException(Variables.ERROR_MESSAGES[0, 2]);
                 }
             }
             else if (this.AddStockRadioButtonCheeck.IsChecked.Equals(true))
             {
                 if (new AccountClass().Purchase(commonUseDataSet.PetuniaCommonUse, TransactionType.check, new DBQueres(mysqlNecessaryFunction.DatabaseOperation), new DatabaseRead(mysqlNecessaryFunction.DataReader)))
                 {
                     this.AddStockTextBoxInvoiceNUmber.Text = string.Empty;
                     throw new SuccessfullException(Variables.ERROR_MESSAGES[0, 11]);
                 }
                 else
                 {
                     throw new PetuniaException(Variables.ERROR_MESSAGES[0, 2]);
                 }
             }
             else if (this.AddStockReadioButtonCredit.IsChecked.Equals(true))
             {
                 if (this.AddStockComboBoxCreditorsName.Text != string.Empty && this.AddStockTextBoxPaymentAmount.Text != string.Empty && this.AddStockLabelCreditAmount.Text != string.Empty && Convert.ToDouble(this.AddStockLabelCreditAmount.Text) >= 0)
                 {
                     if (new AccountClass().Purchase(commonUseDataSet.PetuniaCommonUse, TransactionType.Credit, new DBQueres(mysqlNecessaryFunction.DatabaseOperation), new DatabaseRead(mysqlNecessaryFunction.DataReader)))
                     {
                         this.AddStockTextBoxInvoiceNUmber.Text = string.Empty;
                         throw new SuccessfullException(Variables.ERROR_MESSAGES[0, 11]);
                     }
                     else
                     {
                         throw new PetuniaException(Variables.ERROR_MESSAGES[0, 2]);
                     }
                 }
                 else
                 {
                     throw new PetuniaException(Variables.ERROR_MESSAGES[0, 5]);
                 }
             }
             else
             {
                 throw new PetuniaException(Variables.ERROR_MESSAGES[1, 4]);
             }
         }
         else
         {
             throw new PetuniaException(Variables.ERROR_MESSAGES[0, 5]);
         }
     }
     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
     {
         Mouse.OverrideCursor = null;
         this.AddStockButtonAdd.IsEnabled = true;
         mysqlNecessaryFunction.Dispose();
         commonUseDataSet.Dispose();
     }
 }
 private void EditRechagreComboBoxCompanyNameSelectIndexChange(object sender, System.Windows.RoutedEventArgs e)
 {
     DataTable tempDataTable = new MySqlNaceassaryElement().DataReader(string.Format("SELECT * FROM {0} WHERE {1}='{2}'", Variables.TABLE_NAME[16], Variables.COLUMN_NAME[7], this.EditRechagreComboBoxCompanyName.Text));
     if (tempDataTable.Rows.Count>0)
     {
         DataRow tempDataRow=tempDataTable.Rows[0];
         this.EditRechagreTextBoxContractPerson.Text = tempDataRow[2].ToString();
         this.EditRechagreTextBoxPhoneNumber.Text = tempDataRow[3].ToString();
     }
     tempDataTable.Dispose();
 }
 //Return Product Sales Search Click
 private void ReturnProductSalesButtonSearchClick(object sender, System.Windows.RoutedEventArgs e)
 {
     this.ReturnProductSalesButtonSearch.IsEnabled = false;
     Mouse.OverrideCursor = Cursors.Wait;
     DataTable tempDataTable=new DataTable();
     string tableName;
     try
     {
         if (this.ReturnProductSalesLabelProductID.Text != string.Empty)
         {
             if (operationType.Equals(Variables.OperationTrypes.PurchaseReturn))
             {
                 tableName = Variables.TABLE_NAME[12];
             }
             else if (operationType.Equals(Variables.OperationTrypes.SalesReturn))
             {
                 tableName = Variables.TABLE_NAME[14];
             }
             else
             {
                 throw new PetuniaException(Variables.ERROR_MESSAGES[0, 2]);
             }
             if (this.ReturnProductSalesRadioButtonbyAll.IsChecked.Equals(true))
             {
                 tempDataTable = new MySqlNaceassaryElement().DataReader(string.Format("SELECT {11}.{0},{10}.{1},{10}.{2},{10}.{3},{11}.{4},{11}.{5},{11}.{6},{11}.{7},{11}.{8},{11}.{9} FROM {10},{11} WHERE {11}.{4}='{12}' AND {10}.{4}={11}.{4} ORDER BY {0}", Variables.COLUMN_NAME[0], Variables.COLUMN_NAME[7], Variables.COLUMN_NAME[10], Variables.COLUMN_NAME[11], Variables.COLUMN_NAME[4], Variables.COLUMN_NAME[6], Variables.COLUMN_NAME[5], Variables.COLUMN_NAME[1], Variables.COLUMN_NAME[15], Variables.COLUMN_NAME[13], Variables.TABLE_NAME[11], tableName, this.ReturnProductSalesLabelProductID.Text));
                 GridViewLoadProductHistory.Clear();
                 foreach (DataRow tempDataRow in tempDataTable.Rows)
                 {
                     GridViewLoadProductHistory.Add(new ProductHistory(tempDataRow[0].ToString().Substring(0, 9), tempDataRow[2].ToString(), tempDataRow[1].ToString(), tempDataRow[3].ToString(), tempDataRow[4].ToString(), tempDataRow[5].ToString(), tempDataRow[6].ToString(), tempDataRow[7].ToString(), tempDataRow[8].ToString(), tempDataRow[9].ToString()));
                 }
             }
             else if (this.ReturnProductSalesRadioButtonByDate.IsChecked.Equals(true))
             {
                 tempDataTable = new MySqlNaceassaryElement().DataReader(string.Format("SELECT {11}.{0},{10}.{1},{10}.{2},{10}.{3},{11}.{4},{11}.{5},{11}.{6},{11}.{7},{11}.{8},{11}.{9} FROM {10},{11} WHERE {11}.{0}='{12}' AND {10}.{4}={11}.{4} ORDER BY {0}", Variables.COLUMN_NAME[0], Variables.COLUMN_NAME[7], Variables.COLUMN_NAME[10], Variables.COLUMN_NAME[11], Variables.COLUMN_NAME[4], Variables.COLUMN_NAME[6], Variables.COLUMN_NAME[5], Variables.COLUMN_NAME[1], Variables.COLUMN_NAME[15], Variables.COLUMN_NAME[13], Variables.TABLE_NAME[11], tableName, new PetuniaNecessaryFunction().DateFromRadDatePicker(this.ReturnProductSalesDateAndTime)));
                 GridViewLoadProductHistory.Clear();
                 foreach (DataRow tempDataRow in tempDataTable.Rows)
                 {
                     GridViewLoadProductHistory.Add(new ProductHistory(tempDataRow[0].ToString().Substring(0, 9), tempDataRow[2].ToString(), tempDataRow[1].ToString(), tempDataRow[3].ToString(), tempDataRow[4].ToString(), tempDataRow[5].ToString(), tempDataRow[6].ToString(), tempDataRow[7].ToString(), tempDataRow[8].ToString(), tempDataRow[9].ToString()));
                 }
             }
             else
             {
                 throw new PetuniaException(Variables.ERROR_MESSAGES[1, 5]);
             }
         }
         else
         {
             throw new PetuniaException(Variables.ERROR_MESSAGES[0, 5]);
         }
     }
     catch (Exception error)
     {
         Mouse.OverrideCursor = null;
         Microsoft.Windows.Controls.MessageBox.Show(error.Message, Variables.ERROR_MESSAGES[0, 0], MessageBoxButton.OK, MessageBoxImage.Stop);
     }
     finally
     {
         tempDataTable.Dispose();
         tableName = null;
         Mouse.OverrideCursor = null;
         this.ReturnProductSalesButtonSearch.IsEnabled = true;
     }
 }
        //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;
            }
        }
 // Stock info All
 public void StockInfoLoad(TextBlock productID, TextBlock quantity, TextBlock WaitAndAvarageRate, TextBlock Dabit, string ProductIDInternal)
 {
     DataTable tempDataTable = new MySqlNaceassaryElement().DataReader(string.Format("SELECT * FROM {0} WHERE {1} ='{2}'", Variables.TABLE_NAME[4], Variables.COLUMN_NAME[4], ProductIDInternal));
     if (tempDataTable.Rows.Count > 0)
     {
         DataRow tempDataRow = tempDataTable.Rows[0];
         productID.Text = (string)tempDataRow[0];
         quantity.Text = (string)(tempDataRow[1]).ToString();
         WaitAndAvarageRate.Text = (string)(tempDataRow[3]).ToString();
         Dabit.Text = (string)(tempDataRow[2]).ToString();
         tempDataTable.Dispose();
     }
     else
     {
         tempDataTable.Dispose();
         return;
     }
 }
 private void SummaryButtonSearchClick(object sender, System.Windows.RoutedEventArgs e)
 {
     this.SummaryButtonSearch.IsEnabled = false;
     Mouse.OverrideCursor = Cursors.Wait;
     DataTable tempdateTable = new DataTable();
     MySqlNaceassaryElement mysqElement = new MySqlNaceassaryElement();
     try
     {
         if (this.SummaryDate.SelectedDate.ToString() != string.Empty)
         {
             string tempDate = new PetuniaNecessaryFunction().DateFromRadDatePicker(this.SummaryDate);
             tempdateTable = mysqElement.DataReader(string.Format("SELECT {0} FROM {1} WHERE {2} BETWEEN '{3}' AND '{4}'", Variables.COLUMN_NAME[1], Variables.TABLE_NAME[2], Variables.COLUMN_NAME[0], new NecessaryFunction().MysqlDateFormate(((DateTime)this.SummaryDate.SelectedDate).AddDays(-1).ToString()), tempDate));
             if (tempdateTable.Rows.Count > 0)
             {
                 DataRow tempDataRow = tempdateTable.Rows[0];
                 this.TotalSummary.EndingCash = tempDataRow[0].ToString();
                 try
                 {
                     tempDataRow = tempdateTable.Rows[1];
                     this.TotalSummary.StartingCash = tempDataRow[0].ToString();
                 }
                 catch
                 {
                     this.TotalSummary.StartingCash = Variables.ERROR_MESSAGES[2, 1];
                 }
             }
             tempdateTable = mysqElement.DataReader(string.Format("SELECT SUM({0}),SUM({1}) FROM {2} WHERE {3}='{4}'", Variables.COLUMN_NAME[6], Variables.COLUMN_NAME[1], Variables.TABLE_NAME[12], Variables.COLUMN_NAME[0], tempDate));
             if (tempdateTable.Rows.Count > 0)
             {
                 DataRow tempDataRow = tempdateTable.Rows[0];
                 this.TotalSummary.PurchasQuantity = tempDataRow[0].ToString();
                 this.TotalSummary.PurchaseAmount = tempDataRow[1].ToString();
             }
             tempdateTable = mysqElement.DataReader(string.Format("SELECT SUM({0}),SUM({1}) FROM {2} WHERE {3}='{4}'", Variables.COLUMN_NAME[6], Variables.COLUMN_NAME[1], Variables.TABLE_NAME[14], Variables.COLUMN_NAME[0], tempDate));
             if (tempdateTable.Rows.Count > 0)
             {
                 DataRow tempDataRow = tempdateTable.Rows[0];
                 this.TotalSummary.SalesQuantity = tempDataRow[0].ToString();
                 this.TotalSummary.SalesAmount = tempDataRow[1].ToString();
             }
             tempdateTable = mysqElement.DataReader(string.Format("SELECT SUM({0}) FROM {1} WHERE {2}='{3}'", Variables.COLUMN_NAME[1], Variables.TABLE_NAME[6], Variables.COLUMN_NAME[0], tempDate));
             if (tempdateTable.Rows.Count > 0)
             {
                 DataRow tempDataRow = tempdateTable.Rows[0];
                 this.TotalSummary.Expanses = tempDataRow[0].ToString();
             }
             tempdateTable = mysqElement.DataReader(string.Format("SELECT SUM({0}),SUM({1}) FROM {2} WHERE {3}='{4}' AND {5}='Return'", Variables.COLUMN_NAME[6], Variables.COLUMN_NAME[1], Variables.TABLE_NAME[12], Variables.COLUMN_NAME[0], tempDate, Variables.COLUMN_NAME[14]));
             if (tempdateTable.Rows.Count > 0)
             {
                 DataRow tempDataRow = tempdateTable.Rows[0];
                 this.TotalSummary.PuchaseReturnQuantity = tempDataRow[0].ToString();
                 this.TotalSummary.PuchaseReturnAmount = tempDataRow[1].ToString();
             }
             tempdateTable = mysqElement.DataReader(string.Format("SELECT SUM({0}),SUM({1}) FROM {2} WHERE {3}='{4}' AND {5}='Return'", Variables.COLUMN_NAME[6], Variables.COLUMN_NAME[1], Variables.TABLE_NAME[14], Variables.COLUMN_NAME[0], tempDate, Variables.COLUMN_NAME[14]));
             if (tempdateTable.Rows.Count > 0)
             {
                 DataRow tempDataRow = tempdateTable.Rows[0];
                 this.TotalSummary.SalesReturnQuantity = tempDataRow[0].ToString();
                 this.TotalSummary.SalesReurnAmount = tempDataRow[1].ToString();
             }
         }
         else
         {
             throw new PetuniaException(Variables.ERROR_MESSAGES[0, 5]);
         }
     }
     catch (Exception error)
     {
         Mouse.OverrideCursor = null;
         Microsoft.Windows.Controls.MessageBox.Show(error.Message, Variables.ERROR_MESSAGES[0, 0], MessageBoxButton.OK, MessageBoxImage.Hand);
     }
     finally
     {
         tempdateTable.Dispose();
         mysqElement.Dispose();
         Mouse.OverrideCursor = null;
         this.SummaryButtonSearch.IsEnabled = true;
     }
 }