Пример #1
0
        private void Button_Click_2(object sender, RoutedEventArgs e)
        {
            InvoiceInfo ii = new InvoiceInfo();

            ii.Show();
            this.Hide();
        }
        private void Settings_Click(object sender, RoutedEventArgs e)
        {
            InvoiceInfo ii = new InvoiceInfo();

            ii.Show();
            this.Hide();
        }
Пример #3
0
        private void detailsButton_Click(object sender, RoutedEventArgs e)
        {
            byte[] file = null;
            if (!string.IsNullOrEmpty(filename))
            {
                using (var stream = new FileStream(filename, FileMode.Open, FileAccess.Read))
                {
                    using (var reader = new BinaryReader(stream))
                    {
                        file = reader.ReadBytes((int)stream.Length);
                    }
                }
            }

            string connectionstring = null;

            connectionstring = myConnection.connectionString();
            MySqlConnection cnn = new MySqlConnection(connectionstring);

            cnn.Open();
            MySqlCommand command = cnn.CreateCommand();

            command.Parameters.AddWithValue("@userid", LoginWindow.id);
            command.CommandText = "SELECT * FROM info WHERE userid=@userid";
            MySqlDataReader reader2 = command.ExecuteReader();

            if (reader2.HasRows == true) //if info exists for the current id, execute update
            {
                cnn.Close();
                cnn.Open();
                command = cnn.CreateCommand();
                command.Parameters.AddWithValue("@userid", LoginWindow.id);

                if (file == null)
                {
                    file = data;
                }
                command.Parameters.Add("@File", MySqlDbType.VarBinary, file.Length).Value = file;
                command.Parameters.AddWithValue("@logo", file);
                TextRange    tr = new TextRange(descrField.Document.ContentStart, descrField.Document.ContentEnd);
                MemoryStream ms = new MemoryStream();
                tr.Save(ms, DataFormats.Rtf);
                command.Parameters.AddWithValue("@description", ASCIIEncoding.Default.GetString(ms.ToArray()));
                command.Parameters.AddWithValue("@details", detailsField.Text);
                command.Parameters.AddWithValue("@tax", taxtext.Text);
                command.Parameters.AddWithValue("@bank1", bank1Field.Text);
                command.Parameters.AddWithValue("@bank2", bank2Field.Text);
                command.Parameters.AddWithValue("@bank3", bank3Field.Text);
                command.Parameters.AddWithValue("@bank4", bank4Field.Text);
                command.Parameters.AddWithValue("@banknum1", banknum1Field.Text);
                command.Parameters.AddWithValue("@banknum2", banknum2Field.Text);
                command.Parameters.AddWithValue("@banknum3", banknum3Field.Text);
                command.Parameters.AddWithValue("@banknum4", banknum4Field.Text);
                command.Parameters.AddWithValue("@iban1", iban1Field.Text);
                command.Parameters.AddWithValue("@iban2", iban2Field.Text);
                command.Parameters.AddWithValue("@iban3", iban3Field.Text);
                command.Parameters.AddWithValue("@iban4", iban4Field.Text);
                command.CommandText = "UPDATE info SET userid=@userid, logo=@logo, description=@description, details=@details, tax=@tax, bank1=@bank1, bank2=@bank2, " +
                                      "bank3=@bank3, bank4=@bank4, banknum1=@banknum1, banknum2=@banknum2, banknum3=@banknum3, banknum4=@banknum4, iban1=@iban1, iban2=@iban2, iban3=@iban3, iban4=@iban4";

                if (command.ExecuteNonQuery() > 0)
                {
                    MessageBox.Show("Invoice Informations were successfuly updated.");
                    InvoiceInfo ii = new InvoiceInfo();
                    ii.Show();
                    this.Hide();
                }
                else
                {
                    MessageBox.Show("Record was not added!");
                }
                cnn.Close();
            }
            else //if there is no info already, execute insert
            {
                connectionstring = myConnection.connectionString();
                cnn = new MySqlConnection(connectionstring);
                cnn.Open();
                command = cnn.CreateCommand();
                command.Parameters.AddWithValue("@userid", LoginWindow.id);
                command.Parameters.Add("@File", MySqlDbType.VarBinary, file.Length).Value = file;
                command.Parameters.AddWithValue("@logo", file);
                string richText = new TextRange(descrField.Document.ContentStart, descrField.Document.ContentEnd).Text;
                command.Parameters.AddWithValue("@description", richText);
                command.Parameters.AddWithValue("@details", detailsField.Text);
                command.Parameters.AddWithValue("@tax", taxtext.Text);
                command.Parameters.AddWithValue("@bank1", bank1Field.Text);
                command.Parameters.AddWithValue("@bank2", bank2Field.Text);
                command.Parameters.AddWithValue("@bank3", bank3Field.Text);
                command.Parameters.AddWithValue("@bank4", bank4Field.Text);
                command.Parameters.AddWithValue("@banknum1", banknum1Field.Text);
                command.Parameters.AddWithValue("@banknum2", banknum2Field.Text);
                command.Parameters.AddWithValue("@banknum3", banknum3Field.Text);
                command.Parameters.AddWithValue("@banknum4", banknum4Field.Text);
                command.Parameters.AddWithValue("@iban1", iban1Field.Text);
                command.Parameters.AddWithValue("@iban2", iban2Field.Text);
                command.Parameters.AddWithValue("@iban3", iban3Field.Text);
                command.Parameters.AddWithValue("@iban4", iban4Field.Text);
                command.CommandText = "INSERT INTO info (userid, logo, description, details, tax, bank1, bank2, bank3, bank4, banknum1, banknum2, banknum3, banknum4, iban1, iban2, iban3, iban4) VALUES (@userid, @logo, @description, @details, @tax, @bank1, @bank2, @bank3, @bank4, @banknum1, @banknum2, @banknum3, @banknum4, @iban1, @iban2, @iban3, @iban4)";

                if (command.ExecuteNonQuery() >= 0)
                {
                    MessageBox.Show("Invoice Informations were successfuly saved.");
                    InvoiceInfo ii = new InvoiceInfo();
                    ii.Show();
                    this.Hide();
                }
                else
                {
                    MessageBox.Show("Record was not added!");
                }
                cnn.Close();
            }
        }