Esempio n. 1
0
        private void openToolStripMenuItem_Click(object sender, EventArgs e)
        {
            dlgOpen.InitialDirectory = @"C:\College Park Auto Repair";

            if (dlgOpen.ShowDialog() == DialogResult.OK)
            {
                FileStream stmRepair = new FileStream(dlgOpen.FileName,
                                                      FileMode.Open);
                BinaryFormatter bnrRepair = new BinaryFormatter();
                RepairOrder     order     = (RepairOrder)bnrRepair.Deserialize(stmRepair);

                txtCustomerName.Text = order.CustomerName;
                txtAddress.Text      = order.Address;
                txtCity.Text         = order.City;
                txtState.Text        = order.State;
                txtZIPCode.Text      = order.ZIPCode;
                txtMake.Text         = order.Make;
                txtModel.Text        = order.Model;
                txtYear.Text         = order.Year.ToString();
                txtProblem.Text      = order.ProblemDescription;

                int i = 0;
                foreach (Part prt in order.Parts)
                {
                    dgvPartsUsed.Rows.Add();

                    dgvPartsUsed.Rows[i].Cells[0].Value = prt.PartName;
                    dgvPartsUsed.Rows[i].Cells[1].Value = prt.UnitPrice.ToString("F");
                    dgvPartsUsed.Rows[i].Cells[2].Value = prt.Quantity.ToString();
                    dgvPartsUsed.Rows[i].Cells[3].Value = prt.SubTotal.ToString("F");
                    i++;
                }

                i = 0;
                foreach (JobPerformed jp in order.Jobs)
                {
                    dgvJobsPerformed.Rows.Add();

                    dgvJobsPerformed.Rows[i].Cells[0].Value = jp.Job;
                    dgvJobsPerformed.Rows[i].Cells[1].Value = jp.Cost;
                    i++;
                }

                txtTotalParts.Text      = order.TotalParts.ToString("F");
                txtTotalLabor.Text      = order.TotalLabor.ToString("F");
                txtTaxRate.Text         = order.TaxRate.ToString("F");
                txtTaxAmount.Text       = order.TaxAmount.ToString("F");
                txtRepairTotal.Text     = order.RepairTotal.ToString("F");
                txtRecommendations.Text = order.Recommendations;

                stmRepair.Close();
            }
        }
Esempio n. 2
0
        private void saveAsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            CalculateTotal();

            string        strDirectory = @"C:\College Park Auto Repair";
            DirectoryInfo dirInfo      = Directory.CreateDirectory(strDirectory);

            RepairOrder order = new RepairOrder();

            dlgSave.InitialDirectory = strDirectory;

            if (dlgSave.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                order.CustomerName       = txtCustomerName.Text;
                order.Address            = txtAddress.Text;
                order.City               = txtCity.Text;
                order.State              = txtState.Text;
                order.ZIPCode            = txtZIPCode.Text;
                order.Make               = txtMake.Text;
                order.Model              = txtModel.Text;
                order.Year               = Convert.ToInt32(txtYear.Text);
                order.ProblemDescription = txtProblem.Text;

                if (dgvPartsUsed.Rows.Count > 1)
                {
                    List <Part> parts = new List <Part>();

                    for (int row = 0; row < dgvPartsUsed.Rows.Count - 1; row++)
                    {
                        Part prt = new Part();
                        prt.PartName  = dgvPartsUsed.Rows[row].Cells[0].EditedFormattedValue.ToString();
                        prt.UnitPrice = double.Parse(dgvPartsUsed.Rows[row].Cells[1].EditedFormattedValue.ToString());
                        prt.Quantity  = int.Parse(dgvPartsUsed.Rows[row].Cells[2].EditedFormattedValue.ToString());
                        prt.SubTotal  = double.Parse(dgvPartsUsed.Rows[row].Cells[3].EditedFormattedValue.ToString());
                        parts.Add(prt);
                    }
                    order.Parts = parts;
                }
                else
                {
                    order.Parts = null;
                }

                if (dgvJobsPerformed.Rows.Count > 1)
                {
                    List <JobPerformed> work = new List <JobPerformed>();

                    for (int row = 0; row < dgvJobsPerformed.Rows.Count - 1; row++)
                    {
                        JobPerformed done = new JobPerformed();
                        done.Job  = dgvJobsPerformed.Rows[row].Cells[0].EditedFormattedValue.ToString();
                        done.Cost = double.Parse(dgvJobsPerformed.Rows[row].Cells[1].EditedFormattedValue.ToString());
                        work.Add(done);
                    }

                    order.Jobs = work;
                }

                order.TotalParts      = double.Parse(txtTotalParts.Text);
                order.TotalLabor      = double.Parse(txtTotalLabor.Text);
                order.TaxRate         = double.Parse(txtTaxRate.Text);
                order.TaxAmount       = double.Parse(txtTaxAmount.Text);
                order.RepairTotal     = double.Parse(txtRepairTotal.Text);
                order.Recommendations = txtRecommendations.Text;

                FileStream stmRepair = new FileStream(dlgSave.FileName,
                                                      FileMode.Create);
                BinaryFormatter bfmRepair = new BinaryFormatter();
                bfmRepair.Serialize(stmRepair, order);

                stmRepair.Close();
                newToolStripMenuItem_Click(sender, e);
            }
        }