Ejemplo 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);
        }
        private void BtnNewService_add_Click(object sender, RoutedEventArgs e)
        {
            //For insertion Done
            string name        = txbNewService_name.Text;
            string address     = txbNewService_address.Text;
            string telephone   = txbNewService_telephone.Text;
            string emailadress = txbNewService_email.Text;
            string fax         = txbNewService_fax.Text;
            string cellphone   = txbNewService_cellphone.Text;
            string service     = cbbNewService_entities.SelectionBoxItem.ToString();
            string postalcode  = txbNewService_areaCode.Text;
            string agency_ID   = GeneralMethods.makeAgency_ID(name, postalcode);

            //Query for inserting the service provider
            try
            {
                NpgsqlConnection myConnect = new NpgsqlConnection(MainWindow.ConnectionString);
                myConnect.Open();
                using (var cmd = new NpgsqlCommand($"INSERT INTO agencydetails (agency_id,nameofagency,address,telephone,emailaddress,fax,cellphone,service) VALUES (@agency_id,@nameofagency,@address,@telephone,@emailaddress,@fax,@cellphone,@service)", myConnect))
                {
                    cmd.Parameters.AddWithValue("agency_id", agency_ID);
                    cmd.Parameters.AddWithValue("nameofagency", name);
                    cmd.Parameters.AddWithValue("address", address);
                    cmd.Parameters.AddWithValue("telephone", telephone);
                    cmd.Parameters.AddWithValue("emailaddress", emailadress);
                    cmd.Parameters.AddWithValue("fax", fax);
                    cmd.Parameters.AddWithValue("cellphone", cellphone);
                    cmd.Parameters.AddWithValue("service", service);
                    cmd.ExecuteNonQuery();
                }
                MessageBox.Show($"Successfully added into database. Agency_Id is: {agency_ID}");
            }
            catch (Exception h)
            {
                MessageBox.Show(h.ToString());
            }
        }
        /// <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);
            }
        }
        private void btnConsultant_Voucher_addNewVoucher_Click(object sender, RoutedEventArgs e)
        {
            voucher_no = GeneralMethods.makeVoucher_no();
            txbConsultsnt_Vouchers_outputVoucherNumber.Text = voucher_no;

            //Query for retrieving client_id
            try
            {
                NpgsqlConnection myConnect = new NpgsqlConnection(MainWindow.ConnectionString);
                myConnect.Open();

                using (var cmd = new NpgsqlCommand($"SELECT client_no FROM orders,client WHERE order_no = '{order_no}' AND orders.quote_no=client.quote_no", myConnect))
                {
                    NpgsqlDataReader query = cmd.ExecuteReader();
                    while (query.Read())
                    {
                        client_id = query[0].ToString();
                    }
                    myConnect.Close();
                }
            }
            catch (Exception h)
            {
                MessageBox.Show(h.ToString());
            }

            //Query for retrieving voucher amount
            try
            {
                NpgsqlConnection myConnect = new NpgsqlConnection(MainWindow.ConnectionString);
                myConnect.Open();

                using (var cmd = new NpgsqlCommand($"SELECT amount FROM orders, quote WHERE order_no = '{order_no}' AND orders.quote_no=quote.quote_no", myConnect))
                {
                    NpgsqlDataReader query = cmd.ExecuteReader();
                    while (query.Read())
                    {
                        Voucheramount = Convert.ToDouble(query[0].ToString());
                    }
                    myConnect.Close();
                }
            }
            catch (Exception h)
            {
                MessageBox.Show(h.ToString());
            }

            //Query for retrieving accomm_id
            //try
            //{
            //    NpgsqlConnection myConnect = new NpgsqlConnection(MainWindow.ConnectionString);
            //    myConnect.Open();

            //    using (var cmd = new NpgsqlCommand($"SELECT accomm_id FROM orders,accommodation WHERE order_no = '{order_no}' AND orders.quote_no=accommmodation.quote_no", myConnect))
            //    {
            //        NpgsqlDataReader query = cmd.ExecuteReader();
            //        while (query.Read())
            //        {
            //            accomm_ID = query[0].ToString();
            //        }
            //        myConnect.Close();
            //    }
            //}
            //catch (Exception h)
            //{
            //    MessageBox.Show(h.ToString());
            //}

            //Query for retrieving agency_id
            try
            {
                NpgsqlConnection myConnect = new NpgsqlConnection(MainWindow.ConnectionString);
                myConnect.Open();

                using (var cmd = new NpgsqlCommand($"SELECT agencyids FROM orders,quote WHERE order_no = '{order_no}' AND orders.quote_no=quote.quote_no", myConnect))
                {
                    NpgsqlDataReader query = cmd.ExecuteReader();
                    while (query.Read())
                    {
                        agency_ID = query[0].ToString();
                    }
                    myConnect.Close();
                }
            }
            catch (Exception h)
            {
                MessageBox.Show(h.ToString());
            }

            //Query for retrieving staff_id
            try
            {
                NpgsqlConnection myConnect = new NpgsqlConnection(MainWindow.ConnectionString);
                myConnect.Open();

                using (var cmd = new NpgsqlCommand($"SELECT consultant_no FROM orders,quote WHERE orders.quote_no=quote.quote_no", myConnect))
                {
                    NpgsqlDataReader query = cmd.ExecuteReader();
                    while (query.Read())
                    {
                        staff_ID = query[0].ToString();
                    }
                    myConnect.Close();
                }
            }
            catch (Exception h)
            {
                MessageBox.Show(h.ToString());
            }

            try
            {
                NpgsqlConnection myConnect = new NpgsqlConnection(MainWindow.ConnectionString);
                myConnect.Open();

                using (var cmd = new NpgsqlCommand($"INSERT INTO voucher (voucher_no,order_no,client_id,agency_id,staff_id,amount) VALUES (@voucher_no,@order_no,@client_id,@agency_id,@staff_id,@amount)", myConnect))
                {
                    cmd.Parameters.AddWithValue("voucher_no", voucher_no);
                    cmd.Parameters.AddWithValue("order_no", order_no);
                    cmd.Parameters.AddWithValue("client_id", client_id);
                    cmd.Parameters.AddWithValue("agency_id", agency_ID);
                    cmd.Parameters.AddWithValue("staff_id", staff_ID);
                    cmd.Parameters.AddWithValue("amount", Voucheramount);
                    cmd.ExecuteNonQuery();
                }
            }
            catch (Exception h)
            {
                MessageBox.Show(h.ToString());
            }
        }
 private void validateNumber(object sender, TextChangedEventArgs e)
 {
     GeneralMethods.checkPhoneNumber((TextBox)sender);
 }
 private void validateValue(object sender, TextChangedEventArgs e)
 {
     GeneralMethods.checkAmountTyped((TextBox)sender);
 }
        //private void LtbConsultant_Search_Results_SelectionChanged(object sender, SelectionChangedEventArgs e)
        //{
        //    // get the index of the selected item
        //    int indexPath = lblConsultant_inboxList.SelectedIndex;
        //    if (indexPath >= 0)
        //    {
        //        // the textbox that has the details
        //        TextBlock id = (TextBlock)lblConsultant_inboxList.SelectedItem;

        //        // change the font
        //        id.FontSize = 16;

        //        // get the ID
        //        lblConsultantID.Content = id.Text;

        //        // Assign the new button
        //        lblConsultant_inboxList.Items.RemoveAt(indexPath);
        //        lblConsultant_inboxList.Items.Insert(indexPath, id);

        //        // get the ID of the reciever
        //        string idContent = currentStaffID.ToLower();

        //        // get the index of the entry
        //        int idNum = Convert.ToInt32(id.Tag);

        //        // read the selected entry
        //        readSelectedID(idContent, idNum);

        //        // enable
        //        composeMessageWindow.txbMessage_message.IsEnabled = true;
        //        composeMessageWindow.btnMessage_send.IsEnabled = true;
        //    }
        //}

        /// <summary>
        /// Going to the Search results window if anything is picked from the list
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void LtbConsultant_Search_Results_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            string        qoviNum             = ltbConsultant_Search_Results.SelectedItem.ToString(); //order/quote/invoice/voucher number that has been selected by the user
            SearchResults searchResultsWindow = new SearchResults();

            searchResultsWindow.Owner = this;
            searchResultsWindow.Show();
            searchResultsWindow.tbkSearchResults.Text = "";
            NpgsqlConnection myConnect = new NpgsqlConnection(MainWindow.ConnectionString);

            //Display quotes
            try
            {
                myConnect.Open();
                NpgsqlCommand    cmdView = new NpgsqlCommand($"SELECT service FROM quote WHERE quote_no = '{qoviNum}'", myConnect);
                NpgsqlDataReader drView  = cmdView.ExecuteReader();
                while (drView.Read())
                {
                    searchResultsWindow.tbkSearchResults.Text  = GeneralMethods.quoteSummary(qoviNum.Replace(" ", ""), drView[0].ToString()); //Viewing the selected quote's summary in the new window
                    searchResultsWindow.tbkSearchResults.Text += GeneralMethods.quoteSummaryAmounts(qoviNum);
                }
                myConnect.Close();
            }
            catch (Exception h)
            {
                MessageBox.Show(h.ToString());
            }
            //End display quote

            //Display order

            //End display order

            //Display voucher
            //End display voucher

            //Display invoice
            //End display invoice

            //Display staff, client or service proivder
            switch (cbxStatus)
            {
            case "Staff":
                try
                {
                    myConnect.Open();
                    NpgsqlCommand    cmdStaff = new NpgsqlCommand($"SELECT staff_id, stafffirstnames, stafflastname, staffposition,email,cellphone,telephone,fax,address FROM staff WHERE staff_id = '{ltbConsultant_Search_Results.SelectedItem.ToString().Remove(0, ltbConsultant_Search_Results.SelectedItem.ToString().IndexOf(',') + 1).Replace(" ", "")}'", myConnect);  //Removes the name of the staff because I'm seraching it with the staff_id in the databse
                    NpgsqlDataReader drStaff  = cmdStaff.ExecuteReader();
                    while (drStaff.Read())
                    {
                        searchResultsWindow.tbkSearchResults.Text = $" Staff Id: {drStaff[0]} \n Name: {drStaff[1]} {drStaff[2]} \n Position: {drStaff[3]} \n Email: {drStaff[4]} \n Cellphone: {drStaff[5]} \n Telephone: {drStaff[6]} \n Fax: {drStaff[7]} \n Address: {drStaff[8]}";     //Viewing the selected staff member's summary in the new window
                    }
                    myConnect.Close();
                }
                catch (Exception h)
                {
                    MessageBox.Show(h.ToString());
                }
                break;

            case "Clients":
                try
                {
                    myConnect.Open();
                    NpgsqlCommand    cmdClients = new NpgsqlCommand($"SELECT client_no,clientname,emailaddress,cellphone,telephone,fax,address FROM client WHERE client_no = '{ltbConsultant_Search_Results.SelectedItem.ToString().Remove(0, ltbConsultant_Search_Results.SelectedItem.ToString().IndexOf(',') + 1).Replace(" ", "")}'", myConnect);  //Removes the name of the staff because I'm seraching it with the staff_id in the databse
                    NpgsqlDataReader drClients  = cmdClients.ExecuteReader();
                    while (drClients.Read())
                    {
                        searchResultsWindow.tbkSearchResults.Text = $" Client No.: {drClients[0]} \n Name: {drClients[1]} \n Email: {drClients[2]} \n Cellphone: {drClients[3]} \n Telephone: {drClients[4]} \n Fax: {drClients[5]} \n Address: {drClients[6]}";     //Viewing the selected staff member's summary in the new window
                    }
                    myConnect.Close();
                }
                catch (Exception h)
                {
                    MessageBox.Show(h.ToString());
                }
                break;

            case "Service Providers":
                try
                {
                    myConnect.Open();
                    NpgsqlCommand    cmdServiceP = new NpgsqlCommand($"SELECT agency_id, agencyname, emailaddress, cellphone, telephone, fax, address FROM serviceproviders WHERE agency_id = '{ltbConsultant_Search_Results.SelectedItem.ToString().Remove(0, ltbConsultant_Search_Results.SelectedItem.ToString().IndexOf(',') + 1).Replace(" ", "")}'", myConnect);  //Removes the name of the staff because I'm seraching it with the staff_id in the databse
                    NpgsqlDataReader drServiceP  = cmdServiceP.ExecuteReader();
                    while (drServiceP.Read())
                    {
                        searchResultsWindow.tbkSearchResults.Text = $" Agency ID: {drServiceP[0]} \n Name: {drServiceP[1]} \n Email: {drServiceP[2]} \n Cellphone {drServiceP[3]} \n Telephone: {drServiceP[4]} \n Fax: {drServiceP[5]} \n Address: {drServiceP[6]}";
                    }
                    myConnect.Close();
                }
                catch (Exception h)
                {
                    MessageBox.Show(h.ToString());
                }
                break;
            }
            //End display staff, client or service provider
        }
 private void BtnConsultant_logOut_Click(object sender, RoutedEventArgs e)
 {
     GeneralMethods.logOut(this);
 }
Ejemplo n.º 9
0
 private void Manager_Home1_Closed(object sender, EventArgs e)
 {
     GeneralMethods.CloseAllWindows();
 }
Ejemplo n.º 10
0
 private void BtnOwner_logOut_Click_1(object sender, RoutedEventArgs e)
 {
     GeneralMethods.logOut(this);
 }
Ejemplo n.º 11
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");
                //    }
                //}
            }
        }
Ejemplo n.º 12
0
 private void TxbNewEmployee_salary_TextChanged(object sender, TextChangedEventArgs e)
 {
     GeneralMethods.checkAmountTyped((TextBox)sender, false);
 }
Ejemplo n.º 13
0
 private void btnManager_logOut_Click(object sender, RoutedEventArgs e)
 {
     GeneralMethods.logOut(this);
 }
Ejemplo n.º 14
0
 private void Home_Page_Closed(object sender, EventArgs e)
 {
     GeneralMethods.closeAllWindows();
 }