Exemplo n.º 1
0
        private void btnLuu_Click(object sender, EventArgs e)
        {
            if (txtTen.Text == "" || txtGia.Text == "" || txtMaSp.Text == "" || txtSoLuong.Text == "" || string.IsNullOrEmpty(file))
            {
                MessageBox.Show("Bạn cần nhập đủ thông tin !");
                return;
            }

            try
            {
                SanPham sanpham = new SanPham()
                {
                    MaSp    = txtMaSp.Text,
                    MaLoai  = cmbLoai.SelectedValue.ToString(),
                    Gia     = Convert.ToInt32(txtGia.Text),
                    TenSp   = txtTen.Text,
                    SoLuong = Convert.ToInt32(txtSoLuong.Text),
                    Hinh    = imageMang
                };

                dbo.SanPhams.Add(sanpham);
                dbo.SaveChanges();
                MessageBox.Show("Thêm sản phẩm thành công !");

                return;
            }
            catch
            {
                MessageBox.Show("Không thành công !");
            }
        }
Exemplo n.º 2
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (textBox1.Text == "" || textBox2.Text == "")
            {
                MessageBox.Show("Bạn cần nhập đủ thông tin !");
                return;
            }
            try
            {
                SanPham sp = dbo.SanPhams.First(d => d.TenSp == label1.Text);
                if (sp.SoLuong - Convert.ToInt32(numericUpDown1.Value) >= 0)
                {
                    sp.SoLuong = sp.SoLuong - Convert.ToInt32(numericUpDown1.Value);
                    dbo.SaveChanges();
                }
                else
                {
                    MessageBox.Show("Số lượng sản phẩm trong kho không đủ !");
                    return;
                }

                Hoa_Don hoadon = new Hoa_Don()
                {
                    TenKh    = textBox1.Text,
                    SoDt     = Convert.ToInt32(textBox2.Text),
                    SoLuong  = Convert.ToInt32(numericUpDown1.Value),
                    SanPham  = label1.Text,
                    TongTien = Convert.ToInt32(label4.Text),
                    NgayBan  = DateTime.Today
                };
                hd.Hoa_Don.Add(hoadon);
                hd.SaveChanges();

                SaveFileDialog save = new SaveFileDialog();
                if (save.ShowDialog() == DialogResult.OK)
                {
                    string noidung = " \r\n Tên sản phẩm:   " + label1.Text + " \r\n Khách hàng:   " + textBox1.Text + "  \r\n Số điện thoại:   " + textBox2.Text + "  \r\n Số lượng:   " + numericUpDown1.Text + "  \r\n Thành tiền:   " + label4.Text + " VNĐ \r\n Ngày bán: " + DateTime.Today + "";
                    File.WriteAllText(save.FileName, noidung);
                }

                MessageBox.Show("Thanh toán thành công !");
            }
            catch
            {
                MessageBox.Show("Thanh toán thất bại !");
            }
        }
Exemplo n.º 3
0
 private void btnXoa_Click(object sender, EventArgs e)
 {
     try
     {
         if ((MessageBox.Show("Bạn thực sự muốn xóa ?", "Cảnh báo", MessageBoxButtons.YesNo, MessageBoxIcon.Warning)) == DialogResult.Yes)
         {
             string  tensp = dgvsp.CurrentRow.Cells["TenSp"].Value.ToString();
             SanPham sp    = dbo.SanPhams.First(i => i.TenSp == tensp);
             dbo.SanPhams.Remove(sp);
             dbo.SaveChanges();
             MessageBox.Show("Xóa thành công !");
             load();
             return;
         }
     }
     catch
     {
         MessageBox.Show("Xóa không thành công !");
     }
 }
Exemplo n.º 4
0
        private void btnLuu_Click(object sender, EventArgs e)
        {
            if (txtTen.Text == "" || txtGia.Text == "" || txtSoLuong.Text == "")
            {
                MessageBox.Show("Bạn cần nhập đủ thông tin !");
                return;
            }
            try
            {
                SanPham sp = dbo.SanPhams.First(d => d.TenSp == get);
                sp.Gia     = Convert.ToInt32(txtGia.Text);
                sp.TenSp   = txtTen.Text;
                sp.SoLuong = Convert.ToInt32(txtSoLuong.Text);
                sp.Hinh    = imageMang;
                sp.MaLoai  = cmbLoai.SelectedValue.ToString();
                dbo.SaveChanges();

                MessageBox.Show("Cập nhật thành công !");
            }
            catch
            {
                MessageBox.Show("Cập nhật không thành công !");
            }
        }
Exemplo n.º 5
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (txtMatKhauHienTai.Text == "" || txtMatKhauMoi.Text == "" || txtNhapLai.Text == "")
            {
                MessageBox.Show("Bạn cần điền đầy đủ thông tin !");
                return;
            }

            if (txtMatKhauHienTai.Text != Program.matKhau)
            {
                MessageBox.Show("Mật khẩu cũ không đúng !");
                return;
            }

            if (txtMatKhauMoi.Text != txtNhapLai.Text)
            {
                MessageBox.Show("Mật khẩu mới không khớp !");
                return;
            }

            try
            {
                QuanLyLinhKienEntity1 dbo = new QuanLyLinhKienEntity1();

                TaiKhoan tk = dbo.TaiKhoans.First(t => t.Ten == Program.tenTk);

                tk.MatKhau = txtMatKhauMoi.Text;
                dbo.SaveChanges();

                MessageBox.Show("Đổi mật khẩu thành công !");
            }
            catch
            {
                MessageBox.Show("Đổi mật khẩu không thành công !");
            }
        }