public bool Xoa(KhuyenMaiDTO kmDTO)
        {
            string query = "  delete from KHUYENMAI where MAKM='" + kmDTO.Makm + "'";
            bool   kq    = xl.Command(query);

            return(kq);
        }
Beispiel #2
0
        public IHttpActionResult Put([FromBody] KhuyenMaiDTO x)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest("Not a valid data"));
            }

            KhuyenMaiDAO.Instance.UpdateKM(x.TenCT, x.MoTa, x.NgayBD, x.NgayKT, x.ChietKhau);
            return(Ok());
        }
        public bool Them(KhuyenMaiDTO kmDTO)
        {
            String query = String.Empty;

            query += "insert into KHUYENMAI(TENKM, TGBD, TGKT, MUCGIAMGIA)";
            query += "values('" + kmDTO.Tenkm + "', '" + kmDTO.TgBD + "', '" + kmDTO.TgKT + "', '" + kmDTO.Mucgiamgia + "')";
            bool kq = xl.Command(query);

            return(kq);
        }
Beispiel #4
0
        public KhuyenMaiDTO GetDTOKM(string tenKM)
        {
            DataTable data = DataProvider.Instance.ExecuteQuery("Select * From KhuyenMai WHERE TenKM = N'" + tenKM + "'");

            if (data.Rows.Count > 0)
            {
                KhuyenMaiDTO km = new KhuyenMaiDTO(data.Rows[0]);
                return(km);
            }
            return(null);
        }
Beispiel #5
0
        public List <KhuyenMaiDTO> TimKiemKMChuaHetHan()
        {
            List <KhuyenMaiDTO> list  = new List <KhuyenMaiDTO>();
            DataTable           table = DataProvider.Instance.executeQuery("select * from KHUYENMAI where NGAYKETTHUC >= GETDATE()");

            foreach (DataRow row in table.Rows)
            {
                KhuyenMaiDTO km = new KhuyenMaiDTO(row);
                list.Add(km);
            }
            return(list);
        }
Beispiel #6
0
        public int GetIDByTenKM(string tenKM)
        {
            string    query = "SELECT * FROM KhuyenMai WHERE TenKM = N'" + tenKM + "'";
            DataTable table = DataProvider.Instance.ExecuteQuery(query);

            foreach (DataRow item in table.Rows)
            {
                KhuyenMaiDTO lkm = new KhuyenMaiDTO(item);
                return(lkm.Id);
            }
            return(-1);
        }
Beispiel #7
0
        public List <KhuyenMaiDTO> LoadDsKMAll()
        {
            List <KhuyenMaiDTO> dsKM = new List <KhuyenMaiDTO>();
            DataTable           data = DataProvider.Instance.ExecuteQuery("SELECT * FROM KhuyenMai Where idLoaiKm = 1");

            foreach (DataRow item in data.Rows)
            {
                KhuyenMaiDTO km = new KhuyenMaiDTO(item);
                dsKM.Add(km);
            }
            return(dsKM);
        }
        public List <KhuyenMaiDTO> GetKhuyenMai()
        {
            List <KhuyenMaiDTO> list = new List <KhuyenMaiDTO>();
            DataTable           data = DataProvider.Instance.ExecuteQuery("select * from KhuyenMai ");

            foreach (DataRow item in data.Rows)
            {
                KhuyenMaiDTO KM = new KhuyenMaiDTO(item);
                list.Add(KM);
            }
            return(list);
        }
        public List <KhuyenMaiDTO> SearchKM(string str)
        {
            List <KhuyenMaiDTO> KMList = new List <KhuyenMaiDTO>();
            DataTable           data   = DataProvider.Instance.ExecuteQuery("EXEC USP_SearchKM @str ", new object[] { str });

            foreach (DataRow item in data.Rows)
            {
                KhuyenMaiDTO tenKM = new KhuyenMaiDTO(item);
                KMList.Add(tenKM);
            }
            return(KMList);
        }
Beispiel #10
0
        public List <KhuyenMaiDTO> GetKhuyenMai()
        {
            List <KhuyenMaiDTO> ListKhuyenMai = new List <KhuyenMaiDTO>();
            DataTable           data          = DataProvider.Instance.ExecuteQuery("select * from KhuyenMai");

            foreach (DataRow item in data.Rows)
            {
                KhuyenMaiDTO khuyenMai = new KhuyenMaiDTO(item);
                ListKhuyenMai.Add(khuyenMai);
            }
            return(ListKhuyenMai);
        }
Beispiel #11
0
        public List <KhuyenMaiDTO> LoadDsKM()
        {
            List <KhuyenMaiDTO> dsKM = new List <KhuyenMaiDTO>();
            DataTable           data = DataProvider.Instance.ExecuteQuery("USP_GetDSKM");

            foreach (DataRow item in data.Rows)
            {
                KhuyenMaiDTO km = new KhuyenMaiDTO(item);
                dsKM.Add(km);
            }
            return(dsKM);
        }
