コード例 #1
0
        private void button1_Click_1(object sender, EventArgs e)
        {
            String logname = textBox1.Text;
            String logPass = textBox2.Text;

            if (logname == string.Empty)
            {
                MessageBox.Show("Insert Username");
            }
            else if (logPass == string.Empty)
            {
                MessageBox.Show("Insert Password");
            }
            else
            {
                SqlCommand cmd = new SqlCommand("FoodDelivery_FinalProject.uspLogin", cn);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.Add("@pLoginName", SqlDbType.NVarChar, 50).Value           = logname;
                cmd.Parameters.Add("@pPassword", SqlDbType.NVarChar).Value                = logPass;
                cmd.Parameters.Add("@responseMessage", SqlDbType.NVarChar, 250).Direction = ParameterDirection.Output;

                if (!verifySGBDConnection())
                {
                    return;
                }
                cmd.Connection = cn;
                cmd.ExecuteNonQuery();

                String type = (String)cmd.Parameters["@responseMessage"].Value;

                if (type == "Client Login")
                {
                    Form client = new Client(logname);
                    client.Show();
                    this.Hide();
                }
                else if (type == "Driver Login")
                {
                    Form driver = new DriverPage(logname);
                    driver.Show();
                    this.Hide();
                }
                else
                {
                    MessageBox.Show(type);
                }
            }
        }
コード例 #2
0
        private void button9_Click(object sender, EventArgs e)
        {
            string LicensePlate = textBox24.Text;
            string Model        = textBox15.Text;


            string picturePath = textBox19.Text;
            string LoginName   = textBox23.Text;
            string Password    = textBox22.Text;
            string Name        = textBox21.Text;
            string contact     = textBox20.Text;
            string street      = textBox18.Text;
            string city        = comboBox1.Text;
            string postalCode  = textBox16.Text;



            string picture = null;

            //Sign up
            if (!(string.IsNullOrEmpty(picturePath)))
            {
                using (Image image = Image.FromFile(picturePath))
                {
                    using (MemoryStream m = new MemoryStream())
                    {
                        image.Save(m, image.RawFormat);
                        byte[] imageBytes = m.ToArray();

                        picture = Convert.ToBase64String(imageBytes);
                    }
                }
            }
            SqlCommand cmd = null;

            cmd             = new SqlCommand("FoodDelivery_FinalProject.AddDriver", cn);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add("@LicensePlate", SqlDbType.NChar, 8).Value = LicensePlate;
            cmd.Parameters.Add("@Model", SqlDbType.NVarChar, 20).Value    = Model;
            cmd.Parameters.Add("@pLogin", SqlDbType.NVarChar, 50).Value   = LoginName;
            cmd.Parameters.Add("@pPassword", SqlDbType.NVarChar).Value    = Password;
            cmd.Parameters.Add("@pName", SqlDbType.NVarChar).Value        = Name;
            cmd.Parameters.Add("@Contact", SqlDbType.NChar, 9).Value      = contact;
            cmd.Parameters.Add("@Image", SqlDbType.NVarChar).Value        = picture;
            cmd.Parameters.Add("@Street", SqlDbType.NVarChar).Value       = street;
            cmd.Parameters.Add("@City", SqlDbType.NVarChar).Value         = city;
            cmd.Parameters.Add("@PostalCode ", SqlDbType.NVarChar).Value  = postalCode;


            cmd.Parameters.Add("@responseMessage", SqlDbType.NVarChar, 250).Direction = ParameterDirection.Output;



            if (!verifySGBDConnection())
            {
                return;
            }
            cmd.Connection = cn;
            cmd.ExecuteNonQuery();

            MessageBox.Show(cmd.Parameters["@responseMessage"].Value.ToString());

            Form v1 = new DriverPage(LoginName);

            v1.Show();
            this.Close();
        }