Esempio n. 1
0
        public static bool Delete(SanPham data)
        {
            try
            {
                if (data != null)
                {
                    SanPham objDb = GetById(data.Id);

                    if (objDb != null)
                    {
                        objDb.DeleteFlag = true;
                        dbContext.SubmitChanges();

                        return true;
                    }
                }
            }
            catch
            {

            }

            CreateSQlConnection();

            return false;
        }
Esempio n. 2
0
        public UcInfo(DTO.SanPham data)
        {
            InitializeComponent();

            this.data = data;
            isUpdate = true;
            lbSelect.Text = Constant.DEFAULT_TITLE_EDIT;

            if (Init())
            {
                tbMa.Text = data.Id.ToString();
                tbTen.Text = data.Ten;
                tbGia.Text = data.Gia.ToString();
                cbDVT.Text = data.DonViTinh;

                if (data.IsActived)
                {
                    rbBan.Checked = true;
                }
                else
                {
                    rbTamNgung.Checked = true;
                }

                tbGhiChu.Text = data.GhiChu;
            }
            else
            {
                this.Visible = false;
            }
        }
Esempio n. 3
0
        public UcDetail(DTO.SanPham data)
        {
            InitializeComponent();

            this.data = data;

            if (Init())
            {
                tbMa.Text = data.MaSanPham;
                cbGroup.Text = data.SanPhamGroup.Ten;
                tbTen.Text = data.Ten;

                if (data.IsActive)
                {
                    rbBan.Checked = true;
                }
                else
                {
                    rbTamNgung.Checked = true;
                }

                tbMoTa.Text = data.MoTa;
            }
            else
            {
                this.Visible = false;
            }
        }
Esempio n. 4
0
        public SanPham GetSanPhamByMASP(string strSP)
        {
            SanPham sp = null;
            try
            {
                if (conn.State != ConnectionState.Open)
                    conn.Open();

                OleDbCommand cmd = new OleDbCommand("Select * from tbSanPham Where masp=@madm Order By MaSP asc", conn);
                cmd.Parameters.Add("@masp", OleDbType.BSTR).Value = strSP;
                OleDbDataReader rd = cmd.ExecuteReader();
                if (rd.Read())
                {
                    sp = new SanPham();
                    sp.MaSanPham = rd["MaSP"].ToString();
                    sp.TenSanPham = rd["TenSP"].ToString();
                    sp.SoLuong = (int)rd["SoLuong"];
                    sp.DonGia = (int)rd["DonGia"];
                    sp.XuatXu = rd["XuatXu"].ToString();
                    sp.MaDanhMuc = rd["MaDM"].ToString();
                    conn.Close();
                }
            }
            catch (Exception)
            {
                conn.Close();
            }
            return sp;
        }
Esempio n. 5
0
        public UcInfo(DTO.SanPham data)
        {
            InitializeComponent();

            this.data = data;
            isUpdate = true;
            lbSelect.Text = Constant.DEFAULT_TITLE_EDIT;

            if (Init())
            {
                tbMa.Text = data.MaSanPham;
                tbTen.Text = data.Ten;

                if (data.IsActive)
                {
                    rbBan.Checked = true;
                }
                else
                {
                    rbTamNgung.Checked = true;
                }

                tbMoTa.Text = data.MoTa;

                cbGroup.Text = data.SanPhamGroup.Ten;
            }
            else
            {
                this.Visible = false;
            }
        }
Esempio n. 6
0
        public UcInfo(DTO.SanPham data)
        {
            InitializeComponent();

            this.data = data;
            isUpdate = true;
            lbSelect.Text = Constant.DEFAULT_TITLE_EDIT;

            if (Init())
            {
                tbMa.Text = data.MaSanPham;
                tbTen.Text = data.Ten;
                cbDVT.Text = data.DonViTinh;
                cbXuatXu.Text = data.XuatXu == null ? string.Empty : data.XuatXu.Ten;
                tbHieu.Text = data.Hieu;
                tbThoiHan.Text = data.ThoiHan.ToString();
                tbSize.Text = data.Size;
                tbMoTa.Text = data.MoTa;

                cbGroup.Text = data.SanPhamGroup.Ten;
                cbDonViThoiHan.Text = data.DonViThoiHan;
            }
            else
            {
                this.Visible = false;
            }
        }
