Beispiel #1
0
        public void xoa()
        {
            Console.Clear();
            Console.WriteLine("XOA THONG TIN HANG HOA ");
            List <hanghoa> list = spDLL.GetAllhanghoa();
            string         ma;

            Console.Write("Nhap ma hoa don  can xoa:");
            ma = Console.ReadLine();
            int i = 0;

            for (i = 0; i < list.Count; ++i)
            {
                if (list[i].Mahang == ma)
                {
                    break;
                }
            }

            if (i < list.Count)
            {
                hanghoa b = new hanghoa(list[i]);
                spDLL.xoahanghoa(b);
            }
            else
            {
                Console.WriteLine("Khong ton tai ma san pham nay");
            }
        }
Beispiel #2
0
        private void button2_Click(object sender, EventArgs e)
        {
            HANGHOADAL cmd  = new HANGHOADAL();
            hanghoa    data = new hanghoa();

            data.mahh        = txtma.Text;
            data.tenhh       = txtten.Text;
            data.dvt         = cbdvt.Text;
            data.loaihh      = cbloai.Text;
            data.soluong     = txtsoluong.Text;
            data.soluonggiam = txtsoluonggiam.Text;
            data.gia         = txtgia.Text;



            bool kt = cmd.hanghoa_update(data);

            if (kt == false)
            {
                MessageBox.Show("Loi");
            }
            else
            {
                MessageBox.Show("Sửa thành công");
            }
            Load_Data("select * from HANGHOA");
        }
Beispiel #3
0
        public hanghoa thongtinhanghoa(int id)
        {
            banhangDataContext context = new banhangDataContext();
            hanghoa            hh      = context.hanghoas.FirstOrDefault(x => x.mahang == id);

            return(hh);
        }
Beispiel #4
0
 private void gvchitietdonhang_CellClick(object sender, DataGridViewCellEventArgs e)
 {
     try
     {
         if (e.RowIndex > -1)
         {
             DataGridViewRow row   = gvchitietdonhang.Rows[e.RowIndex];
             frmhanghoa      frmhh = new frmhanghoa();
             hanghoa         hh    = frmhh.chitiethanghoa(row.Cells[1].Value.ToString());
             txtnhapmahang.Text  = hh.mahang.ToString();
             txtnhapmaloai.Text  = hh.maloai.ToString();
             txtnhapmanhom.Text  = hh.manhom.ToString();
             txtnhaptenhang.Text = hh.tenhang.ToString();
             txtnhapgia.Text     = hh.gia.ToString();
             txtnhaphinh.Text    = hh.hinh.ToString();
             txtnhapmota.Text    = hh.mota.ToString();
             string linkanh = tt.linkanh + hh.hinh.ToString();
             try
             {
                 picnhaphinh.Image    = Image.FromFile(linkanh);
                 picnhaphinh.SizeMode = PictureBoxSizeMode.StretchImage;
             }
             catch { picnhaphinh.Image = null; };
         }
     }
     catch { };
 }
Beispiel #5
0
        private void btntimhh_Click(object sender, EventArgs e)
        {
            try
            {
                string  id = txtnhapmahang.Text;
                hanghoa hh = chitiethanghoa(id);

                if (hh != null)
                {
                    txtnhapmaloai.Text  = hh.maloai + "";
                    txtnhapmanhom.Text  = hh.manhom + "";
                    txtnhaptenhang.Text = hh.tenhang + "";
                    txtnhapgia.Text     = hh.gia + "";
                    txtnhaphinh.Text    = hh.hinh + "";
                    txtnhapmota.Text    = hh.mota + "";
                    try
                    {
                        string linkanh = tt.linkanh + txtnhaphinh.Text;
                        picnhaphinh.Image    = Image.FromFile(linkanh);
                        picnhaphinh.SizeMode = PictureBoxSizeMode.StretchImage;
                    }
                    catch { picnhaphinh.Image = null; };
                }
            }
            catch { };
        }
Beispiel #6
0
        //Chèn một bản ghi hàng hóa vào tệp
        public void themhanghoa(hanghoa hh)
        {
            string       mahang = DateTime.Now.ToString("tt");
            StreamWriter fwrite = File.AppendText(txtfile);

            fwrite.WriteLine();
            fwrite.Write(mahang + "#" + hh.Tenhang + "#" + hh.Slnhap + "#" + hh.Slhienco);
            fwrite.Close();
        }
Beispiel #7
0
 public SuaHangHoa(hanghoa a)
 {
     InitializeComponent();
     tbma.Text      = a.mahh;
     tbgia.Text     = a.gia.ToString();
     tbslton.Text   = a.slton.ToString();
     tbten.Text     = a.tenhh;
     tbma.IsEnabled = false;
 }
Beispiel #8
0
        private void Click_Sua(object sender, RoutedEventArgs e)
        {
            var a = new hanghoa();

            a = (hanghoa)lvdsHangHoa.SelectedItem;
            SuaHangHoa sua = new SuaHangHoa(a);

            sua.ShowDialog();
            LoadDuLieu();
        }
