Ejemplo n.º 1
0
        private void btLuu_Click(object sender, EventArgs e)
        {
            float chietkhau;
            bool  isInt = float.TryParse(txtChietKhau.Text.Trim().ToString(), out chietkhau);

            if (txtMaKM.Text.Trim().Length == 0)
            {
                MessageBox.Show("Bạn phải nhập mã khuyến mãi", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                txtMaKM.Focus();
                return;
            }
            else if (checkmkm(txtMaKM.Text, busKM))
            {
                MessageBox.Show("Mã khuyến mãi đã tồn tại, vui lòng nhập lại", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                txtMaKM.Focus();
                return;
            }

            if (txtTenKM.Text.Trim().Length == 0)
            {
                MessageBox.Show("Bạn phải nhập tên khuyến mãi", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                txtTenKM.Focus();
                return;
            }
            else if (checktkm(txtTenKM.Text, busKM))
            {
                MessageBox.Show("Tên khuyến mãi đã tồn tại, vui lòng nhập lại", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                txtTenKM.Focus();
                return;
            }

            if (!isInt || float.Parse(txtChietKhau.Text) < 0)
            {
                MessageBox.Show("Bạn phải nhập chiết khấu > 0", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                txtChietKhau.Focus();
                return;
            }
            if (dtpNgBD.Value > dtpNgKT.Value)
            {
                MessageBox.Show("Ngày bắt đầu phải nhỏ hơn ngày kết thúc", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                dtpNgBD.Focus();
                return;
            }


            DTO_KhuyenMai km = new DTO_KhuyenMai(txtMaKM.Text, txtTenKM.Text, float.Parse(txtChietKhau.Text), dtpNgBD.Value, dtpNgKT.Value);

            if (busKM.insertKM(km))
            {
                MessageBox.Show("Thêm thành công");
                LoadGridview_KM();
                btLuu.Enabled     = false;
                btXoa.Enabled     = false;
                btCapNhat.Enabled = false;
            }
            else
            {
                MessageBox.Show("Thêm không thành công");
            }
        }
Ejemplo n.º 2
0
        private void btnSua_Click(object sender, EventArgs e)
        {
            if (lvwGiay.SelectedItems.Count > 0)
            {
                ListViewItem item    = lvwGiay.SelectedItems[0];
                DTO_Giay     dtoGiay = new DTO_Giay();
                dtoGiay.maGiay  = item.SubItems[2].Text;
                dtoGiay.TenGiay = item.SubItems[3].Text;
                dtoGiay.moTa    = item.SubItems[6].Text;
                dtoGiay.soLuong = int.Parse(item.SubItems[8].Text);
                dtoGiay.gia     = float.Parse(item.SubItems[9].Text);

                DTO_GioiTinh   dtoGioiTinh   = new DTO_GioiTinh();
                DTO_ThuongHieu dtoThuongHieu = new DTO_ThuongHieu();
                DTO_KhuyenMai  dtoKhuyenMai  = new DTO_KhuyenMai();
                dtoGioiTinh.tenGioiTinh      = item.SubItems[4].Text;
                dtoThuongHieu.tenThuongHieu  = item.SubItems[5].Text;
                dtoKhuyenMai.phanTramGiamGia = float.Parse(item.SubItems[7].Text);

                Tool_SuaGiay toolSuaGiayy = new Tool_SuaGiay(dtoGiay, dtoGioiTinh, dtoThuongHieu, dtoKhuyenMai);
                toolSuaGiayy.ShowDialog();
                if (toolSuaGiayy.isClickSua)
                {
                    loadDataGiay();
                }
            }
        }
Ejemplo n.º 3
0
        public bool insertKM(DTO_KhuyenMai km)
        {
            try
            {
                _conn.Open();
                SqlCommand cmd = new SqlCommand();
                cmd.Connection  = _conn;
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.CommandText = "Sp_InsertKM";
                cmd.Parameters.AddWithValue("@MaKM", km.MaKM);
                cmd.Parameters.AddWithValue("@tenKM", km.TenKM);
                cmd.Parameters.AddWithValue("@chietkhau", km.ChietKhau);
                cmd.Parameters.AddWithValue("@startDate", km.NgayBD);
                cmd.Parameters.AddWithValue("@endDate", km.NgayKT);

                if (cmd.ExecuteNonQuery() > 0)
                {
                    return(true);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
            finally
            {
                _conn.Close();
            }
            return(false);
        }
Ejemplo n.º 4
0
        public void loadKhuyenMai()
        {
            List <DTO_KhuyenMai> khuyenMais = new List <DTO_KhuyenMai>();

            foreach (DataRow row in busKhuyenMai.getAllKhuyenMai().Rows)
            {
                DTO_KhuyenMai km = new DTO_KhuyenMai();
                km.maKhuyenMai = row["MAKHUYENMAI"].ToString();
                km.tenSuKien   = row["TENSUKIEN"].ToString() + "  -" + row["PHANTRAMGIAMGIA"].ToString() + "%";
                khuyenMais.Add(km);
            }
            cbbKhuyenMai.DataSource    = khuyenMais;
            cbbKhuyenMai.DisplayMember = "tenSuKien";
        }
Ejemplo n.º 5
0
        public DTO_KhuyenMai curKM(string TenKM)
        {
            DTO_KhuyenMai km = (from DataRow dr in dalKM.GetDanhSachKM().Rows
                                where string.Compare(dr[1].ToString(), TenKM, true) == 0
                                select new DTO_KhuyenMai
            {
                MaKM = dr[0].ToString(),
                TenKM = dr[1].ToString(),
                NgayBD = (DateTime)dr[2],
                NgayKT = (DateTime)dr[3],
                ChietKhau = float.Parse(dr[4].ToString())
            }).FirstOrDefault();

            return(km);
        }
Ejemplo n.º 6
0
        private void btnSua_Click(object sender, EventArgs e)
        {
            if (lvwKhuyenMai.SelectedItems.Count > 0)
            {
                ListViewItem  item         = lvwKhuyenMai.SelectedItems[0];
                DTO_KhuyenMai dtoKhuyenMai = new DTO_KhuyenMai();
                dtoKhuyenMai.maKhuyenMai     = item.SubItems[1].Text;
                dtoKhuyenMai.tenSuKien       = item.SubItems[2].Text;
                dtoKhuyenMai.phanTramGiamGia = float.Parse(item.SubItems[3].Text);

                Tool_SuaKhuyenMai toolSuaKhuyenMai = new Tool_SuaKhuyenMai(dtoKhuyenMai);
                toolSuaKhuyenMai.ShowDialog();
                if (toolSuaKhuyenMai.isClickSua)
                {
                    loadDataKhuyenMai();
                }
            }
        }
Ejemplo n.º 7
0
        private void btCapNhat_Click(object sender, EventArgs e)
        {
            float chietkhau;
            bool  isInt = float.TryParse(txtChietKhau.Text.Trim().ToString(), out chietkhau);

            if (txtMaKM.Text.Trim().Length == 0)
            {
                MessageBox.Show("Bạn phải nhập mã khuyến mãi", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                txtMaKM.Focus();
                return;
            }
            else if (txtTenKM.Text.Trim().Length == 0)
            {
                MessageBox.Show("Bạn phải nhập tên khuyến mãi", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                txtTenKM.Focus();
                return;
            }
            if (!isInt || float.Parse(txtChietKhau.Text) < 0)
            {
                MessageBox.Show("Bạn phải nhập chiết khấu > 0", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                txtChietKhau.Focus();
                return;
            }

            if (dtpNgBD.Value > dtpNgKT.Value)
            {
                MessageBox.Show("Ngày bắt đầu phải nhỏ hơn ngày kết thúc", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                dtpNgBD.Focus();
                return;
            }

            DTO_KhuyenMai km = new DTO_KhuyenMai(txtMaKM.Text, txtTenKM.Text, float.Parse(txtChietKhau.Text), dtpNgBD.Value, dtpNgKT.Value);

            if (busKM.UpdateKM(km))
            {
                MessageBox.Show("Cập nhật thành công");
                LoadGridview_KM();
            }
            else
            {
                MessageBox.Show("Cập nhật không thành công");
            }
        }
Ejemplo n.º 8
0
        private void dgvkm_Click(object sender, EventArgs e)
        {
            DTO_KhuyenMai km = busKM.curKM(dataGridView1.CurrentRow.Cells["TenKM"].Value.ToString());

            txtMaKM.Text      = km.MaKM;
            txtTenKM.Text     = km.TenKM;
            txtChietKhau.Text = km.ChietKhau.ToString();

            dtpNgBD.Text = km.NgayBD.ToString();
            dtpNgKT.Text = km.NgayKT.ToString();

            txtMaKM.Enabled      = true;
            txtTenKM.Enabled     = true;
            txtChietKhau.Enabled = true;
            dtpNgBD.Enabled      = true;
            dtpNgKT.Enabled      = true;
            btCapNhat.Enabled    = true;
            btXoa.Enabled        = true;
            btLuu.Enabled        = false;
        }
Ejemplo n.º 9
0
        public bool addKhuyenMai(DTO_KhuyenMai dtoKhuyenMai)
        {
            String SQLInsert = "INSERT INTO KHUYENMAI (MAKHUYENMAI, TENSUKIEN, PHANTRAMGIAMGIA) " +
                               "VALUES(@MAKHUYENMAI, @TENSUKIEN, @PHANTRAMGIAMGIA)";

            try
            {
                conn = new DBConnection().getConnection();
                conn.Open();
                SqlCommand sqlCommand = new SqlCommand(SQLInsert, conn);
                sqlCommand.Parameters.AddWithValue("MAKHUYENMAI", dtoKhuyenMai.maKhuyenMai);
                sqlCommand.Parameters.AddWithValue("TENSUKIEN", dtoKhuyenMai.tenSuKien);
                sqlCommand.Parameters.AddWithValue("PHANTRAMGIAMGIA", dtoKhuyenMai.phanTramGiamGia);
                sqlCommand.ExecuteNonQuery();
                conn.Close();
                return(true);
            }
            catch (Exception e)
            {
                e.ToString();
                return(false);
            }
        }
Ejemplo n.º 10
0
        public bool editKhuyenMai(DTO_KhuyenMai dtoKhuyenMai)
        {
            String SQLUpdate = "UPDATE KHUYENMAI " +
                               "SET TENSUKIEN = @TENSUKIEN, PHANTRAMGIAMGIA = @PHANTRAMGIAMGIA " +
                               "WHERE MAKHUYENMAI = @MAKHUYENMAI";

            try
            {
                conn = new DBConnection().getConnection();
                conn.Open();
                SqlCommand sqlCommand = new SqlCommand(SQLUpdate, conn);
                sqlCommand.Parameters.AddWithValue("MAKHUYENMAI", dtoKhuyenMai.maKhuyenMai);
                sqlCommand.Parameters.AddWithValue("TENSUKIEN", dtoKhuyenMai.tenSuKien);
                sqlCommand.Parameters.AddWithValue("PHANTRAMGIAMGIA", dtoKhuyenMai.phanTramGiamGia);
                sqlCommand.ExecuteNonQuery();
                conn.Close();
                return(true);
            }
            catch (Exception e)
            {
                e.ToString();
                return(false);
            }
        }
Ejemplo n.º 11
0
 public bool addKhuyenMai(DTO_KhuyenMai dtoKhuyenMai)
 {
     return(dalKhuyenMai.addKhuyenMai(dtoKhuyenMai));
 }
Ejemplo n.º 12
0
 public Tool_SuaGiay(DTO_Giay dtoGiay, DTO_GioiTinh dtoGioiTinh, DTO_ThuongHieu dtoThuongHieu, DTO_KhuyenMai dtoKhuyenMai)
 {
     InitializeComponent();
     this.dtoGiay       = dtoGiay;
     this.dtoGioiTinh   = dtoGioiTinh;
     this.dtoThuongHieu = dtoThuongHieu;
     this.dtoKhuyenMai  = dtoKhuyenMai;
     isClickSua         = false;
 }
Ejemplo n.º 13
0
 public bool UpdateKM(DTO_KhuyenMai km)
 {
     return(dalKM.UpdateKM(km));
 }
Ejemplo n.º 14
0
 public bool insertKM(DTO_KhuyenMai km)
 {
     return(dalKM.insertKM(km));
 }
Ejemplo n.º 15
0
 public Tool_SuaKhuyenMai(DTO_KhuyenMai dtoKhuyenMai)
 {
     InitializeComponent();
     this.dtoKhuyenMai = dtoKhuyenMai;
     this.isClickSua   = false;
 }
Ejemplo n.º 16
0
 public bool editKhuyenMai(DTO_KhuyenMai dtoKhuyenMai)
 {
     return(dalKhuyenMai.editKhuyenMai(dtoKhuyenMai));
 }
Ejemplo n.º 17
0
        private void cbKhuyenMai_SelectedIndexChanged(object sender, EventArgs e)
        {
            km = busKM.curKM(cbTenKM.SelectedItem.ToString());

            lbChietKhau.Text = km.ChietKhau.ToString() + "%";
        }