示例#1
0
        public void RetrieveUnitofMeasureofProduct(String ID)
        {
            SqlConnection RetrieveUnitofMeasureofProduct = new SqlConnection("Data Source=SELAKA\\SELA;Initial Catalog=SATHOSA;Integrated Security=True");
            SqlCommand    Select = new SqlCommand("Select Unit_Of_Measure FROM Product Where Product_ID=@ID;", RetrieveUnitofMeasureofProduct);

            //MessageBox.Show(""+ID);
            Select.Parameters.AddWithValue("@ID", ID);
            try
            {
                SqlDataReader DataReader1;
                RetrieveUnitofMeasureofProduct.Open();
                DataReader1 = Select.ExecuteReader();


                while (DataReader1.Read())
                {
                    metroTextBox6.Text = DataReader1["Unit_Of_Measure"].ToString();
                }

                DataReader1.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show("" + ex);
            }
            finally
            {
                RetrieveUnitofMeasureofProduct.Close();
            }
        }
示例#2
0
 public Main()
 {
     _dr = new DataReader1();
     _dh = new DataHandler();
     BeginProcess();
 }
示例#3
0
    public Main()
    {
        _dr = new DataReader1();

        BeginProcess();
    }
        protected void Page_Load(object sender, EventArgs e)
        {
            Label2.Visible = false;

            string ConnectionString = @"Data Source=LAPTOP-PO6LMSNT\SQLEXPRESS;Initial Catalog=TestDatabase;User Id=sa;Password=pass123";


            string Username = "";

            if (Session["user"] != null)
            {
                Username = Session["user"].ToString();
            }

            if (Username == null)
            {
                Response.Write("<script> alert('Not Logged in, redirecting to Login') </script>");
                Response.AddHeader("REFRESH", "1, URL = https://localhost:44372/Login.aspx");
            }
            else
            {
                SqlConnection conn;
                conn = new SqlConnection(ConnectionString);
                conn.Open();

                SqlConnection conn1;
                conn1 = new SqlConnection(ConnectionString);
                conn1.Open();
                int total = 0;

                string sql = "Select * from Cart where username = "******"'" + Username + "'";

                SqlCommand command;
                command = new SqlCommand(sql, conn);
                SqlDataReader DataReader;
                DataReader = command.ExecuteReader();

                if (DataReader.HasRows)
                {
                    DataReader.Read();
                    string quantity;

                    quantity = DataReader.GetValue(0).ToString();

                    string sql1 = "Select cost from Fcatalog where item = 'item1'";

                    SqlCommand command1;
                    command1 = new SqlCommand(sql1, conn1);
                    SqlDataReader DataReader1;
                    DataReader1 = command1.ExecuteReader();

                    if (DataReader1.HasRows)
                    {
                        DataReader1.Read();
                        string amount = DataReader1.GetValue(0).ToString();

                        total         += Int32.Parse(quantity) * Int32.Parse(amount);
                        Label1.Text    = total.ToString();
                        Label1.Visible = true;
                    }
                    command1.Dispose();
                    DataReader1.Close();

                    quantity = DataReader.GetValue(1).ToString();
                    sql1     = "Select cost from Fcatalog where item = 'item2'";

                    command1    = new SqlCommand(sql1, conn1);
                    DataReader1 = command1.ExecuteReader();

                    if (DataReader1.HasRows)
                    {
                        DataReader1.Read();
                        string amount = DataReader1.GetValue(0).ToString();

                        total         += Int32.Parse(quantity) * Int32.Parse(amount);
                        Label1.Text    = total.ToString();
                        Label1.Visible = true;
                    }
                    command1.Dispose();
                    DataReader1.Close();

                    quantity = DataReader.GetValue(2).ToString();
                    sql1     = "Select cost from Fcatalog where item = 'item3'";

                    command1    = new SqlCommand(sql1, conn1);
                    DataReader1 = command1.ExecuteReader();

                    if (DataReader1.HasRows)
                    {
                        DataReader1.Read();
                        string amount = DataReader1.GetValue(0).ToString();

                        total         += Int32.Parse(quantity) * Int32.Parse(amount);
                        Label1.Text    = total.ToString();
                        Label1.Visible = true;
                    }
                    command1.Dispose();
                    DataReader1.Close();

                    quantity = DataReader.GetValue(3).ToString();
                    sql1     = "Select cost from Fcatalog where item = 'item4'";

                    command1    = new SqlCommand(sql1, conn1);
                    DataReader1 = command1.ExecuteReader();

                    if (DataReader1.HasRows)
                    {
                        DataReader1.Read();
                        string amount = DataReader1.GetValue(0).ToString();

                        total         += Int32.Parse(quantity) * Int32.Parse(amount);
                        Label1.Text    = total.ToString();
                        Label1.Visible = true;
                    }
                    command1.Dispose();
                    DataReader1.Close();

                    quantity = DataReader.GetValue(4).ToString();
                    sql1     = "Select cost from Fcatalog where item = 'item5'";

                    command1    = new SqlCommand(sql1, conn1);
                    DataReader1 = command1.ExecuteReader();

                    if (DataReader1.HasRows)
                    {
                        DataReader1.Read();
                        string amount = DataReader1.GetValue(0).ToString();

                        total         += Int32.Parse(quantity) * Int32.Parse(amount);
                        Label1.Text    = total.ToString();
                        Label1.Visible = true;
                    }
                    command1.Dispose();
                    DataReader1.Close();

                    quantity = DataReader.GetValue(5).ToString();
                    sql1     = "Select cost from Fcatalog where item = 'item6'";

                    command1    = new SqlCommand(sql1, conn1);
                    DataReader1 = command1.ExecuteReader();


                    if (DataReader1.HasRows)
                    {
                        DataReader1.Read();
                        string amount = DataReader1.GetValue(0).ToString();

                        total         += Int32.Parse(quantity) * Int32.Parse(amount);
                        Label1.Text    = total.ToString();
                        Label1.Visible = true;
                    }
                    command1.Dispose();
                    DataReader1.Close();

                    quantity = DataReader.GetValue(6).ToString();
                    sql1     = "Select cost from Fcatalog where item = 'item7'";

                    command1    = new SqlCommand(sql1, conn1);
                    DataReader1 = command1.ExecuteReader();

                    if (DataReader1.HasRows)
                    {
                        DataReader1.Read();
                        string amount = DataReader1.GetValue(0).ToString();

                        total         += Int32.Parse(quantity) * Int32.Parse(amount);
                        Label1.Text    = total.ToString();
                        Label1.Visible = true;
                    }
                    command1.Dispose();
                    DataReader1.Close();
                    quantity = DataReader.GetValue(7).ToString();
                    sql1     = "Select cost from Fcatalog where item = 'item8'";

                    command1    = new SqlCommand(sql1, conn1);
                    DataReader1 = command1.ExecuteReader();

                    if (DataReader1.HasRows)
                    {
                        DataReader1.Read();
                        string amount = DataReader1.GetValue(0).ToString();

                        total         += Int32.Parse(quantity) * Int32.Parse(amount);
                        Label1.Text    = total.ToString();
                        Label1.Visible = true;
                    }
                    command1.Dispose();
                    DataReader1.Close();
                }

                command.Dispose();

                conn.Close();
                conn1.Close();

                if (total == 0)
                {
                    Response.Write("<script> alert('No items in cart, redirecting to Catalog') </script>");
                    Response.AddHeader("REFRESH", "1, URL = https://localhost:44372/Catalog.aspx");
                }
            }
        }