Beispiel #9
0
        public void Nhap()
        {
            Console.Clear();
            Console.WriteLine("           NHAP THONG TIN HANG HOA   ");
            hanghoa sp = new hanghoa();

            Console.Write("Nhap ten hang :"); sp.Tenhang          = Console.ReadLine();
            Console.Write("Nhap so luong nhap :"); sp.Slnhap      = int.Parse(Console.ReadLine());
            Console.Write("Nhap so luong hien co :"); sp.Slhienco = int.Parse(Console.ReadLine());
            spDLL.themhanghoa(sp);
        }
Beispiel #10
0
 public void themhanghoa(hanghoa thh)
 {
     if (thh.Tenhang != "")
     {
         lhh.themhanghoa(thh);
     }
     else
     {
         throw new Exception("Du lieu sai");
     }
 }
Beispiel #11
0
        public hanghoa chitiethanghoa(string id)
        {
            string                     link           = tt.link + "hanghoa/" + id;
            HttpWebRequest             request        = WebRequest.CreateHttp(link);
            HttpWebResponse            response       = request.GetResponse() as HttpWebResponse;
            DataContractJsonSerializer jsonSerializer = new DataContractJsonSerializer(typeof(hanghoa));
            object                     responsedata   = jsonSerializer.ReadObject(response.GetResponseStream());
            hanghoa                    hh             = responsedata as hanghoa;

            return(hh);
        }
Beispiel #12
0
        private void btnthemvaodsmua_Click(object sender, EventArgs e)
        {
            frmhanghoa frmhh = new frmhanghoa();

            try
            {
                hanghoa hh = frmhh.chitiethanghoa(txtmahangtch.Text);

                if (hh != null)
                {
                    bool dkthem = true;
                    for (int i = 0; i < lvmuataicuahang.Items.Count; i++)
                    {
                        ListViewItem lv = lvmuataicuahang.Items[i];
                        if (txtmahangtch.Text == lv.SubItems[0].Text)
                        {
                            dkthem = false;
                        }
                    }
                    if (dkthem == true)
                    {
                        ListViewItem lvi = new ListViewItem(txtmahangtch.Text);
                        lvi.SubItems.Add(hh.tenhang);
                        lvi.SubItems.Add(txtsoluongtch.Text);
                        if (txtkhuyenmai.Text == "")
                        {
                            txtkhuyenmai.Text = "0";
                        }
                        float khuyenmai = ((float)Convert.ToDouble(txtkhuyenmai.Text) / 100) * hh.gia;
                        int   gia1sp    = hh.gia - (int)khuyenmai;
                        int   tong      = Convert.ToInt32(txtsoluongtch.Text) * gia1sp;
                        lvi.SubItems.Add(gia1sp.ToString());
                        lvi.SubItems.Add(tong.ToString());
                        lvmuataicuahang.Items.Add(lvi);
                    }
                    else
                    {
                        MessageBox.Show("sản phẩm đã tồn tại trong danh sách mua ");
                    }
                }
                else
                {
                    MessageBox.Show("không tìm thấy hàng hóa");
                }
            }
            catch { MessageBox.Show("loi!"); };
            txtmahangtch.Text  = "";
            txtsoluongtch.Text = "";
            txtkhuyenmai.Text  = "";
        }
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            var them = new hanghoa();

            them.tenhh = tbten.Text.ToString();
            them.mahh  = tbma.Text.ToString();
            them.slton = Int32.Parse(tbslton.Text);
            them.gia   = float.Parse(tbgia.Text);
            using (var db = new QLKEntities())
            {
                db.hanghoas.Add(them);
                db.SaveChanges();
            }
            this.Close();
        }
Beispiel #14
0
 public bool xoahanghoa(int mahang)
 {
     try
     {
         banhangDataContext context = new banhangDataContext();
         hanghoa            xoahh   = context.hanghoas.FirstOrDefault(x => x.mahang == mahang);
         if (xoahh != null)
         {
             context.hanghoas.DeleteOnSubmit(xoahh);
             context.SubmitChanges();
             return(true);
         }
     }
     catch { };
     return(false);
 }
Beispiel #15
0
        public void Sua()
        {
            Console.Clear();
            Console.WriteLine("SUA THONG TIN HANG HOA");
            List <hanghoa> list = spDLL.GetAllhanghoa();
            string         ma;

            Console.Write("Nhap ma hoa don ban can sua:");
            ma = Console.ReadLine();
            int i = 0;

            for (i = 0; i < list.Count; ++i)
            {
                if (list[i].Mahang == ma)
                {
                    break;
                }
            }

            if (i < list.Count)
            {
                hanghoa sp = new hanghoa(list[i]);
                //Console.Write("Nhap ma hang hoa:");
                //string mahh = Console.ReadLine();
                //if (mahh != "") sp.Mahang = mahh;
                Console.Write("ten hang:");
                string th = Console.ReadLine();
                sp.Tenhang = th;
                Console.Write("Nhap so luong nhap:");
                int sln = int.Parse(Console.ReadLine());
                if (sln > 0)
                {
                    sp.Slnhap = sln;
                }
                Console.Write("Nhap so luong hien co:");
                int slhc = int.Parse(Console.ReadLine());
                if (slhc > 0)
                {
                    sp.Slhienco = slhc;
                }
                spDLL.suahanghoa(sp);
            }
            else
            {
                Console.WriteLine("Khong ton tai ma hang hoa nay");
            }
        }
