Example #1
0
        private void Button1_Click_1(object sender, EventArgs e)
        {
            Random rand = new Random();

            int Service_num = rand.Next(100, 1000);// creatingservice number

            try
            {
                string date = dateTimePicker1.Value.ToShortDateString();
                string service = "", employee = "";

                //adding the employee name and type of service
                if (checkBox1.Checked)
                {
                    service  += checkBox1.Text;
                    employee += "Sam Deker, ";
                }
                else
                {
                    service  += "";
                    employee += "";
                }

                if (checkBox2.Checked)
                {
                    service  += checkBox2.Text;
                    employee += "Stembiso Zwane,";
                }
                else
                {
                    service  += "";
                    employee += "";
                }

                if (checkBox3.Checked)
                {
                    service  += checkBox3.Text;
                    employee += "James Hlope";
                }
                else
                {
                    service  += "";
                    employee += "";
                }

                if (radioButton5.Checked)
                {
                    service  = radioButton5.Text;
                    employee = "David May";
                }
                else
                {
                    service  += "";
                    employee += "";
                }


                string Client_ID = Login.Client_ID;
                // adding service info to service table

                SqlConnection conn = new SqlConnection(Login.conString);

                conn.Open();
                string insert = "INSERT INTO Service ([Service_number], [Client_id], [Service_type], [Service_date], [Employee_name], [Total_cost]) VALUES('" + Service_num + "','" + Client_ID + "','" + service + "','" + date + "','" + employee + "','" + totalCost + "')";

                SqlDataAdapter adapter1 = new SqlDataAdapter();
                SqlCommand     command  = new SqlCommand(insert, conn);

                adapter1.InsertCommand = new SqlCommand(insert, conn);
                adapter1.InsertCommand.ExecuteNonQuery();
                command.Dispose();
                conn.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

            // displaying user message
            MessageBox.Show("Service appointment made successfully! \n Service number: " + Service_num.ToString() + " Service Date: " + date.ToString());
            Welcome w = new Welcome();

            w.ShowDialog();
            this.Hide();
        }