Esempio n. 1
0
        private void BtnConsultant_Orders_addNewOrder_Click(object sender, RoutedEventArgs e)
        {
            // Extract and assign to variables
            order_no = txbConsultant_Orders_orderNumber.Text;
            string orderDate = txbConsultant_Orders_orderdate.Text;

            // check if the textboxes are empty or the strings associated with the textboxes
            bool checkEmptyStringBool = GeneralMethods.checkEmptytxtBox(order_no);

            try
            {
                NpgsqlConnection myConnect = new NpgsqlConnection(MainWindow.ConnectionString);
                myConnect.Open();
                using (var cmd = new NpgsqlCommand($"INSERT INTO orders (quote_no,order_no,datereceived,orderdate) VALUES (@quote_no,@order_no,@datereceived,@orderdate)", myConnect))
                {
                    cmd.Parameters.AddWithValue("quote_no", quote_no);
                    cmd.Parameters.AddWithValue("order_no", order_no);
                    cmd.Parameters.AddWithValue("datereceived", DateTime.Today.ToString().Substring(0, 10));
                    cmd.Parameters.AddWithValue("orderdate", orderDate);
                    cmd.ExecuteNonQuery();
                    MessageBox.Show("Successfully added into the database.");
                }
            }
            catch (Exception h)
            {
                MessageBox.Show(h.ToString());
            }


            // Display data from the database which is belongs to the current quote number
            // 1. Assign the the data to variables so that it becomes easy to store the database again when creating a new order
            // 2. Display the data in the textbox



            // reset the textboxes
            GeneralMethods.clearTextBoxes(txbConsultant_Orders_orderNumber, txbConsultant_Orders_inputQuote);
        }
        /// <summary>
        /// Send a message.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void BtnMessage_send_Click(object sender, RoutedEventArgs e)
        {
            // extract the value and assign them to variables
            if (SearchResultComboBox.SelectedIndex < 0)
            {
                return;
            }

            string staffTo          = SearchResultComboBox.SelectedItem.ToString();
            string subjectOFmassage = txbMessage_subject.Text;
            string message          = txbMessage_message.Text;

            // CHECK FOR ERRORS
            // 1. check if the staff id or name exist in the databse
            // 2. check empty textboxes/variables

            // 1.

            // 2.
            string[] stringVs = new string[] {
                subjectOFmassage,
                message
            };

            bool t_or_f = GeneralMethods.checkEmptytxtBox(stringVs);

            if (!t_or_f)
            {
                // .. todo

                insertMessage(currentStaffID, staffTo, message);
                txbMessage_message.Text = "";

                // clear the textboxes
                GeneralMethods.clearTextBoxes(txbMessage_subject, txbMessage_message);
            }
        }
Esempio n. 3
0
        private void BtnNewEmployee_generate_Click(object sender, RoutedEventArgs e)
        {
            bool boolValue = GeneralMethods.checkEmptytxtBox(txbNewEmployee_surname.Text,
                                                             txbNewEmployee_name.Text, txbNewEmployee_address.Text,
                                                             txbEmployee_cellphone.Text, txbNewEmployee_telephone.Text, txbNewEmployee_fax.Text, txbNewEmployee_email.Text,
                                                             cmbNewEmployee_position.Text, txbNewEmployee_salary.Text);

            NpgsqlConnection myConnect = new NpgsqlConnection(MainWindow.ConnectionString);

            if (!boolValue) //if all the text boxes are fine then this code will execute
            {
                //Extracting Informtaion
                string Surname     = txbNewEmployee_surname.Text;
                string Name        = txbNewEmployee_name.Text;
                string FullAddress = txbNewEmployee_address.Text;
                string Cellphone   = txbEmployee_cellphone.Text;
                string Telephone   = txbNewEmployee_telephone.Text;
                string Fax         = txbNewEmployee_fax.Text;
                string Email       = txbNewEmployee_email.Text;
                string Position    = cmbNewEmployee_position.Text;
                double Salary      = Convert.ToDouble(txbNewEmployee_salary.Text);

                try
                {
                    myConnect.Open();
                    NpgsqlCommand myCommand = new NpgsqlCommand($"INSERT INTO staff (staff_id, stafffirstnames,stafflastname,address,cellphone,telephone,fax,staffposition,salary,dateofhire,emailaddress) " +
                                                                $"VALUES ('{GeneralMethods.makeStaffID(Surname, Cellphone)}', '{Name}', '{Surname}', '{FullAddress}', '{Cellphone}', '{Telephone}', '{Fax}', '{Position}', '{Salary}', '{dateofhire}','{Email}') ", myConnect);
                    myCommand.ExecuteNonQuery();

                    GeneralMethods.clearTextBoxes(txbNewEmployee_surname, txbNewEmployee_name, txbNewEmployee_address,
                                                  txbEmployee_cellphone, txbNewEmployee_telephone,
                                                  txbNewEmployee_fax, txbNewEmployee_email, txbNewEmployee_salary);
                    myConnect.Close();
                }
                catch (Exception h)
                {
                    MessageBox.Show(h.ToString());
                }

                //try
                //{
                //    myConnect = new NpgsqlConnection(MainWindow.ChatConnectionString);
                //    myConnect.Open();
                //    using (var cmd = new NpgsqlCommand($"INSERT INTO staff_members (staffid) VALUES (@staffid)", myConnect))
                //    {

                //        cmd.Parameters.AddWithValue("staffid", GeneralMethods.makeStaffID(Surname, Cellphone));
                //        cmd.ExecuteNonQuery();
                //        MessageBox.Show($"Successfully added into the database. New Employee ID is: {GeneralMethods.makeStaffID(Surname, Cellphone)}");
                //    }
                //}
                //catch (Exception h)
                //{
                //    MessageBox.Show(h.ToString());
                //}

                //// Creates a table in the database
                //using (var conn = new NpgsqlConnection(MainWindow.ChatConnectionString))
                //{
                //    // open the connection
                //    conn.Open();

                //    // create a table
                //    using (var cmd = new NpgsqlCommand())
                //    {
                //        cmd.Connection = conn;
                //        cmd.CommandText = string.Format("CREATE TABLE {0} ("
                //                                      + "tb_ID         serial          NOT NULL,"
                //                                      + "DateSent      varchar(30)     NOT NULL,"
                //                                      + "sender        varchar(30)     NOT NULL,"
                //                                      + "reciever      varchar(30)     NOT NULL,"
                //                                      + "message       varchar(500)    NOT NULL,"
                //                                      + "PRIMARY KEY(tb_ID)"
                //                                      + ")", GeneralMethods.makeStaffID(Surname, Cellphone));
                //        cmd.ExecuteNonQuery();
                //        MessageBox.Show("Table created", "Attention");
                //    }
                //}
            }
        }