Beispiel #16
0
 private void Click_Xoa(object sender, RoutedEventArgs e)
 {
     if (lvdsHangHoa.SelectedItem != null)
     {
         var a = new hanghoa();
         a = (hanghoa)lvdsHangHoa.SelectedItem;
         using (var db = new QLKEntities())
         {
             var delete = (from d in db.hanghoas where d.mahh == a.mahh select d).Single();
             db.hanghoas.Remove(delete);
             db.SaveChanges();
         }
         QLKEntities t = new QLKEntities();
         lvdsHangHoa.ItemsSource = t.hanghoas.ToList();
         MessageBox.Show("Đã xóa.");
     }
 }
Beispiel #17
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            var sua = new hanghoa();

            sua.tenhh = tbten.Text.ToString();
            sua.mahh  = tbma.Text.ToString();
            sua.slton = Int32.Parse(tbslton.Text);
            sua.gia   = float.Parse(tbgia.Text);
            using (var db = new QLKEntities())
            {
                var update = (from u in db.hanghoas where u.mahh == sua.mahh select u).Single();
                update.tenhh = sua.tenhh;
                update.slton = sua.slton;
                update.gia   = sua.gia;
                db.SaveChanges();
            }
            this.Close();
        }
Beispiel #18
0
        public void Hientimkiem(hanghoa hh)
        {
            int            i;
            List <hanghoa> list = lhh.GetAllhanghoa();

            Console.WriteLine("mahang" + "\t" + "tenhang" + "\t" + "soluongnhap" + "\t" + "soluonghienco");
            for (i = 0; i < list.Count; ++i)
            {
                if (list[i].Mahang == hh.Mahang)
                {
                    Console.WriteLine(hh.Mahang + "\t" + hh.Tenhang + "\t\t" + hh.Slnhap + "\t\t" + hh.Slhienco);
                }

                else
                {
                    throw new Exception("Khong ton tai hs nay");
                }
            }
        }
Beispiel #19
0
        private void button3_Click(object sender, EventArgs e)
        {
            HANGHOADAL cmd  = new HANGHOADAL();
            hanghoa    data = new hanghoa();

            data.mahh = txtma.Text;

            bool kt = cmd.hanghoa_delete(data);

            if (kt == false)
            {
                MessageBox.Show("Loi");
            }
            else
            {
                MessageBox.Show("Xóa thành công");
            }
            Load_Data("select * from HANGHOA");
        }
Beispiel #20
0
 public bool themhanghoa(string maloai, int manhom, string tenhang, int gia, string hinh, string mota)
 {
     try
     {
         banhangDataContext context = new banhangDataContext();
         hanghoa            hhmoi   = new hanghoa();
         hhmoi.maloai  = maloai;
         hhmoi.manhom  = manhom;
         hhmoi.tenhang = tenhang;
         hhmoi.gia     = gia;
         hhmoi.hinh    = hinh;
         hhmoi.mota    = mota;
         context.hanghoas.InsertOnSubmit(hhmoi);
         context.SubmitChanges();
         return(true);
     }
     catch { };
     return(false);
 }
Beispiel #21
0
 public bool suahanghoa(int mahang, string maloai, int manhom, string tenhang, int gia, string hinh, string mota)
 {
     try
     {
         banhangDataContext context = new banhangDataContext();
         hanghoa            suahh   = context.hanghoas.FirstOrDefault(x => x.mahang == mahang);
         if (suahh != null)
         {
             suahh.maloai  = maloai;
             suahh.manhom  = manhom;
             suahh.tenhang = tenhang;
             suahh.gia     = gia;
             suahh.hinh    = hinh;
             suahh.mota    = mota;
             context.SubmitChanges();
             return(true);
         }
     }
     catch { };
     return(false);
 }
Beispiel #22
0
        public void xoahanghoa(hanghoa xhh)
        {
            int            i;
            List <hanghoa> list = lhh.GetAllhanghoa();

            for (i = 0; i < list.Count; ++i)
            {
                if (list[i].Mahang == xhh.Mahang)
                {
                    break;
                }
            }
            if (i < list.Count)
            {
                list.RemoveAt(i);
                lhh.update(list);
            }
            else
            {
                throw new Exception("Khong ton tai ma nay");
            }
        }
Beispiel #23
0
        public void Hientimkiem()
        {
            Console.Clear();
            Console.WriteLine("HIEN THONG TIN TIM KIEM");
            List <hanghoa> list = spDLL.GetAllhanghoa();
            string         ma;

            Console.Write("Nhap ma hang can hien thi:");
            ma = Console.ReadLine();
            int i;

            for (i = 0; i < list.Count; ++i)
            {
                if (list[i].Mahang == ma)
                {
                    break;
                }
            }
            if (i < list.Count)
            {
                hanghoa b = new hanghoa(list[i]);
                spDLL.Hientimkiem(b);
            }
        }