Esempio n. 7
0
        public UcInfo()
        {
            InitializeComponent();

            dataHoaDon = new HoaDon();
            dataHoaDonDetail = new HoaDonDetail();
            dataSP = new DTO.SanPham();
            dataChietKhau = new ChietKhau();

            isUpdate = false;

            if (InitSP() && Init())
            {
                RefreshDataSP();

                RefreshData();

                CreateNewId();

                pbAvatar.Image = Image.FromFile(ConstantResource.SANPHAM_DEFAULT_SP);
            }
            else
            {
                this.Visible = false;
            }
        }
Esempio n. 8
0
        public UcInfo(DTO.SanPham data)
        {
            InitializeComponent();

            Init();

            this.data = data;

            LoadData(data);
        }
Esempio n. 9
0
        public UcInfo()
        {
            InitializeComponent();

            data = new DTO.SanPham();
            isUpdate = false;

            if (Init())
            {
                RefreshData();
            }
            else
            {
                this.Visible = false;
            }
        }
Esempio n. 10
0
        public static bool Delete(SanPham data, User user)
        {
            try
            {
                if (data != null)
                {
                    List<HoaDonDetail> listHoaDonDetail = HoaDonDetailDao.GetList(string.Empty, CommonDao.ID_TYPE_MUA, string.Empty, DateTime.Now,
                        string.Empty, string.Empty, 0, 0);

                    if (listHoaDonDetail != null)
                    {
                        listHoaDonDetail = listHoaDonDetail.Where(p => p.HoaDon.IdType == CommonDao.ID_TYPE_MUA &&
                            p.IdSanPham == data.Id && p.SanPham.DeleteFlag == false).ToList();
                        int total = 0;

                        foreach (HoaDonDetail detail in listHoaDonDetail)
                        {
                            total += detail.SoLuong;
                        }

                        if (total == data.SoLuong)
                        {
                            SanPham objDb = GetById(data.Id);

                            if (objDb != null)
                            {
                                data.UpdateBy = user.UserName;
                                data.UpdateDate = DateTime.Now;

                                objDb.DeleteFlag = true;
                                dbContext.SubmitChanges();

                                return true;
                            }
                        }
                    }
                }
            }
            catch
            {

            }

            CreateSQlConnection();

            return false;
        }
Esempio n. 11
0
 private void button3_Click(object sender, EventArgs e)
 {
     try
     {
         int sl = Convert.ToInt32(txtSoLuong.Text);
         int dg = Convert.ToInt32(txtGia.Text);
         SanPham sp = new SanPham(txtMaSP.Text, txtTenSp.Text, sl, dg, txtXuatXu.Text, cboDanhMuc.SelectedValue.ToString());
         if (objSP.UpdateSanPham(sp))
         {
             MessageBox.Show("Thành công");
             dataGridView1.DataSource = objSP.GetSanPhamByMADM(Form1.strMaDanhMuc_Chon);
         }
         else
             MessageBox.Show("Thất bại");
     }
     catch (Exception)
     {
         MessageBox.Show("Thất bại");
     }
 }
Esempio n. 12
0
 public bool AddSanPham(SanPham sp)
 {
     try
     {
         if (conn.State != ConnectionState.Open)
             conn.Open();
         OleDbCommand cmd = new OleDbCommand("Insert into tbSanPham Values (@masp, @tensp, @soluong, @dongia, @xuatxu, @madm)",conn);
         cmd.Parameters.Add("@masp", OleDbType.BSTR).Value = sp.MaSanPham;
         cmd.Parameters.Add("@tensp", OleDbType.BSTR).Value = sp.TenSanPham;
         cmd.Parameters.Add("@soluong", OleDbType.Numeric).Value = sp.SoLuong;
         cmd.Parameters.Add("@dongia", OleDbType.Numeric).Value = sp.DonGia;
         cmd.Parameters.Add("@xuatxu", OleDbType.BSTR).Value = sp.XuatXu;
         cmd.Parameters.Add("@madm", OleDbType.BSTR).Value = sp.MaDanhMuc;
         cmd.ExecuteNonQuery();
         conn.Close();
         return true;
     }
     catch (Exception e)
     {
         conn.Close();
         Console.WriteLine(e.Message);
         return false;
     }
 }
Esempio n. 13
0
 public bool AddSanPham(SanPham sp)
 {
     return objSP.AddSanPham(sp);
 }
Esempio n. 14
0
 public bool UpdateSanPham(SanPham sp)
 {
     try
     {
         if (conn.State != ConnectionState.Open)
             conn.Open();
         OleDbCommand cmd = new OleDbCommand("Update tbSanPham set tensp='" + sp.TenSanPham + "'" + " ,soluong=" + sp.SoLuong + " ,dongia=" + sp.DonGia + ", xuatxu='" + sp.XuatXu + "' , madm='" + sp.MaDanhMuc + "' where masp='" + sp.MaSanPham + "' ", conn);
         cmd.ExecuteNonQuery();
         conn.Close();
         return true;
     }
     catch (Exception e)
     {
         conn.Close();
         Console.WriteLine(e.Message);
         return false;
     }
 }