Beispiel #12
0
        private void cbxTenKM_SelectedIndexChanged(object sender, EventArgs e)
        {
            string       tenKM  = cbxTenKM.Text;
            string       tenLKM = cbxLoaiKM.Text;
            KhuyenMaiDTO km     = KhuyenMaiDAO.Instance.GetDTOKM(tenKM);

            txbDieuKien.Text  = km.DieuKien.ToString();
            txbGiamGiaPT.Text = km.GiamGia.ToString();
            txbGiamGiaTM.Text = km.GiamTien.ToString();
            txbToiDa.Text     = km.ToiDa.ToString();
            txbNDKM.Text      = km.TenKM;
            cbxLoaiKM.Text    = LoaiKhuyenMaiDAO.Instance.GetTenLoaiKMByID(km.IdLoaiKM);
        }
Beispiel #13
0
        private void fillList()
        {
            DataTable table = new DataTable();


            table.Columns.Add("Stt", typeof(int));
            table.Columns.Add("MaKM", typeof(string));
            table.Columns.Add("TenKM", typeof(string));
            table.Columns.Add("MaApDung", typeof(string));
            table.Columns.Add("GiaTri", typeof(string));

            BangVocher.DataSource = table;

            int soluong;

            try
            {
                soluong = Int32.Parse(TxtSoLuong.Text);
            }
            catch
            {
                soluong = 0;
            }
            list = new List <KhuyenMaiDTO>();
            for (int i = 0; i < soluong; i++)
            {
                KhuyenMaiDTO km = new KhuyenMaiDTO();
                km.MaKM  = getnewcodeKM(i);
                km.TenKM = txtTenVocher.Text;
                try
                {
                    km.GiaTri = Decimal.Parse(TxtGiaTri.Text);
                }
                catch
                {
                    km.GiaTri = 0;
                }

                km.MaApDung  = "VOCHER-" + km.MaKM;
                km.LoaiKM    = "Vocher";
                km.BatDau    = DateTime.Today;
                km.KetThuc   = DateTime.Today;
                km.TuXoa     = false;
                km.TrangThai = true;
                list.Add(km);
                table.Rows.Add(i + 1, km.MaKM, km.TenKM, km.MaApDung, ConvertDTO.Instance.CurrencyFromDecimal(km.GiaTri));
            }

            BangVocher.DataSource = table;
        }
        public IHttpActionResult HoanThanh(KhuyenMaiDTO x)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest("Not a valid model"));
                }

                KhuyenMaiDAO.Instance.HoanThanh(x.List, x.TenCT, x.MoTa, x.NgayBD, x.NgayKT);
            }
            catch (Exception)
            {
            }
            return(Ok());
        }
Beispiel #15
0
 public IHttpActionResult Put(KhuyenMaiDTO x)
 {
     try
     {
         if (!ModelState.IsValid)
         {
             return(BadRequest("Not a valid model"));
         }
         //int idkm, string tenct, string mota, DateTime ngaybd, DateTime ngaykt, float chietkhau
         KhuyenMaiDAO.Instance.UpdateKM(x.MaKM, x.TenCT, x.MoTa, x.NgayBD, x.NgayKT, x.ChietKhau);
     }
     catch (Exception)
     {
     }
     return(Ok());
 }
