Esempio n. 1
0
        private void BtnCarDetails_Click(object sender, RoutedEventArgs e)
        {
            FinalPage finalPage = new FinalPage();

            finalPage.Show();
            this.Close();
        }
Esempio n. 2
0
        //Logic for clearing the fields

        private void btnClear_Click(object sender, RoutedEventArgs e)
        {
            clear();
            FinalPage finPage = new FinalPage();

            this.Close();
            finPage.ShowDialog();
            try { this.Show(); }
            catch
            {
            }
        }
        /*Logic for loggimg into
         * Admin Section*/

        private void Btnlogin_Click(object sender, RoutedEventArgs e)
        {
            string configManager = ConfigurationManager.ConnectionStrings["databaseConnString"].ConnectionString;

            using (SqlConnection sqlCon = new SqlConnection(configManager))
            {
                String        query  = "select count(1) from Admin where UserName=@UserName AND Password=@Password";
                SqlCommand    sqlCmd = new SqlCommand(query, sqlCon);
                StringBuilder sb     = new StringBuilder();

                sqlCmd.Parameters.AddWithValue("@UserName", txtName.Text);

                sqlCmd.Parameters.AddWithValue("@Password", pwdPassword.Password);

                try
                {
                    sqlCon.Open();
                    sqlCmd.CommandType = CommandType.Text;
                    int count = Convert.ToInt32(sqlCmd.ExecuteScalar());
                    if (count == 1)
                    {
                        FinalPage finalPage = new FinalPage();
                        finalPage.Show();
                        this.Close();
                    }
                    else
                    {
                        MessageBox.Show("Username or Password incorrect.");
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message.ToString());
                }
                finally
                {
                    sqlCon.Close();
                }
            }
        }
Esempio n. 4
0
        /*Logic for adding new information
         * to the CAR table*/

        private void BtnAdd_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                StringBuilder sb      = new StringBuilder();
                int           invalid = 0;
                using (cims)
                {
                    CAR car = new CAR();
                    if (!(Regex.IsMatch(txtmodel.Text, @"^\w+\s*\w*$")))
                    {
                        invalid = 1;
                        sb.Append(Environment.NewLine + "Model cannot be blank and must be in proper format.");
                    }
                    else
                    {
                        car.Model = txtmodel.Text;
                    }

                    if (cmbManufacturer.SelectedValue != null)
                    {
                        car.ManufacturerId = Convert.ToInt32(cmbManufacturer.SelectedValue.ToString());
                    }
                    else
                    {
                        invalid = 1;
                        sb.Append(Environment.NewLine + "Please Select Manufacturer.");
                    }

                    if (cmbType.SelectedValue != null)
                    {
                        car.TypeId = Convert.ToInt32(cmbType.SelectedValue.ToString());
                    }
                    else
                    {
                        invalid = 1;
                        sb.Append(Environment.NewLine + "Please Select Car Type.");
                    }

                    if (!(Regex.IsMatch(txtEngine.Text, @"^[0-9].[0-9]L$")))
                    {
                        invalid = 1;
                        sb.Append(Environment.NewLine + "Engine should be in proper format(e.g. 3.5L).");
                    }
                    else
                    {
                        car.Engine = txtEngine.Text;
                    }

                    if (!(Regex.IsMatch(txtBHP.Text, @"^\d+$")))
                    {
                        invalid = 1;
                        sb.Append(Environment.NewLine + "BHP cannot be blank and must be numeric.");
                    }
                    else
                    {
                        car.BHP = Convert.ToInt32(txtBHP.Text);
                    }

                    if (cmbTransmission.SelectedValue != null)
                    {
                        car.TransmissionId = Convert.ToInt32(cmbTransmission.SelectedValue.ToString());
                    }
                    else
                    {
                        invalid = 1;
                        sb.Append(Environment.NewLine + "Please Select Car Transmission.");
                    }

                    if (!(Regex.IsMatch(txtMileage.Text, @"^\d+$")))
                    {
                        invalid = 1;
                        sb.Append(Environment.NewLine + "Mileage cannot be blank and must be numeric.");
                    }
                    else
                    {
                        car.Mileage = Convert.ToInt32(txtMileage.Text);
                    }

                    if (!(Regex.IsMatch(txtSeat.Text, @"^\d+$")))
                    {
                        invalid = 1;
                        sb.Append(Environment.NewLine + "Seat cannot be blank and must be numeric.");
                    }
                    else
                    {
                        car.Seat = Convert.ToInt32(txtSeat.Text);
                    }

                    if (!(Regex.IsMatch(txtAirbagDetails.Text, @"^\w+$")))
                    {
                        invalid = 1;
                        sb.Append(Environment.NewLine + "Airbag details cannot be blank.");
                    }
                    else
                    {
                        car.AirBagDetails = txtAirbagDetails.Text;
                    }

                    if (!(Regex.IsMatch(txtBootspace.Text, @"^\d+\s*\w*$")))
                    {
                        invalid = 1;
                        sb.Append(Environment.NewLine + "Bootspace cannot be blank.");
                    }
                    else
                    {
                        car.BootSpace = txtBootspace.Text;
                    }

                    if (!(Regex.IsMatch(txtPrice.Text, @"^\d+$")))
                    {
                        invalid = 1;
                        sb.Append(Environment.NewLine + "Price cannot be blank and must be numeric.");
                    }
                    else
                    {
                        car.Price = Convert.ToInt64(txtPrice.Text);
                    }

                    if (invalid == 1)
                    {
                        MessageBox.Show(sb.ToString());
                    }
                    else
                    {
                        cims.CARs.Add(car);

                        cims.SaveChanges();

                        MessageBox.Show("1 Record Added");
                    }
                }

                FinalPage finPage = new FinalPage();
                this.Close();
                finPage.ShowDialog();
                try { this.Show(); }
                catch
                {
                }
            }

            catch (Exception ex)
            {
                MessageBox.Show(ex.Message.ToString());
            }
        }