Пример #1
0
        void LoadMaSP()
        {
            var conn = Sqlconn.CreateConnection();

            conn.Open();
            var           cm = (SqlCommand)Sqlconn.CreateCommand("SELECT MaSP FROM SanPham ", conn);
            SqlDataReader dr = cm.ExecuteReader();

            while (dr.Read())

            {
                txtMaSP.Items.Add(dr[0]).ToString();
            }
            conn.Close();
        }
Пример #2
0
        public override void Login()
        {
            DBfactory Sqlconn = SQLdatabase.getInstanceSQL();  //Gọi SQL từ Factory Pattern

            var conn = Sqlconn.CreateConnection();

            conn.Open();
            string sqlSelect = "SELECT count(*)  FROM Users WHERE NameLogin = @NameLogin and PassW=@PassW";
            var    cmd       = (SqlCommand)Sqlconn.CreateCommand(sqlSelect, conn);

            cmd.Parameters.AddWithValue("NameLogin", account.getUserName());
            cmd.Parameters.AddWithValue("PassW", account.getPassword());
            var       dr = cmd.ExecuteReader();
            DataTable dt = new DataTable();

            dt.Load(dr);
            if (dt.Rows[0][0].ToString() == "1")
            {
                this.success = true;
                Home f = new Home();
                f.Show();
            }
            else
            {
                this.success = false;
                MessageBox.Show("Erorr: Username or Password incorect!");
            }
        }
Пример #3
0
        public string MaHD()
        {
            string MaHD;

            MaHD = "HD_" + RandomChar(5);
            string sqlSelect = "SELECT count(*) FROM HoaDon WHERE MaHD = @MaHD";
            var    conn      = Sqlconn.CreateConnection();

            conn.Open();
            var cmd = (SqlCommand)Sqlconn.CreateCommand(sqlSelect, conn);

            cmd.Parameters.AddWithValue("MaHD", MaHD);
            SqlDataReader dr = cmd.ExecuteReader();
            DataTable     dt = new DataTable();

            dt.Load(dr);
            if (dt.Rows[0][0].ToString() != "0")
            {
                MaHD = "HD_" + RandomChar(5);
            }
            return(MaHD);
        }
        public override void Add_Khach_hang()
        {
            String query = "INSERT INTO KhachHang VALUES(@MaKH, @TenKH, @SdtKH, @DiaChiKH)";
            var    conn  = Sqlconn.CreateConnection();

            conn.Open();
            var command = (SqlCommand)Sqlconn.CreateCommand(query, conn);

            command.Parameters.AddWithValue("MaKH", str[0]);
            command.Parameters.AddWithValue("TenKH", str[1]);
            command.Parameters.AddWithValue("SdtKH", str[2]);
            command.Parameters.AddWithValue("DiaChiKH", str[3]);
            command.ExecuteNonQuery();
            conn.Close();
        }