Beispiel #16
0
        public IHttpActionResult Post(KhuyenMaiDTO x)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest("Not a valid model"));
                }

                KhuyenMaiDAO.Instance.InsertKM(x.TenCT, x.MoTa, x.NgayBD, x.NgayKT, x.ChietKhau);
            }
            catch (Exception)
            {
            }
            return(Ok());
        }
        public List <KhuyenMaiDTO> select()
        {
            Fxuly xuLy = new Fxuly();
            List <KhuyenMaiDTO> listKM = new List <KhuyenMaiDTO>();
            string query = String.Empty;

            query += "select [MAKM], [TENKM], [TGBD], [TGKT], [MUCGIAMGIA] from [KHUYENMAI]";
            using (SqlConnection con = new SqlConnection(xuLy.ConnectionString))
            {
                using (SqlCommand cmd = new SqlCommand())
                {
                    cmd.Connection  = con;
                    cmd.CommandType = CommandType.Text;
                    cmd.CommandText = query;
                    try
                    {
                        con.Open();
                        SqlDataReader reader = null;
                        reader = cmd.ExecuteReader();
                        if (reader.HasRows == true)
                        {
                            while (reader.Read())
                            {
                                KhuyenMaiDTO db = new KhuyenMaiDTO();
                                db.Makm       = int.Parse(reader["MAKM"].ToString());
                                db.Tenkm      = reader["TENKM"].ToString();
                                db.TgBD       = DateTime.Parse(reader["TGBD"].ToString());
                                db.TgKT       = DateTime.Parse(reader["TGKT"].ToString());
                                db.Mucgiamgia = int.Parse(reader["MUCGIAMGIA"].ToString());
                                listKM.Add(db);
                            }
                        }
                        con.Close();
                        con.Dispose();
                    }
                    catch (Exception ex)
                    {
                        con.Close();
                        con.Dispose();
                    }
                }
                return(listKM);
            }
        }
        public List <KhuyenMaiDTO> selectLoadCB()
        {
            string query = String.Empty;
            Fxuly  xuLy  = new Fxuly();

            query += "select [MAKM], [TENKM], [MUCGIAMGIA] FROM [KHUYENMAI] ";
            List <KhuyenMaiDTO> list = new List <KhuyenMaiDTO>();

            using (SqlConnection con = new SqlConnection(xuLy.ConnectionString))
            {
                using (SqlCommand cmd = new SqlCommand())
                {
                    cmd.Connection  = con;
                    cmd.CommandType = System.Data.CommandType.Text;
                    cmd.CommandText = query;
                    try
                    {
                        con.Open();
                        SqlDataReader reader = null;
                        reader = cmd.ExecuteReader();
                        if (reader.HasRows == true)
                        {
                            while (reader.Read())
                            {
                                KhuyenMaiDTO kn = new KhuyenMaiDTO();
                                kn.maKhuyenMai  = int.Parse(reader["MAKM"].ToString());
                                kn.tenKhuyenMai = reader["TENKM"].ToString();
                                kn.mucKhuyenMai = int.Parse(reader["MUCGIAMGIA"].ToString());
                                list.Add(kn);
                            }
                        }
                        con.Close();
                        con.Dispose();
                    }
                    catch (Exception ex)
                    {
                        con.Close();
                        return(null);
                    }
                }
                return(list);
            }
        }
Beispiel #19
0
        private void btn_Xoa_Click(object sender, EventArgs e)
        {
            int currentRowIndex = dgv_KM.CurrentCellAddress.Y;

            if (-1 < currentRowIndex && currentRowIndex < dgv_KM.RowCount)
            {
                kmDTO = (KhuyenMaiDTO)dgv_KM.Rows[currentRowIndex].DataBoundItem;
                if (kmDTO != null)
                {
                    bool kq = kmBUS.Xoa(kmDTO);
                    if (kq == true)
                    {
                        loadKM();
                        MessageBox.Show("Xóa khuyến mãi thành công");
                    }
                    else
                    {
                        MessageBox.Show("Xóa khuyến mãi thất bại");
                    }
                }
            }
        }