Esempio n. 15
0
        private void InsertData()
        {
            data = new DTO.SanPham();

            data.MaSanPham = tbMa.Text;
            data.Ten = tbTen.Text;
            data.IdGroup = ConvertUtil.ConvertToInt(((CommonComboBoxItems)cbGroup.SelectedItem).Value);
            data.MoTa = tbMoTa.Text;
            data.IsActive = rbBan.Checked;

            if (SanPhamBus.Insert(data, FormMain.user))
            {
                if (MessageBox.Show(string.Format(Constant.MESSAGE_INSERT_SUCCESS, "Sản phẩm " + data.MaSanPham) + Constant.MESSAGE_NEW_LINE + Constant.MESSAGE_CONTINUE, Constant.CAPTION_CONFIRMATION, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
                {
                    this.Dispose();
                }
                else
                {
                    RefreshData();
                    //CreateNewIdSP();
                }
            }
            else
            {
                if (MessageBox.Show(string.Format(Constant.MESSAGE_INSERT_ERROR_DUPLICATED, tbTen.Text) +
                    Constant.MESSAGE_NEW_LINE + Constant.MESSAGE_EXIT, Constant.CAPTION_ERROR, MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.OK)
                {
                    this.Dispose();
                }
            }
        }
Esempio n. 16
0
 partial void DeleteSanPham(SanPham instance);
Esempio n. 17
0
 partial void UpdateSanPham(SanPham instance);
Esempio n. 18
0
 partial void InsertSanPham(SanPham instance);
Esempio n. 19
0
        public static bool Update(SanPham data, User user)
        {
            try
            {
                if (data != null)
                {
                    data.UpdateBy = user.UserName;
                    data.UpdateDate = DateTime.Now;

                    dbContext.SubmitChanges();

                    return true;
                }

                return false;
            }
            catch
            {
                return false;
            }
        }
Esempio n. 20
0
		private void attach_SanPhams(SanPham entity)
		{
			this.SendPropertyChanging();
			entity.SanPhamGroup = this;
		}
Esempio n. 21
0
        public static bool Update(SanPham data)
        {
            try
            {
                if (data != null)
                {
                    dbContext.SubmitChanges();

                    return true;
                }

                return false;
            }
            catch
            {
                return false;
            }
        }
 /// <summary>
 /// Deprecated Method for adding a new object to the SanPhams EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToSanPhams(SanPham sanPham)
 {
     base.AddObject("SanPhams", sanPham);
 }
Esempio n. 23
0
        private void InsertData()
        {
            data = new DTO.SanPham();

            data.MaSanPham = tbMa.Text;
            data.Ten = tbTen.Text;
            data.IdGroup = ConvertUtil.ConvertToInt(((CommonComboBoxItems)cbGroup.SelectedItem).Value);

            if (cbXuatXu.SelectedItem != null)
            {
                data.IdXuatXu = ConvertUtil.ConvertToInt(((CommonComboBoxItems)cbXuatXu.SelectedItem).Value);
            }

            data.MoTa = tbMoTa.Text;
            data.DonViTinh = cbDVT.Text;
            data.Hieu = tbHieu.Text;
            data.Size = tbSize.Text;
            data.ThoiHan = ConvertUtil.ConvertToByte(tbThoiHan.Text);
            data.DonViThoiHan = cbDonViThoiHan.Text;

            if (SanPhamBus.Insert(data, FormMain.user))
            {
                this.Dispose();
            }
            else
            {
                if (MessageBox.Show(Constant.MESSAGE_INSERT_ERROR + Constant.MESSAGE_NEW_LINE + Constant.MESSAGE_EXIT, Constant.CAPTION_ERROR, MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.OK)
                {
                    this.Dispose();
                }
            }
        }
Esempio n. 24
0
 public bool UpdateSanPham(SanPham sp)
 {
     return objSP.UpdateSanPham(sp);
 }
Esempio n. 25
0
		private void detach_SanPhams(SanPham entity)
		{
			this.SendPropertyChanging();
			entity.SanPhamGroup = null;
		}
Esempio n. 26
0
        private void GetInfoSP()
        {
            try
            {
                dataSP = SanPhamBus.GetById(ConvertUtil.ConvertToInt(((CommonComboBoxItems)cbMaSP.SelectedItem).Value));
                dataCK = ChietKhauBus.GetByIdSP(dataSP.Id);

                if (dataSP.GiaBan == 0)
                {
                    MessageBox.Show(Constant.MESSAGE_ERROR_MISSING_MONEY, Constant.CAPTION_ERROR, MessageBoxButtons.OK, MessageBoxIcon.Error);

                    return;
                }

                tbTenSP.Text = dataSP.Ten;

                int soLuong = 0;
                bool isDuplicated = false;

                foreach (ListViewItem item in lvThongTin.Items)
                {
                    if (ConvertUtil.ConvertToInt(item.SubItems[1].Text) == dataSP.Id)
                    {
                        soLuong = ConvertUtil.ConvertToInt(item.SubItems[6].Text);
                        tbChietKhau.Text = ConvertUtil.ConvertToInt(item.SubItems[4].Text.Replace(Constant.SYMBOL_DISCOUNT, string.Empty)).ToString();
                        tbChietKhau.ReadOnly = true;
                        isDuplicated = true;

                        break;
                    }
                }

                soLuong = dataSP.SoLuong - soLuong;

                tbTon.Text = soLuong.ToString();

                if (soLuong > 0)
                {
                    tbSoLuong.Text = "1";
                    tbSoLuong.ReadOnly = false;
                }
                else
                {
                    tbSoLuong.Text = string.Empty;
                    tbSoLuong.ReadOnly = true;
                }

                if (!chbCKTongHD.Checked && !isDuplicated)
                {
                    tbChietKhau.ReadOnly = false;
                    tbChietKhau.Text = dataKH == null ? string.Empty : dataKH.KhachHangGroup.ChietKhau.ToString();

                    if (dataCK != null && dataCK.Value != 0)
                    {
                        tbChietKhau.Text = dataCK.Value.ToString();
                    }
                }

                tbDVT.Text = dataSP.DonViTinh;
                tbGiaBan.Text = dataSP.GiaBan.ToString(Constant.DEFAULT_FORMAT_MONEY);

                if (!string.IsNullOrEmpty(dataSP.Avatar))
                {
                    pbAvatar.Image = Convert_Function.ConvertByteArrayToImage(Convert_Function.ConvertStringToByteArray(dataSP.Avatar));
                }
                else
                {
                    pbAvatar.Image = Image.FromFile(ConstantResource.SANPHAM_DEFAULT_SP);
                }
            }
            catch
            {
                MessageBox.Show(Constant.MESSAGE_ERROR_NULL_DATA, Constant.CAPTION_ERROR, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Esempio n. 27
0
        public static bool Insert(SanPham data, User user)
        {
            try
            {
                data.CreateBy = data.UpdateBy = user.UserName;
                data.CreateDate = data.UpdateDate = DateTime.Now;

                dbContext.SanPhams.InsertOnSubmit(data);
                dbContext.SubmitChanges();

                return true;
            }
            catch
            {
                return false;
            }
        }
Esempio n. 28
0
        private void InsertData()
        {
            data = new DTO.SanPham();

            data.Ten = tbTen.Text;
            data.Gia = ConvertUtil.ConvertToInt(tbGia.Text);
            data.DonViTinh = cbDVT.Text;
            data.GhiChu = tbGhiChu.Text;
            data.IsActived = rbBan.Checked;

            if (SanPhamBus.Insert(data))
            {
                if (MessageBox.Show(string.Format(Constant.MESSAGE_INSERT_SUCCESS, "Sản phẩm " + data.Ten) + Constant.MESSAGE_NEW_LINE + Constant.MESSAGE_CONTINUE, Constant.CAPTION_CONFIRMATION, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
                {
                    this.Dispose();
                }
                else
                {
                    RefreshData();
                    //CreateNewIdSP();
                }
            }
            else
            {
                if (MessageBox.Show(string.Format(Constant.MESSAGE_INSERT_ERROR_DUPLICATED, tbTen.Text) +
                    Constant.MESSAGE_NEW_LINE + Constant.MESSAGE_EXIT, Constant.CAPTION_ERROR, MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.OK)
                {
                    this.Dispose();
                }
            }
        }
Esempio n. 29
0
        public UcInfo(DTO.HoaDonDetail data)
        {
            InitializeComponent();

            dataHoaDonDetail = data;
            dataHoaDon = data.HoaDon;
            dataSP = data.SanPham;
            dataChietKhau = ChietKhauBus.GetByIdSP(data.IdSanPham);
            dataXuatXu = dataSP.XuatXu;

            isUpdate = true;
            lbSelect.Text = Constant.DEFAULT_TITLE_EDIT;

            if (HoaDonDetailBus.CheckIfSold(data.IdSanPham))
            {
                tbSoLuong.ReadOnly = true;
            }

            cbChangeMoney.SelectedIndex = 0;

            if (InitSP() && Init())
            {
                tbMaSP.Text = dataSP.MaSanPham;
                cbGroup.Text = dataSP.SanPhamGroup.Ten;
                cbDVTSP.Text = dataSP.DonViTinh;
                tbTenSP.Text = dataSP.Ten;
                tbSize.Text = dataSP.Size;
                cbXuatXu.Text = dataXuatXu == null ? string.Empty : dataXuatXu.Ten;
                tbHieu.Text = dataSP.Hieu;
                tbThoiHan.Text = dataSP.ThoiHan == 0 ? string.Empty : dataSP.ThoiHan.ToString();
                cbDonViThoiHan.Text = dataSP.DonViThoiHan;
                tbMoTa.Text = dataSP.MoTa;

                tbMaNhap.Text = dataHoaDon.MaHoaDon;
                tbGiaNhap.Text = dataSP.GiaMua.ToString(Constant.DEFAULT_FORMAT_MONEY);
                tbSoLuong.Text = data.SoLuong.ToString();
                tbLaiSuat.Text = dataSP.LaiSuat.ToString();
                tbGiaBan.Text = dataSP.GiaBan.ToString(Constant.DEFAULT_FORMAT_MONEY);
                tbGhiChu.Text = dataHoaDon.GhiChu;

                tbChietKhau.Text = dataChietKhau == null ? string.Empty : dataChietKhau.Value.ToString();

                //avatarPath = Path.Combine(File_Function.getFinalFolder(listFolderAvatar), CommonFunc.setAvatarPath(dataSP.MaSanPham, dataSP.CreateDate));

                if (!string.IsNullOrEmpty(dataSP.Avatar))
                {
                    //string sImage = Convert_Function.ConvertByteArrayToString(Convert_Function.ConvertImageToByteArray(Image.FromFile(avatarPath)));
                    pbAvatar.Image = Convert_Function.ConvertByteArrayToImage(Convert_Function.ConvertStringToByteArray(dataSP.Avatar));
                }
                else
                {
                    pbAvatar.Image = Image.FromFile(ConstantResource.SANPHAM_DEFAULT_SP);
                }

                oldDate = dataSP.UpdateDate;
            }
            else
            {
                this.Visible = false;
            }
        }
Esempio n. 30
0
        public static bool Insert(SanPham data)
        {
            try
            {
                if (GetByName(data.Ten) != null)
                {
                    return false;
                }

                dbContext.SanPhams.InsertOnSubmit(data);
                dbContext.SubmitChanges();

                return true;
            }
            catch
            {
                return false;
            }
        }
Esempio n. 31
0
        private bool UpdateDataSP()
        {
            dataSP = SanPhamBus.GetById(dataHoaDonDetail.IdSanPham);

            dataSP.MaSanPham = tbMaSP.Text;
            dataSP.Ten = tbTenSP.Text;
            dataSP.SanPhamGroup = SanPhamGroupBus.GetById(ConvertUtil.ConvertToInt(((CommonComboBoxItems)cbGroup.SelectedItem).Value));

            if (cbXuatXu.SelectedItem != null)
            {
                dataXuatXu = XuatXuBus.GetById(ConvertUtil.ConvertToInt(((CommonComboBoxItems)cbXuatXu.SelectedItem).Value));
            }
            else
            {
                dataXuatXu = null;
            }

            dataSP.XuatXu = dataXuatXu;
            dataSP.MoTa = tbMoTa.Text;
            dataSP.DonViTinh = tbDonViTinh.Text;
            dataSP.Hieu = tbHieu.Text;
            dataSP.Size = tbSize.Text;
            dataSP.ThoiHan = ConvertUtil.ConvertToByte(tbThoiHan.Text);
            dataSP.DonViThoiHan = cbDonViThoiHan.Text;

            if (SanPhamBus.Update(dataSP, FormMain.user))
            {
                return true;
            }
            else
            {
                if (MessageBox.Show(Constant.MESSAGE_ERROR + Constant.MESSAGE_NEW_LINE + Constant.MESSAGE_EXIT, Constant.CAPTION_ERROR, MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.No)
                {
                    this.Dispose();
                }
            }

            return false;
        }