Esempio n. 1
0
 public void SaveQuoteToCSV(DeskQoute Quote)
 {
     //open file for writting
     using (StreamWriter sw = new StreamWriter("qoutes.txt", append: true))
     {
         string line = "";
         //loop through quote object and get properties. I had text qualifier just for fun (because I want an A)
         foreach (var property in Quote.GetType().GetProperties())
         {
             line += property.GetValue(Quote, null) + "|";
         }
         //must loop through desk object for it's properties
         foreach (var property in Quote.Desk.GetType().GetProperties())
         {
             line += property.GetValue(Quote.Desk, null) + "|";
         }
         sw.WriteLine(line.Remove(line.Length - 1));//strip off last , so it is a well formed CSV
     }
 }
Esempio n. 2
0
        private void generateQuote_btn_Click(object sender, EventArgs e)
        {
            try
            {
                //check for required and collect values
                string errorMessage = "";

                if (CustomerName_tb.Text == string.Empty)
                {
                    //MessageBox.Show("Please enter a Customer Name");
                    errorMessage += "Customer Name is Required\n";
                    CustomerName_tb.BackColor = Color.Aqua;
                }

                if (DeskWidth_tb.Text == string.Empty)
                {
                    errorMessage          += "Desk Width is Required\n";
                    DeskWidth_tb.BackColor = Color.Aqua;
                }

                if (DeskDepth_tb.Text == string.Empty)
                {
                    errorMessage          += "Desk Depth is Required\n";
                    DeskDepth_tb.BackColor = Color.Aqua;
                }

                if (SurfaceMaterial_tb.SelectedIndex < 0)
                {
                    errorMessage += "Surface Material is Required\n";
                    SurfaceMaterial_tb.BackColor = Color.Aqua;
                }

                if (errorMessage.Length > 0)
                {
                    MessageBox.Show(errorMessage);
                    return;
                }

                CustomerName    = CustomerName_tb.Text;
                DeskWidth       = int.Parse(DeskWidth_tb.Text);
                DeskDepth       = int.Parse(DeskDepth_tb.Text);
                surfaceMaterial = (SurfaceMaterial)SurfaceMaterial_tb.SelectedValue;

                Drawers = Decimal.ToInt32(DeskDrawers_tb.Value);

                if (radioButtonStandard.Checked)
                {
                    RushDays = 14;
                }
                if (radioButton7Day.Checked)
                {
                    RushDays = 7;
                }
                if (radioButton5Day.Checked)
                {
                    RushDays = 5;
                }
                if (radioButton3Day.Checked)
                {
                    RushDays = 3;
                }

                //now we have our parts so create the qoute object by calling the constructor
                NewQuote = new DeskQoute(CustomerName, DateTime.Now, DeskWidth, DeskDepth, Drawers, surfaceMaterial, RushDays);

                //let user know it worked
                MessageBox.Show("New Qoute Successful.\nQuoute total:" + NewQuote.QuoteTotal.ToString("C2"));
            }
            catch (Exception exception)
            {
                Console.WriteLine("Generic Exception Handler: {0}", exception.ToString());
            }

            //save DeskQuote as CSV file
            try
            {
                SaveQuoteToCSV(NewQuote);
            }
            catch (IOException ex)
            {
                MessageBox.Show(ex.Message);
            }

            //all done, so refresh form
            FormReset(); //not working so just go back to main menu
        }