private void btnQuanLyHoaDon_Click(object sender, EventArgs e)
        {
            Form fQuanLyHoaDon = new QuanLyHoaDon("");

            fQuanLyHoaDon.Show();
            this.Hide();
        }
        private void btnXuatDS_Click(object sender, EventArgs e)
        {
            //Lay danh sach de in
            ArrayList listHD = new QuanLyHoaDon().getAllDataInvoice();

            try
            {
                string       fileName  = "HoaDon.txt";
                FileStream   output    = new FileStream(fileName, FileMode.Append, FileAccess.Write);
                StreamWriter writeFile = new StreamWriter(output);

                writeFile.WriteLine("Ngày: " + DateTime.Now);
                writeFile.WriteLine("\t\t\t\tDANH SÁCH HÓA ĐƠN");
                writeFile.WriteLine("{0}\t{1}\t{2}\t{3}\t\t{4}", "Mã HD", "Mã NV", "Tổng tiền", "Ngày lập HD", "Ghi chú");
                writeFile.WriteLine("-------------------------------------------------------------------------------------------------------------------------------");
                foreach (HoaDon hd in listHD)
                {
                    writeFile.WriteLine("{0}\t{1}\t{2}\t{3}\t\t{4}", hd.MaHD, hd.MaNV, hd.TongTien, hd.NgayLapHD, hd.GhiChu);
                }
                writeFile.Close();
                output.Close();
                MessageBox.Show("Xuất danh sách hóa đơn thành công", "Thông báo!", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (DirectoryNotFoundException)
            {
                MessageBox.Show("Không tìm thấy thư mục lưu file", "Thông báo", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation);
            }
            catch (IOException)
            {
                MessageBox.Show("Không xuất danh sách ra file được", "Thông báo", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation);
            }
        }
Exemple #3
0
        private void BtQuanLyHoaDon_Click(object sender, RoutedEventArgs e)
        {
            QuanLyHoaDon quanLyHoaDon = new QuanLyHoaDon();

            quanLyHoaDon.myEvent    += new EventHandler(OnClosedQuanLyHoaDonWindow);
            BtQuanLyHoaDon.IsEnabled = false;
            quanLyHoaDon.Show();
        }
        /// <summary>
        /// Xu ly su kien nut save chi tiet cac san pham vao hoa don
        ///</summary>
        private void btnSave_Click(object sender, EventArgs e)
        {
            //Hien thi nut thanh toan va nut xoa
            btnThanhToan.Enabled = true;
            btnXoa.Enabled       = true;
            //Lay ma hoa don co tong tien bang 0
            int    maHD = new QuanLyHoaDon().searchInvoiceHaveTotalMoneyIs0().MaHD;
            string s    = "";
            string t    = "Thông báo";
            //Lay thong tin
            string maSP      = cboThucDon.SelectedValue.ToString();
            double donGia    = 0;
            int    soLuong   = int.Parse(numUpd.Value.ToString());//lay so luong
            double thanhTien = 0;

            //Lay don gia va ma san pham
            SanPham sp = qlProducts.searchProductByID(maSP);

            donGia = sp.DonGia;
            //Kiem tra so luong con trong kho co du ban khong
            if (soLuong > sp.NSLuong)
            {
                s = "Số lượng trong kho không đủ bán! Số lượng còn lại của sản phẩm là " + sp.NSLuong;
                MessageBox.Show(s, t, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            thanhTien = sp.DonGia * soLuong;
            //tinh tong tien cua hoa don do
            double tongTienHD = 0.0;

            /*Kiem tra san pham trong chitiethoadon da ton tai chua  , neu ton tai thi tien hanh cap nhat so luong
             * Neu chua thi them san pham do vao chitiethoadon
             */
            bool check = false;//Khong co san pham bi trung

            foreach (ListViewItem item in lvwChiTiet.Items)
            {
                if (maSP.CompareTo(item.SubItems[0].Text) == 0)
                {
                    //Neu san pham ton tai thi tien hanh cho update so luong
                    soLuong = int.Parse(numUpd.Value.ToString());
                    //xoa san pham bi trung
                    lvwChiTiet.Items.Remove(item);
                    //Hien thi chi tiet cac san pham len listview
                    hienThiCT(new ChiTietHoaDon(maHD, maSP, donGia, soLuong, thanhTien));
                    check = true;
                }
            }

            //Tinh lai tong tien
            if (check == true)
            {
                foreach (ListViewItem item in lvwChiTiet.Items)
                {
                    tongTienHD += double.Parse(item.SubItems[4].Text);
                }
            }
            if (check == false)
            {
                ////Xoa listview de hien thi
                ListView.SelectedListViewItemCollection listVW = lvwChiTiet.SelectedItems;
                //Hien thi chi tiet cac san pham len listview

                hienThiCT(new ChiTietHoaDon(maHD, maSP, donGia, soLuong, thanhTien));
                numUpd.Value = 1;
                //Tinh lai tong tien luu hoa don
                listVW = lvwChiTiet.SelectedItems;
                foreach (ListViewItem item in lvwChiTiet.Items)
                {
                    tongTienHD += double.Parse(item.SubItems[4].Text);
                }
                txtTongTien.Text = tongTienHD.ToString();//hien thi tong tien len textbox
                return;
            }
            txtTongTien.Text = tongTienHD.ToString();//hien thi tong tien len textbox
        }
Exemple #5
0
        public string KiemTraTaiKhoan(string tenTaiKhoan, string matKhau)
        {
            try
            {
                SqlConnection connect = new SqlConnection(Program.sqlConnection);
                connect.Open();

                SqlCommand    cmd = new SqlCommand("Select * from NguoiDung", connect);
                SqlDataReader dr  = cmd.ExecuteReader();

                while (dr.Read())
                {
                    if (dr["TenDangNhap"].ToString() == "admin")
                    {
                        if (tenTaiKhoan == dr["TenDangNhap"].ToString())
                        {
                            if (matKhau == dr["MatKhau"].ToString())
                            {
                                connect.Close();
                                Form fQuanTri = new MenuQuanTri();
                                fQuanTri.Show();
                                this.Hide();
                                return("Admin");
                            }
                            else
                            {
                                MessageBox.Show("Sai mật khẩu!", "Lỗi đăng nhập", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                                connect.Close();
                                matKhau = "";
                                return("Sai mat khau tai khoan Admin");
                            }
                        }
                    }
                    else
                    {
                        if (tenTaiKhoan == dr["TenDangNhap"].ToString())
                        {
                            if (matKhau == dr["MatKhau"].ToString())
                            {
                                connect.Close();
                                Form fHoaDon = new QuanLyHoaDon(tenTaiKhoan);
                                fHoaDon.Show();
                                this.Hide();
                                return("ThuNgan");
                            }
                            else
                            {
                                MessageBox.Show("Sai mật khẩu!", "Lỗi đăng nhập", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                                matKhau = "";
                                connect.Close();
                                return("Sai mat khau tai khoan Thu ngan");
                            }
                        }
                    }
                }
                MessageBox.Show("Sai tên đăng nhập!", "Lỗi đăng nhập", MessageBoxButtons.OK, MessageBoxIcon.Warning);

                connect.Close();
                return("Sai ten dang nhap");
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message, "Thông báo", MessageBoxButtons.OK);
                return(e.Message);
            }
        }