Beispiel #20
0
        private void btnCapNhat_Click(object sender, EventArgs e)
        {
            if (txtTenCT.Text == null || dtpTuNgay.Text == null || dtpDenNgay == null || txtChietKhau.Text == null)
            {
                MessageBox.Show("Thêm đầy đủ thông tin khuyến mại.", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            int      id        = Convert.ToInt32(txtIDKM.Text);
            string   tenct     = txtTenCT.Text;
            string   mota      = txtMoTa.Text;
            float    chietkhau = float.Parse(txtChietKhau.Text);
            DateTime ngaybd    = Convert.ToDateTime(dtpTuNgay.Text);
            DateTime ngaykt    = Convert.ToDateTime(dtpDenNgay.Text);

            KhuyenMaiDTO KM = new KhuyenMaiDTO(id, tenct, mota, ngaybd, ngaykt, chietkhau);

            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri(baseAddress);

                //HTTP PUT
                var postTask = client.PutAsJsonAsync <KhuyenMaiDTO>("KhuyenMai", KM);

                postTask.Wait();

                var result = postTask.Result;
                if (result.IsSuccessStatusCode)
                {
                    MessageBox.Show("Sửa thành công!", "Thông báo", MessageBoxButtons.OK);
                }
                else
                {
                    MessageBox.Show("Sửa không thành công!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                Load();
            }
        }
Beispiel #21
0
        private void btnHoanThanh_Click(object sender, EventArgs e)
        {
            if (txtTenCT.Text == "" || dtpTuNgay == null || dtpDenNgay == null)
            {
                MessageBox.Show("Nhập đầy đủ thông tin chương trình khuyến mãi!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            if (radKMDH.Checked == true)
            {
                string   tenct     = txtTenCT.Text;
                string   mota      = txtMoTa.Text;
                DateTime ngaybd    = Convert.ToDateTime(dtpTuNgay.Text);
                DateTime ngaykt    = Convert.ToDateTime(dtpDenNgay.Text);
                float    chietkhau = float.Parse(txtCK.Text);

                KhuyenMaiDTO CTKM = new KhuyenMaiDTO(tenct, mota, ngaybd, ngaykt, chietkhau);
                using (var client = new HttpClient())
                {
                    client.BaseAddress = new Uri(baseAddress);

                    //HTTP POST
                    var postTask = client.PostAsJsonAsync <KhuyenMaiDTO>("KhuyenMai", CTKM);
                    postTask.Wait();

                    var result = postTask.Result;
                    if (result.IsSuccessStatusCode)
                    {
                        MessageBox.Show("thêm thành công 1 phiếu đổi!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                    }
                }
            }
            else
            {
                //KhuyenMaiDAO.Instance.HoanThanh(listCTKM, txtTenCT.Text, txtMoTa.Text, Convert.ToDateTime(dtpTuNgay.Text), Convert.ToDateTime(dtpDenNgay.Text));
                string   tenct  = txtTenCT.Text;
                string   mota   = txtMoTa.Text;
                DateTime ngaybd = Convert.ToDateTime(dtpTuNgay.Text);
                DateTime ngaykt = Convert.ToDateTime(dtpDenNgay.Text);

                KhuyenMaiDTO CTKM = new KhuyenMaiDTO(listCT, tenct, mota, ngaybd, ngaykt);
                using (var client = new HttpClient())
                {
                    client.BaseAddress = new Uri(baseAddress);

                    //HTTP POST
                    var postTask = client.PostAsJsonAsync <KhuyenMaiDTO>("HoanThanh", CTKM);
                    postTask.Wait();

                    var result = postTask.Result;
                    if (result.IsSuccessStatusCode)
                    {
                        MessageBox.Show("thêm thành công 1 phiếu đổi!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                    }
                }
            }

            fKhuyenMai KM = new fKhuyenMai();

            this.Hide();
            KM.ShowDialog();
            this.Show();
        }
Beispiel #22
0
        private void BtnThemKM_Click(object sender, EventArgs e)
        {
            if (TimeNgayKetThuc.Value >= TimeNgayBatDau.Value && TimeNgayKetThuc.Value >= DateTime.Today && TimeNgayBatDau.Value >= DateTime.Today)
            {
                if (SelectLoaiKM.selectedIndex == 1)
                {
                    KhuyenMaiDTO km = new KhuyenMaiDTO();

                    km.MaKM      = getnewcodeKM(0);
                    km.TenKM     = fmCT.GetTenCT();
                    km.GiaTri    = fmCT.getGiaTri();
                    km.LoaiKM    = "Chương Trình";
                    km.MaApDung  = getnewcodeKM(0);
                    km.BatDau    = TimeNgayBatDau.Value;
                    km.KetThuc   = TimeNgayKetThuc.Value;
                    km.TuXoa     = SwitchTuXoa.Value;
                    km.TrangThai = (km.BatDau <= DateTime.Today && km.KetThuc >= DateTime.Today)?true:false;
                    if (KhuyenMaiDAO.Instance.Insert(km))
                    {
                        this.Close();
                    }
                    else
                    {
                        MessageBox.Show("Không thể thêm Chương Trình Khuyến Mãi");
                    }
                }

                if (SelectLoaiKM.selectedIndex == 0)
                {
                    int soluong;
                    try
                    {
                        soluong = Int32.Parse(fmVC.getSoLuong());
                    }
                    catch
                    {
                        soluong = 0;
                    }
                    try
                    {
                        for (int i = 0; i < soluong; i++)
                        {
                            KhuyenMaiDTO km = new KhuyenMaiDTO();
                            km.MaKM  = getnewcodeKM(i);
                            km.TenKM = fmVC.getTenVoCher();
                            try
                            {
                                km.GiaTri = Decimal.Parse(fmVC.getGiaTri());
                            }
                            catch
                            {
                                km.GiaTri = 0;
                            }

                            km.MaApDung  = "VOCHER-" + km.MaKM;
                            km.LoaiKM    = "Vocher";
                            km.BatDau    = TimeNgayBatDau.Value;
                            km.KetThuc   = TimeNgayKetThuc.Value;
                            km.TuXoa     = SwitchTuXoa.Value;
                            km.TrangThai = (km.BatDau <= DateTime.Today && km.KetThuc >= DateTime.Today) ? true : false;
                            KhuyenMaiDAO.Instance.Insert(km);
                        }
                        this.Close();
                    }
                    catch
                    {
                        MessageBox.Show("Không thể thêm Vocher");
                    }
                }
            }
            else
            {
                MessageBox.Show("Khuyến Mãi Không Hợp lệ");
            }
        }