예제 #1
0
        private void buyPartslbl_Click(object sender, EventArgs e)
        {
            this.Hide();
            user userform = new user();

            userform.setUsername(username.Text);
            userform.goBacklbl_visible();
            userform.ShowDialog();
            this.Close();
        }
예제 #2
0
        private void goBack_Click(object sender, EventArgs e)
        {
            SqlConnection  sqlConn = new SqlConnection(@"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Users\Hashika\Desktop\Spark-master\Spark\spark_database.mdf;Integrated Security=True");
            string         query   = "SELECT * FROM tbluser where username='******'";
            SqlDataAdapter data    = new SqlDataAdapter(query, sqlConn);
            DataTable      dtbl    = new DataTable();

            data.Fill(dtbl);
            if (dtbl.Rows.Count != 0)
            {
                int type = 0;
                foreach (DataRow row in dtbl.Rows)
                {
                    type = Convert.ToInt16(row["type"].ToString());
                }
                if (type == 1 | type == 2)
                {
                    //if it is cashier
                    this.Hide();
                    user userform = new user();
                    userform.setUsername(username);
                    userform.setDataGrid(this.checkoutDataGrid);
                    userform.ShowDialog();
                    this.Close();
                }
                else if (type == 4)
                {
                    //if it is special customer
                    this.Hide();
                    specialCustomer specialcustomer = new specialCustomer();
                    specialcustomer.setUsername(username);
                    specialcustomer.setDataGrid(this.checkoutDataGrid);
                    specialcustomer.ShowDialog();
                    this.Close();
                }
            }
        }
예제 #3
0
        private void confirmPay_Click(object sender, EventArgs e)
        {
            try
            {
                SqlConnection sqlConn = new SqlConnection(@"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Users\Hashika\Desktop\Spark-master\Spark\spark_database.mdf;Integrated Security=True");
                sqlConn.Open();


                //starting transaction
                string     q    = "BEGIN TRANSACTION";
                SqlCommand cmd1 = new SqlCommand(q, sqlConn);
                cmd1.ExecuteNonQuery();

                for (int i = 0; i < checkoutDataGrid.Rows.Count - 1; i++)
                {
                    //insert into payments table
                    int        stock = 0;
                    string     query = "INSERT INTO payments(carBrand, carModel, partName, quantity, price) VALUES('" + checkoutDataGrid.Rows[i].Cells[0].Value.ToString() + "','" + checkoutDataGrid.Rows[i].Cells[1].Value.ToString() + "','" + checkoutDataGrid.Rows[i].Cells[2].Value.ToString() + "','" + checkoutDataGrid.Rows[i].Cells[3].Value.ToString() + "','" + checkoutDataGrid.Rows[i].Cells[4].Value.ToString() + "')";
                    SqlCommand data  = new SqlCommand(query, sqlConn);
                    data.ExecuteNonQuery();

                    //updating the stocks after the payments
                    string         query1 = "SELECT stock from carParts where carBrand='" + checkoutDataGrid.Rows[i].Cells[0].Value.ToString() + "'and carModel='" + checkoutDataGrid.Rows[i].Cells[1].Value.ToString() + "'and carPartName='" + checkoutDataGrid.Rows[i].Cells[2].Value.ToString() + "'";
                    SqlDataAdapter data1  = new SqlDataAdapter(query1, sqlConn);
                    DataTable      dtbl   = new DataTable();
                    data1.Fill(dtbl);
                    foreach (DataRow row in dtbl.Rows)
                    {
                        stock = Convert.ToInt16(row["stock"].ToString());
                    }
                    stock -= Convert.ToInt16(checkoutDataGrid.Rows[i].Cells[4].Value.ToString());

                    string     query2 = "UPDATE carParts set stock='" + stock + "'where carBrand='" + checkoutDataGrid.Rows[i].Cells[0].Value.ToString() + "'and carModel='" + checkoutDataGrid.Rows[i].Cells[1].Value.ToString() + "'and carPartName='" + checkoutDataGrid.Rows[i].Cells[2].Value.ToString() + "'";
                    SqlCommand data2  = new SqlCommand(query2, sqlConn);
                    data2.ExecuteNonQuery();
                }

                //end transationc
                string     q1   = "COMMIT";
                SqlCommand cmd2 = new SqlCommand(q1, sqlConn);
                cmd2.ExecuteNonQuery();

                //print the bill
                //Data grid view Size
                int height = checkoutDataGrid.Height;
                checkoutDataGrid.Height = (checkoutDataGrid.Rows.Count * checkoutDataGrid.RowTemplate.Height) + checkoutDataGrid.ColumnHeadersHeight;

                bitmap = new Bitmap(this.checkoutDataGrid.Width, this.checkoutDataGrid.Height);
                checkoutDataGrid.DrawToBitmap(bitmap, new Rectangle(0, 0, this.checkoutDataGrid.Width, this.checkoutDataGrid.Height));

                //setting height to the normal
                checkoutDataGrid.Height = height;

                //print preview
                checkoutPreviewDialog.Document = checkoutDocument;
                checkoutPreviewDialog.PrintPreviewControl.Zoom = 1;
                checkoutPreviewDialog.ShowDialog();


                this.Hide();
                user userform = new user();
                userform.setUsername(username);
                userform.ShowDialog();
                this.Close();
            }
            catch (SqlException error)
            {
                MessageBox.Show(error.Message);
            }
        }
예제 #4
0
        private void loginButton_Click(object sender, EventArgs e)
        {
            string username = txtUsername.Text.Trim();
            string password = txtPassword.Text.Trim();

            //setting ms sql connection
            SqlConnection  sqlConn = new SqlConnection(@"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Users\Maneesha\Desktop\Spark\Spark\spark_database.mdf;Integrated Security=True");
            string         query   = "SELECT * FROM tbluser where username='******'and password='******'";
            SqlDataAdapter data    = new SqlDataAdapter(query, sqlConn);
            DataTable      dtbl    = new DataTable();

            data.Fill(dtbl);
            if (dtbl.Rows.Count != 0)
            {
                int type = 0;
                foreach (DataRow row in dtbl.Rows)
                {
                    type = Convert.ToInt16(row["type"].ToString());
                }
                if (type == 1)
                {
                    this.Hide();
                    //go to the view userForm
                    user userForm = new user();
                    userForm.setUsername(username);
                    userForm.ShowDialog();
                    this.Close();
                }
                else if (type == 2)
                {
                    //go to supplier
                    this.Hide();
                    supplier supplierform = new supplier();
                    supplierform.setUsername(username);
                    supplierform.ShowDialog();
                    this.Close();
                }
                else if (type == 3)
                {
                    //go to admin
                    this.Hide();
                    admin admin = new admin();
                    admin.setUsername(username);
                    admin.ShowDialog();
                    this.Close();
                }
                else if (type == 4)
                {
                    //go to customer
                    this.Hide();
                    specialCustomer specialcustomer = new specialCustomer();
                    specialcustomer.setUsername(username);
                    specialcustomer.ShowDialog();
                    this.Close();
                }
            }
            else
            {
                this.checkCredentials.Visible = true;
            }
        }