private void BtnSave_Click_1(object sender, EventArgs e)
 {
     try
     {
         if (txtRoute.Text == String.Empty)
         {
             WarningIndicator.Visible = true;
             txtRoute.Focus();
             return;
         }
         if (MessageBox.Show("Are you sure you want to save this route?", "New Route", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
         {
             cn.Open();
             cm = new SqlCommand("INSERT INTO tblRoutes (route, datecreated) VALUES (@route, @date)", cn);
             cm.Parameters.AddWithValue("@route", txtRoute.Text);
             cm.Parameters.AddWithValue("@date", DateTime.Now);
             cm.ExecuteNonQuery();
             cn.Close();
             ClearRoute();
             rlist.ShowRoutes();
             this.Dispose();
             MessageBox.Show("Route has been successfully Saved", "Route Saved", MessageBoxButtons.OK, MessageBoxIcon.Information);
         }
     }
     catch (Exception ex)
     {
         cn.Close();
         MessageBox.Show(ex.Message);
     }
 }
示例#2
0
        private void BtnRoutes_Click(object sender, EventArgs e)
        {
            if (!AdminAdministrator.Instance.PnlContainer.Controls.ContainsKey("AdminRoutes"))
            {
                AdminRoutes route = new AdminRoutes();
                route.Dock = DockStyle.Fill;
                AdminAdministrator.Instance.PnlContainer.Controls.Add(route);

                route.ShowRoutes();
            }
            AdminAdministrator.Instance.PnlContainer.Controls["AdminRoutes"].BringToFront();
            AdminAdministrator.Instance.BackButton.Visible = true;
        }
        private void BtnSave_Click_1(object sender, EventArgs e)
        {
            if (txtCustomerName.Text == String.Empty)
            {
                WarningIndicator.Visible  = true;
                WarningIndicator.Location = new System.Drawing.Point(486, 104);
                txtCustomerName.Focus();
                return;
            }
            if (txtOwnerName.Text == String.Empty)
            {
                WarningIndicator.Visible  = true;
                WarningIndicator.Location = new System.Drawing.Point(486, 175);
                txtOwnerName.Focus();
                return;
            }
            if (txtAddress.Text == String.Empty)
            {
                WarningIndicator.Visible  = true;
                WarningIndicator.Location = new System.Drawing.Point(485, 246);
                txtAddress.Focus();
                return;
            }
            if (txtRoute.Text == String.Empty)
            {
                WarningIndicator.Visible  = true;
                WarningIndicator.Location = new System.Drawing.Point(276, 311);
                txtRoute.Focus();
                return;
            }
            else
            {
                cn.Open();
                cm = new SqlCommand("SELECT route FROM tblRoutes WHERE route = @route", cn);
                cm.Parameters.AddWithValue("@route", txtRoute.Text);
                da = new SqlDataAdapter(cm);
                dt = new DataTable();
                da.Fill(dt);
                cn.Close();

                if (dt.Rows.Count >= 1)
                {
                    InsertCustomerInformation();
                    MessageBox.Show("Customer Information Successfully Saved.", "Saving New Customer Informtaion", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    cn.Close();

                    ClearCustomer();
                    CSlist.ShowCustomersInformation();
                    this.Hide();
                }
                else if (dt.Rows.Count <= 0)
                {
                    InsertRoute();
                    AdminRoutes rout = new AdminRoutes();
                    rout.ShowRoutes();
                    InsertCustomerInformation();

                    MessageBox.Show("Customer Information Successfully Saved Into Database.", "Customer Information Saved", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    cn.Close();

                    ClearCustomer();
                    CSlist.ShowCustomersInformation();
                    this.Dispose();
                }
                else
                {
                    return;
                }
            }
        }