Esempio n. 1
0
 private void btnSave_Click(object sender, EventArgs e)
 {
     try
     {
         if (string.IsNullOrEmpty(cboSanPham.SelectedText))
         {
             MessageBox.Show("Chọn sản phẩm để điều chỉnh tồn kho.", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
             return;
         }
         DataSet ds = new DataAccess().getIDSanPhamByTenSP(cboSanPham.SelectedText);
         if (ds == null || ds.Tables[0].Rows.Count < 0 || string.IsNullOrEmpty(ds.Tables[0].Rows[0][0].ToString()))
         {
             // bi loi...
         }
         PhieuDieuChinhTonKho obj = new PhieuDieuChinhTonKho();
         obj.IDSanpham = Convert.ToInt32(ds.Tables[0].Rows[0]["IDSanPham"]);
         obj.SoluongDC = Convert.ToInt32(txtSoLuongDC.Text);
         obj.GhiChu = txtGhiChu.Text;
         new DataAccess().insertPhieuDieuChinhTonKho(obj);
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
     loadAllPhieuDieuChinh();
 }
Esempio n. 2
0
 private void btnSave_Click(object sender, EventArgs e)
 {
     //save Hoa Don
     HoaDonNhap objHoaDonNhap = new HoaDonNhap();
     objHoaDonNhap.Ngay = dateNgay.DateTime;
     objHoaDonNhap.IDNhanvien = arrIDNhanvien[cboNhanvien.SelectedIndex];
     objHoaDonNhap.Ghichu = txtGhiChu.Text;
     int IDHoaDonNhap = new DataAccess().insertHoaDonNhap(objHoaDonNhap);
     if (IDHoaDonNhap >= 0)
     {
         foreach (DataRow aRow in table.Rows)
         {
             ChiTietHoaDonNhap objChiTiet = new ChiTietHoaDonNhap();
             objChiTiet.IDHoaDonNhap = IDHoaDonNhap;
             objChiTiet.IDSanPham = Convert.ToInt32(aRow["IDSanPham"]);
             objChiTiet.GiaNhap = Convert.ToDecimal(aRow["GiaNhap"]);
             objChiTiet.SoLuong = Convert.ToInt32(aRow["SoLuong"]);
             if (new DataAccess().insertChiTietHoaDonNhap(objChiTiet) < 0)
             {
                 //error
                 MessageBox.Show(this, "Thêm mới Chi tiết hóa đơn nhập không thành công", "Thông báo lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
                 //delete
                 new DataAccess().deleteHoaDonNhap(objHoaDonNhap);
             }
         }
     }
     else
     {
         //error
         MessageBox.Show(this, "Thêm mới Hóa đơn nhập không thành công", "Thông báo lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
     btnAddChiTietHD.Enabled = false;
     btnSave.Enabled = false;
     btnClear.Enabled = true;
 }
Esempio n. 3
0
 private void loadAllComboBoxData()
 {
     try
     {
         // load Ten nhan vien
         cboNVLapGhiChu.Properties.Items.Clear();
         DataSet ds = new DataAccess().getAllNhanvien();
         if (ds != null)
         {
             foreach (DataRow item in ds.Tables[0].Rows)
             {
                 cboNVLapGhiChu.Properties.Items.Add(item["Username"].ToString());
             }
         }
         // load Ten cac loai su co
         cboLoaiGhiChu.Properties.Items.Clear();
         DataSet dsLoaiVD = new DataAccess().getAllLoaiVD();
         if (dsLoaiVD != null)
         {
             foreach (DataRow item in dsLoaiVD.Tables[0].Rows)
             {
                 cboLoaiGhiChu.Properties.Items.Add(item["TenVD"]);
             }
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("Tải dữ liệu về nhân viên và loại sự cố không thành công.");
     }
 }
Esempio n. 4
0
 private void btnLogin_Click(object sender, EventArgs e)
 {
     string username = this.txtUserName.Text;
     string password = this.txtPassword.Text;
     if (username != "" && password != "")
     {
         DataAccess da = new DataAccess();
         Nhanvien result = da.getNhanvienByUsername_Password(username, password);
         if (result != null)
         {
             Program.userLevel = (Level)(convertLoai2Level(result.Loai));
             Program.isLogin = true;
             Program.IDNhanvien = result.IDNhanvien;
             Program.username = result.Username;
             Program.password = result.Password;
             Program.userFullName = result.Ten;
             this.Close();
         }
         else
         {
             lblMess.Text = "Thông tin đăng nhập không hợp lệ!";
             txtUserName.Focus();
         }
     }
     else
     {
         lblMess.Text = "Thông tin đăng nhập không hợp lệ!";
         txtUserName.Focus();
     }
 }
Esempio n. 5
0
 public void frmInvoice_Load(object sender, EventArgs e)
 {
     DataSet ds = new DataAccess().getAllHoaDonNhap();
     HoaDonNhapRowsCount = ds.Tables[0].Rows.Count;
     gridControlHoaDonNhap.DataSource = ds.Tables[0];
     dateEditFrom.DateTime = DateTime.Now.Date;
     dateEditTo.DateTime = DateTime.Now.Date;
 }
Esempio n. 6
0
 private void AddItemForComboboxGiaLoaiPhong()
 {
     int i, rowcount;
     DataSet ds = new DataAccess().getAllKhunggio();
     repositoryItemComboBox5.Items.Clear();
     rowcount = Convert.ToInt32(ds.Tables[0].Rows.Count);
     for (i = 0; i < rowcount; i++)
         repositoryItemComboBox5.Items.Add(Convert.ToString(ds.Tables[0].Rows[i]["IDKhunggio"]));
 }
Esempio n. 7
0
 private void AddItemForComboboxLoaiphongSPBandau()
 {
     int i, rowcount;
     DataSet ds = new DataAccess().getAllSanPham();
     repositoryItemComboBox6.Items.Clear();
     rowcount = Convert.ToInt32(ds.Tables[0].Rows.Count);
     for (i = 0; i < rowcount; i++)
         repositoryItemComboBox6.Items.Add(Convert.ToString(ds.Tables[0].Rows[i]["TenSanPham"]));
 }
Esempio n. 8
0
 private void loadAllPhieuDieuChinh()
 {
     DataSet ds = new DataAccess().getAllPhieuDieuChinhTonKho();
     if (ds == null || ds.Tables[0].Rows.Count<0)
     {
         return;
     }
     gcDieuChinhTonKho.DataSource = ds.Tables[0];
 }
Esempio n. 9
0
 private void getBangNguyenLieu(int IDSanPham)
 {
     if (IDSanPham == -1)
     {
         gridControlCongThucPhaChe.DataSource = null;
         return;
     }
     DataSet ds = new DataAccess().getAllSPPhaCheByIDSanPham(IDSanPham);
     gridControlCongThucPhaChe.DataSource = ds.Tables[0];
 }
Esempio n. 10
0
 public frmHoaDonXuatDetail(int IDHoadon)
 {
     InitializeComponent();
     DataSet ds = new DataAccess().getAllIDandNameNhanvien();
     cboEmployee.DataSource = ds.Tables[0];
     cboEmployee.DisplayMember = "Ten";
     cboEmployee.ValueMember = "IDNhanvien";
     updateBillDisplay(IDHoadon);
     iCurrentReceiptID = IDHoadon;
 }
Esempio n. 11
0
        private void AddSPBD(int IDReceipt, int IDLoaiSP, int IDSanPham, string TenSP, int num)
        {
            //add a quantity of a product to current bill
            //check if the parameters are legal

            //DataSet prdPrice = new DataAccess().getGiaXuatSPByIDSanPham(ID);
            //if ((prdPrice != null) && (prdPrice.Tables[0].Rows.Count > 0))
            //{
            //txtPrice.Text = prdPrice.Tables[0].Rows[0][1].ToString();
            if (IDReceipt >= 0)
            {

                DataSet dsGia = new DataAccess().getGiaXuatSPByIDSanPham(IDSanPham);
                //if (ds == null)
                //    return;
                //if (ds.Tables[0].Rows.Count == 0)
                //{
                ChitietHDXuat obj = new ChitietHDXuat();
                obj.IDHoadonXuat = IDReceipt;
                obj.IDSanpham = IDSanPham;
                try
                {
                    obj.Gia = Convert.ToInt32(dsGia.Tables[0].Rows[0]["Gia"]);
                }
                catch
                {
                    MessageBox.Show("Chưa có giá cho " + TenSP, "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
                obj.Soluong = num;
                //get khuyen mai with this product ID
                DataSet ds = new DataAccess().getKhuyenmaiByIDLoaiSP(IDLoaiSP, DateTime.Now.Date);
                if (ds != null)
                {
                    try
                    {
                        obj.Giam = Convert.ToInt32(ds.Tables[0].Rows[0]["Giam"]);
                    }
                    catch (Exception ex)
                    {
                        obj.Giam = 0;
                    }
                }
                else
                    obj.Giam = 0;
                obj.Trangthai = false;
                int res = new DataAccess().insertChitietHDXuat(obj);
                if (res < 0)
                {
                    MessageBox.Show("Không thêm sản phẩm ban đầu vào hóa đơn hiện tại", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }

            }
        }
Esempio n. 12
0
 private void AddItemForComboboxTenNguyenLieu()
 {
     int i, rowcount;
     DataSet ds1 = new DataAccess().getAllSanPham();
     rowcount = Convert.ToInt32(ds1.Tables[0].Rows.Count);
     repositoryItemcboTenNguyenLieu.Items.Clear();
     if (ds1 == null || ds1.Tables[0].Rows.Count < 0)
     {
         return;
     }
     for (i = 0; i < rowcount; i++)
         repositoryItemcboTenNguyenLieu.Items.Add(Convert.ToString(ds1.Tables[0].Rows[i]["TenSanPham"]));
 }
Esempio n. 13
0
 // load cac thong tin lien quan
 private void loadDataRelatedToIssueProcessing()
 {
     // load Ten cac loai su co
     cboLoaiXuLy.Properties.Items.Clear();
     DataSet dsLoaiVD = new DataAccess().getAllLoaiVD();
     if (dsLoaiVD != null)
     {
         foreach (DataRow item in dsLoaiVD.Tables[0].Rows)
         {
             cboLoaiXuLy.Properties.Items.Add(item["TenVD"]);
         }
     }
 }
Esempio n. 14
0
 private void loadSanPham()
 {
     cboSanPham.Properties.Items.Clear();
     DataSet ds = new DataAccess().getAllSanPham();
     if (ds == null || ds.Tables[0].Rows.Count<0)
     {
         return;
     }
     for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
     {
         cboSanPham.Properties.Items.Add(ds.Tables[0].Rows[i]["TenSanPham"].ToString());
     }
 }
Esempio n. 15
0
 private void btnList_Click(object sender, EventArgs e)
 {
     try
     {
         DateTime dateFrom = dateEditFrom.DateTime;
         DateTime dateTo = dateEditTo.DateTime;
         DataSet ds = new DataAccess().getHoaDonNhap(dateFrom,dateTo);
         HoaDonNhapRowsCount = ds.Tables[0].Rows.Count;
         gridControlHoaDonNhap.DataSource = ds.Tables[0];
     }
     catch
     {
     }
 }
Esempio n. 16
0
        private void cbRoomViewChart_Click(object sender, EventArgs e)
        {
            if (rdRoomDate.Checked)
            {//By Date
                if (dtselectedRoom == null || dtselectedRoom.Rows.Count <= 0)
                {
                    MessageBox.Show("Bạn chưa chọn sản phẩm cần khảo sát. Vui lòng chọn một vài sản phẩm cần " +
                        "vẽ biều đồ ở khung loại sản phẩm!",
                        "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
                DateTime dtFrom = dtRoomByDateFrom.Value;
                DateTime dtTo = dtRoomByDateTo.Value;
                if (DateTime.Compare(dtFrom, dtTo) > 0)
                {
                    MessageBox.Show("Ngày bắt đầu lớn hơn ngày kết thúc. Vui lòng chọn lại thông tin ngày tháng",
                        "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
                else
                {
                    DataAccess da = new DataAccess();
                    TimeSpan ts = dtTo - dtFrom;
                    string stridRoom = "";
                    int i = 0, j = 0;
                    DateTime dtCurrent = dtFrom;
                    if (dtChartData != null && dtChartData.Rows.Count > 0)
                        dtChartData.Rows.Clear();
                    if (dtChartData != null && dtChartData.Columns.Count > 0)
                        dtChartData.Columns.Clear();
                    if (listofRoomName != null)
                        listofRoomName = null;
                    if (listofRoomID != null)
                        listofRoomID = null;
                    listofRoomName = new string[dtselectedRoom.Rows.Count];
                    listofRoomID = new int[dtselectedRoom.Rows.Count];
                    DataColumn dcdt = new DataColumn("Ngayxuat", Type.GetType("System.String"));
                    dtChartData.Columns.Add(dcdt);
                    for (i = 0; i < dtselectedRoom.Rows.Count; i++)
                    {
                        DataColumn dc = new DataColumn(Convert.ToString(dtselectedRoom.Rows[i]["TenPhong"]),
                            Type.GetType("System.String"));
                        dtChartData.Columns.Add(dc);
                        listofRoomName[i] = Convert.ToString(dtselectedRoom.Rows[i]["TenPhong"]);
                        listofRoomID[i] = Convert.ToInt32(dtselectedRoom.Rows[i]["IDPhong"]);
                        if (i == 0)
                        {
                            stridRoom += " and (";
                            stridRoom += " Phong.IDPhong = " + Convert.ToString(dtselectedRoom.Rows[i]["IDPhong"]);
                        }
                        else
                        {
                            stridRoom += " or " + " Phong.IDPhong = " + Convert.ToString(dtselectedRoom.Rows[i]["IDPhong"]);
                        }
                        if (i == dtselectedRoom.Rows.Count - 1)
                        {
                            stridRoom += ")";
                        }

                    }
                    string strWheredate = "";
                    string strQuery = "";
                    for (j = 0; j <= ts.Days; j++)
                    {
                        dtCurrent = dtFrom.AddDays(j);
                        //Get the number of product sold in that day.
                        strWheredate = "And Year(Ngayxuat) = " + dtCurrent.Year +
                            " and Month(Ngayxuat) = " + dtCurrent.Month +
                                " and Day(Ngayxuat) = " + dtCurrent.Day + " ";

                        strQuery =
                            "Select IDHoadonxuat, Hoadonxuat.IDGiaLoaiPhong, Ngayxuat, " +
                            "GioBD, GioKT, TenPhong " +
                            " From  Hoadonxuat, Phong" +
                            " Where Hoadonxuat.IDPhong = Phong.IDPhong " + stridRoom + strWheredate;
                        DataSet dsTemp = da.getDataByQuery(strQuery);
                        DataRow dr = dtChartData.NewRow();
                        dr["Ngayxuat"] = dtCurrent.ToString("MM/dd/yyyy");
                        if (dsTemp != null)
                        {
                            for (i = 0; i < dsTemp.Tables[0].Rows.Count; i++)
                            {
                                string colName = Convert.ToString(dsTemp.Tables[0].Rows[i]["TenPhong"]);

                                DateTime dtBD = Convert.ToDateTime(dsTemp.Tables[0].Rows[i]["GioBD"].ToString());
                                DateTime dtKT = Convert.ToDateTime(dsTemp.Tables[0].Rows[i]["GioKT"].ToString());
                                TimeSpan dif = dtKT - dtBD;
                                Decimal soluongGio = dif.Hours + Convert.ToDecimal(dif.Minutes) / 60;

                                if (!(dr[colName] is DBNull))
                                    soluongGio += Convert.ToDecimal(dr[colName]);
                                dr[colName] = soluongGio.ToString("###,###,###,##0.##");
                            }
                            dtChartData.Rows.Add(dr);
                        }
                    }
                    if (dtChartData == null || dtChartData.Rows.Count == 0)
                    {
                        MessageBox.Show("Dữ liệu rỗng! Xin vui lòng chọn lại dữ liệu", "Thông báo",
                            MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                    else
                    {
                        frmChartView ch = new frmChartView(dtChartData, "ByDate", listofRoomName);
                        ch.ShowDialog();
                    }
                }
            }
            else if (rdRoomMonth.Checked)
            {//By Month
                if (dtselectedRoom == null || dtselectedRoom.Rows.Count <= 0)
                {
                    MessageBox.Show("Bạn chưa chọn sản phẩm cần khảo sát. Vui lòng chọn một vài sản phẩm cần " +
                        "vẽ biều đồ ở khung loại sản phẩm!",
                        "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }

                if (cbRoomByMonthFromMonth.Text == "" || cbRoomByMonthToMonth.Text == "" ||
                    cbRoomByMonthFromYear.Text == "" || cbRoomByMonthToYear.Text == "")
                {
                    MessageBox.Show("Bạn chưa thông tin tháng năm. Vui lòng chọn tháng bắt đầu và tháng kết thúc ",
                        "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
                int startMonth = Convert.ToInt32(cbRoomByMonthFromMonth.Text);
                int endMondth = Convert.ToInt32(cbRoomByMonthToMonth.Text);
                int startYear = Convert.ToInt32(cbRoomByMonthFromYear.Text);
                int endYear = Convert.ToInt32(cbRoomByMonthToYear.Text);
                DateTime start = new DateTime(startYear, startMonth, 1);
                DateTime end = new DateTime(endYear, endMondth, 1);
                if (DateTime.Compare(start, end) > 0)
                {
                    MessageBox.Show("Ngày bắt đầu lớn hơn ngày kết thúc. Vui lòng chọn lại thông tin ngày tháng",
                        "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
                else
                {
                    DataAccess da = new DataAccess();
                    DateTime dtCurrent = start;
                    int diff = (endYear - startYear) * 12 + (endMondth - startMonth);

                    string stridRoom = "";
                    int i = 0, j = 0;
                    if (dtChartData != null && dtChartData.Rows.Count > 0)
                        dtChartData.Rows.Clear();
                    if (dtChartData != null && dtChartData.Columns.Count > 0)
                        dtChartData.Columns.Clear();
                    if (listofRoomName != null)
                        listofRoomName = null;
                    if (listofRoomID != null)
                        listofRoomID = null;
                    listofRoomName = new string[dtselectedRoom.Rows.Count];
                    listofRoomID = new int[dtselectedRoom.Rows.Count];
                    DataColumn dcdt = new DataColumn("Ngayxuat", Type.GetType("System.String"));
                    dtChartData.Columns.Add(dcdt);
                    for (i = 0; i < dtselectedRoom.Rows.Count; i++)
                    {
                        DataColumn dc = new DataColumn(Convert.ToString(dtselectedRoom.Rows[i]["TenPhong"]),
                            Type.GetType("System.String"));
                        dtChartData.Columns.Add(dc);
                        listofRoomName[i] = Convert.ToString(dtselectedRoom.Rows[i]["TenPhong"]);
                        listofRoomID[i] = Convert.ToInt32(dtselectedRoom.Rows[i]["IDPhong"]);
                        if (i == 0)
                        {
                            stridRoom += " and (";
                            stridRoom += " Phong.IDPhong = " + Convert.ToString(dtselectedRoom.Rows[i]["IDPhong"]);
                        }
                        else
                        {
                            stridRoom += " or " + " Phong.IDPhong = " + Convert.ToString(dtselectedRoom.Rows[i]["IDPhong"]);
                        }
                        if (i == dtselectedRoom.Rows.Count - 1)
                        {
                            stridRoom += ")";
                        }

                    }
                    string strWheredate = "";
                    string strQuery = "";
                    for (j = 0; j <= diff; j++)
                    {
                        dtCurrent = start.AddMonths(j);
                        //Get the number of product sold in that day.
                        strWheredate = "And Year(Ngayxuat) = " + dtCurrent.Year +
                            " and Month(Ngayxuat) = " + dtCurrent.Month + " ";

                        strQuery =
                            "Select IDHoadonxuat, Hoadonxuat.IDGiaLoaiPhong, Ngayxuat, " +
                            "GioBD, GioKT, TenPhong " +
                            " From  Hoadonxuat, Phong" +
                            " Where Hoadonxuat.IDPhong = Phong.IDPhong " + stridRoom + strWheredate;
                        DataSet dsTemp = da.getDataByQuery(strQuery);
                        DataRow dr = dtChartData.NewRow();
                        dr["Ngayxuat"] = dtCurrent.ToString("MM/yyyy");
                        if (dsTemp != null)
                        {
                            for (i = 0; i < dsTemp.Tables[0].Rows.Count; i++)
                            {
                                string colName = Convert.ToString(dsTemp.Tables[0].Rows[i]["TenPhong"]);

                                DateTime dtBD = Convert.ToDateTime(dsTemp.Tables[0].Rows[i]["GioBD"].ToString());
                                DateTime dtKT = Convert.ToDateTime(dsTemp.Tables[0].Rows[i]["GioKT"].ToString());
                                TimeSpan dif = dtKT - dtBD;
                                Decimal soluongGio = dif.Hours + Convert.ToDecimal(dif.Minutes) / 60;

                                if (!(dr[colName] is DBNull))
                                    soluongGio += Convert.ToDecimal(dr[colName]);
                                dr[colName] = soluongGio.ToString("###,###,###,##0.##");
                            }
                            dtChartData.Rows.Add(dr);
                        }
                    }
                    if (dtChartData == null || dtChartData.Rows.Count == 0)
                    {
                        MessageBox.Show("Dữ liệu rỗng! Xin vui lòng chọn lại dữ liệu", "Thông báo",
                            MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                    else
                    {
                        frmChartView ch = new frmChartView(dtChartData, "ByMonth", listofRoomName);
                        ch.ShowDialog();
                    }
                }
            }
        }
Esempio n. 17
0
        private void btnInComeViewChart_Click(object sender, EventArgs e)
        {
            if (rdInComeDate.Checked)
            {//By Date
                DateTime dtFrom = dtInComeByDateFromDate.Value;
                DateTime dtTo = dtInComeByDateToDate.Value;
                if (DateTime.Compare(dtFrom, dtTo) > 0)
                {
                    MessageBox.Show("Ngày bắt đầu lớn hơn ngày kết thúc. Vui lòng chọn lại thông tin ngày tháng",
                        "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
                else
                {
                    DataAccess da = new DataAccess();
                    TimeSpan ts = dtTo - dtFrom;
                    //string stridProduct = "";
                    int i = 0, j = 0;
                    DateTime dtCurrent = dtFrom;
                    if (dtChartData != null && dtChartData.Rows.Count > 0)
                        dtChartData.Rows.Clear();
                    if (dtChartData != null && dtChartData.Columns.Count > 0)
                        dtChartData.Columns.Clear();
                    //if (listofProductName != null)
                    //    listofProductName = null;
                    //if (listofProductID != null)
                    //    listofProductID = null;
                    //listofProductName = new string[dtSelectedProduct.Rows.Count];
                    //listofProductID = new int[dtSelectedProduct.Rows.Count];
                    DataColumn dcdt = new DataColumn("Ngayxuat", Type.GetType("System.String"));
                    dtChartData.Columns.Add(dcdt);
                    DataColumn dcTT = new DataColumn("ThanhTien", Type.GetType("System.String"));
                    dtChartData.Columns.Add(dcTT);
                    string strWheredate = "";
                    string strQuery = "";
                    for (j = 0; j <= ts.Days; j++)
                    {
                        dtCurrent = dtFrom.AddDays(j);
                        //Get the number of product sold in that day.
                        strWheredate = "And Year(Ngayxuat) = " + dtCurrent.Year +
                            " and Month(Ngayxuat) = " + dtCurrent.Month +
                                " and Day(Ngayxuat) = " + dtCurrent.Day + " ";

                        DataSet dsTP_PT = null;
                        if (chkInComePhuThu_TienPhong.Checked)
                        {
                            string strQueryPhong_PT =
                                "Select IDHoadonxuat, Hoadonxuat.IDGiaLoaiPhong, Ngayxuat As NgayBan, " +
                                "Phuthu, GioBD, GioKT, GiaLoaiPhong.Gia, TenPhong As TenSanPham" +
                                " From  Hoadonxuat, Phong, GiaLoaiPhong" +
                                " Where Hoadonxuat.IDPhong = Phong.IDPhong and " +
                                " Hoadonxuat.IDGiaLoaiPhong = GiaLoaiPhong.IDGiaLoaiPhong " + strWheredate;
                            dsTP_PT = (DataSet)(da.getDataByQuery(strQueryPhong_PT));
                        }
                        string subQuerySP = "Select Hoadonxuat.IDHoadonXuat, Ngayxuat As NgayBan, SanPham.IDSanPham, TenSanPham, Soluong, " +
                            "DVT, Hoadonxuat.Giam, Max(NgayXuatSP) as NgayXuatSP1 " +
                            "From Hoadonxuat, ChitietHDXuat,  SanPham, NhomSP, GiaXuatSP " +
                            "Where ChitietHDXuat.IDHoadonXuat = Hoadonxuat.IDHoadonXuat and " +
                            "NhomSP.IDNhomSP = SanPham.IDNhomSP and " +
                            "SanPham.IDSanPham = ChitietHDXuat.IDSanPham and " +
                            "SanPham.IDSanPham = GiaXuatSP.IDSanPham " + strWheredate +
                            " and (Year(NgayXuatSP) < Year(Ngayxuat) or " +
                            "(Year(NgayXuatSP) = Year(Ngayxuat) and Month(NgayXuatSP) < Month(Ngayxuat)) or " +
                            "(Year(NgayXuatSP) = Year(Ngayxuat) and Month(NgayXuatSP) = Month(Ngayxuat) and Day(NgayXuatSP) <= Day(Ngayxuat)))" +
                            " GROUP BY Hoadonxuat.IDHoadonXuat, Ngayxuat, SanPham.IDSanPham, TenSanPham, Soluong, " +
                            "DVT, Hoadonxuat.Giam ";
                        strQuery = "Select T.IDHoadonXuat, T.NgayBan, T.IDSanPham, T.TenSanPham, T.Soluong, " +
                            "T.DVT, T.Giam, T.NgayXuatSP1, Max(Gia) as Gia " +
                            "From GiaXuatSP, (" + subQuerySP + ") as T " +
                            "Where T.IDSanPham = GiaXuatSP.IDSanPham and " +
                            "T.NgayXuatSP1 = GiaXuatSP.NgayXuatSP " +
                            "GROUP BY T.IDHoadonXuat, T.NgayBan, T.IDSanPham, T.TenSanPham, T.Soluong, " +
                            "T.DVT, T.Giam, T.NgayXuatSP1";
                        //dsSP = (DataSet)(da.getDataByQuery(strQuery));
                        //strQuery = "Select SanPham.IDSanPham, SanPham.TenSanPham, SanPham.DVT, " +
                        //    "Hoadonxuat.Ngayxuat, Sum(soluong) as TongSoluong " +
                        //    "From SanPham, ChitietHDXuat, Hoadonxuat " +
                        //    "Where SanPham.IDSanPham = ChitietHDXuat.IDSanPham and " +
                        //    "ChitietHDXuat.IDHoadonXuat = Hoadonxuat.IDHoadonXuat " +
                        //    strWheredate +
                        //    "Group by SanPham.IDSanPham, SanPham.TenSanPham, " +
                        //    "SanPham.DVT, Hoadonxuat.Ngayxuat " +
                        //    "ORDER BY Hoadonxuat.Ngayxuat";
                        DataSet dsTemp = da.getDataByQuery(strQuery);
                        DataRow dr = dtChartData.NewRow();
                        dr["Ngayxuat"] = dtCurrent.ToString("MM/dd/yyyy");
                        /////////////////////////////
                        if (dsTemp != null)
                        {
                            for (i = 0; i < dsTemp.Tables[0].Rows.Count; i++)
                            {
                                Decimal soluong = Convert.ToDecimal(dsTemp.Tables[0].Rows[i]["Soluong"].ToString());
                                Decimal gia = Convert.ToDecimal(dsTemp.Tables[0].Rows[i]["Gia"].ToString());
                                Decimal tt = gia * soluong;
                                if (!(dr["ThanhTien"] is DBNull || dr["ThanhTien"] == ""))
                                    tt += Convert.ToDecimal(dr["ThanhTien"]);
                                dr["ThanhTien"] = (tt).ToString("###,###,###,###.##");
                            }
                        }
                        if (dsTP_PT != null)
                        {
                            for (i = 0; i < dsTP_PT.Tables[0].Rows.Count; i++)
                            {
                                Decimal gia = Convert.ToDecimal(dsTP_PT.Tables[0].Rows[i]["Gia"].ToString());
                                DateTime dtBD = Convert.ToDateTime(dsTP_PT.Tables[0].Rows[i]["GioBD"].ToString());
                                DateTime dtKT = Convert.ToDateTime(dsTP_PT.Tables[0].Rows[i]["GioKT"].ToString());
                                TimeSpan dif = dtKT - dtBD;
                                Decimal soluongGio = dif.Hours + Convert.ToDecimal(dif.Minutes) / 60;
                                Decimal tt = soluongGio * gia;
                                if (!(dr["ThanhTien"] is DBNull || dr["ThanhTien"] == ""))
                                    tt += Convert.ToDecimal(dr["ThanhTien"]);
                                dr["ThanhTien"] = (tt).ToString("###,###,###,###.##");
                                if (dsTP_PT.Tables[0].Rows[i]["PhuThu"].ToString() != "")
                                {
                                    Decimal phuThu = Convert.ToDecimal(dsTP_PT.Tables[0].Rows[i]["PhuThu"].ToString());
                                    if (phuThu != 0)
                                    {
                                        if (!(dr["ThanhTien"] is DBNull || dr["ThanhTien"] == ""))
                                            phuThu += Convert.ToDecimal(dr["ThanhTien"]);
                                        dr["ThanhTien"] = (phuThu).ToString("###,###,###,###.##");
                                    }
                                }
                            }
                        }
                        dtChartData.Rows.Add(dr);
                        ////////////////////////////
                    }
                    if (dtChartData == null || dtChartData.Rows.Count == 0)
                    {
                        MessageBox.Show("Dữ liệu rỗng! Xin vui lòng chọn lại dữ liệu", "Thông báo",
                            MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                    else
                    {
                        frmChartView ch = new frmChartView(dtChartData, "ByDate");
                        ch.ShowDialog();
                    }
                }
            }
            else if (rdInComeMonth.Checked)
            {//By Month
                if (cbInComeByMonthFromMonth.Text == "" || cbInComeByMonthToMonth.Text == "" ||
                    cbInComeByMonthFromYear.Text == "" || cbInComeByMonthToYear.Text == "")
                {
                    MessageBox.Show("Bạn chưa thông tin tháng năm. Vui lòng chọn tháng bắt đầu và tháng kết thúc ",
                        "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
                int startMonth = Convert.ToInt32(cbInComeByMonthFromMonth.Text);
                int endMondth = Convert.ToInt32(cbInComeByMonthToMonth.Text);
                int startYear = Convert.ToInt32(cbInComeByMonthFromYear.Text);
                int endYear = Convert.ToInt32(cbInComeByMonthToYear.Text);
                DateTime start = new DateTime(startYear, startMonth, 1);
                DateTime end = new DateTime(endYear, endMondth, 1);
                if (DateTime.Compare(start, end) > 0)
                {
                    MessageBox.Show("Ngày bắt đầu lớn hơn ngày kết thúc. Vui lòng chọn lại thông tin ngày tháng",
                        "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
                else
                {
                    DataAccess da = new DataAccess();
                    //string stridProduct = "";
                    int i = 0, j = 0;
                    DateTime dtCurrent = start;
                    int diff = (endYear - startYear) * 12 + (endMondth - startMonth);
                    if (dtChartData != null && dtChartData.Rows.Count > 0)
                        dtChartData.Rows.Clear();
                    if (dtChartData != null && dtChartData.Columns.Count > 0)
                        dtChartData.Columns.Clear();
                    DataColumn dcdt = new DataColumn("Ngayxuat", Type.GetType("System.String"));
                    dtChartData.Columns.Add(dcdt);
                    DataColumn dcTT = new DataColumn("ThanhTien", Type.GetType("System.String"));
                    dtChartData.Columns.Add(dcTT);
                    string strWheredate = "";
                    string strQuery = "";
                    for (j = 0; j <= diff; j++)
                    {
                        dtCurrent = start.AddMonths(j);
                        //Get the number of product sold in that day.
                        strWheredate = "And Year(Ngayxuat) = " + dtCurrent.Year +
                            " and Month(Ngayxuat) = " + dtCurrent.Month + " ";
                        DataSet dsTP_PT = null;
                        if (chkInComePhuThu_TienPhong.Checked)
                        {
                            string strQueryPhong_PT =
                                "Select IDHoadonxuat, Hoadonxuat.IDGiaLoaiPhong, Ngayxuat As NgayBan, " +
                                "Phuthu, GioBD, GioKT, GiaLoaiPhong.Gia, TenPhong As TenSanPham" +
                                " From  Hoadonxuat, Phong, GiaLoaiPhong" +
                                " Where Hoadonxuat.IDPhong = Phong.IDPhong and " +
                                " Hoadonxuat.IDGiaLoaiPhong = GiaLoaiPhong.IDGiaLoaiPhong " + strWheredate;
                            dsTP_PT = (DataSet)(da.getDataByQuery(strQueryPhong_PT));
                        }
                        string subQuerySP = "Select Hoadonxuat.IDHoadonXuat, Ngayxuat As NgayBan, SanPham.IDSanPham, TenSanPham, Soluong, " +
                            "DVT, Hoadonxuat.Giam, Max(NgayXuatSP) as NgayXuatSP1 " +
                            "From Hoadonxuat, ChitietHDXuat,  SanPham, NhomSP, GiaXuatSP " +
                            "Where ChitietHDXuat.IDHoadonXuat = Hoadonxuat.IDHoadonXuat and " +
                            "NhomSP.IDNhomSP = SanPham.IDNhomSP and " +
                            "SanPham.IDSanPham = ChitietHDXuat.IDSanPham and " +
                            "SanPham.IDSanPham = GiaXuatSP.IDSanPham " + strWheredate +
                            " and (Year(NgayXuatSP) < Year(Ngayxuat) or " +
                            "(Year(NgayXuatSP) = Year(Ngayxuat) and Month(NgayXuatSP) < Month(Ngayxuat)) or " +
                            "(Year(NgayXuatSP) = Year(Ngayxuat) and Month(NgayXuatSP) = Month(Ngayxuat) and Day(NgayXuatSP) <= Day(Ngayxuat)))" +
                            " GROUP BY Hoadonxuat.IDHoadonXuat, Ngayxuat, SanPham.IDSanPham, TenSanPham, Soluong, " +
                            "DVT, Hoadonxuat.Giam ";
                        strQuery = "Select T.IDHoadonXuat, T.NgayBan, T.IDSanPham, T.TenSanPham, T.Soluong, " +
                            "T.DVT, T.Giam, T.NgayXuatSP1, Max(Gia) as Gia " +
                            "From GiaXuatSP, (" + subQuerySP + ") as T " +
                            "Where T.IDSanPham = GiaXuatSP.IDSanPham and " +
                            "T.NgayXuatSP1 = GiaXuatSP.NgayXuatSP " +
                            "GROUP BY T.IDHoadonXuat, T.NgayBan, T.IDSanPham, T.TenSanPham, T.Soluong, " +
                            "T.DVT, T.Giam, T.NgayXuatSP1";

                        DataSet dsTemp = da.getDataByQuery(strQuery);
                        DataRow dr = dtChartData.NewRow();
                        dr["Ngayxuat"] = dtCurrent.ToString("MM/yyyy");

                        /////////////////////////////
                        if (dsTemp != null)
                        {
                            for (i = 0; i < dsTemp.Tables[0].Rows.Count; i++)
                            {
                                Decimal soluong = Convert.ToDecimal(dsTemp.Tables[0].Rows[i]["Soluong"].ToString());
                                Decimal gia = Convert.ToDecimal(dsTemp.Tables[0].Rows[i]["Gia"].ToString());
                                Decimal tt = gia * soluong;
                                if (!(dr["ThanhTien"] is DBNull || dr["ThanhTien"] == ""))
                                    tt += Convert.ToDecimal(dr["ThanhTien"]);
                                dr["ThanhTien"] = (tt).ToString("###,###,###,###.##");
                            }
                        }
                        if (dsTP_PT != null)
                        {
                            for (i = 0; i < dsTP_PT.Tables[0].Rows.Count; i++)
                            {
                                Decimal gia = Convert.ToDecimal(dsTP_PT.Tables[0].Rows[i]["Gia"].ToString());
                                DateTime dtBD = Convert.ToDateTime(dsTP_PT.Tables[0].Rows[i]["GioBD"].ToString());
                                DateTime dtKT = Convert.ToDateTime(dsTP_PT.Tables[0].Rows[i]["GioKT"].ToString());
                                TimeSpan dif = dtKT - dtBD;
                                Decimal soluongGio = dif.Hours + Convert.ToDecimal(dif.Minutes) / 60;
                                Decimal tt = soluongGio * gia;
                                if (!(dr["ThanhTien"] is DBNull || dr["ThanhTien"] == ""))
                                    tt += Convert.ToDecimal(dr["ThanhTien"]);
                                dr["ThanhTien"] = (tt).ToString("###,###,###,###.##");
                                if (dsTP_PT.Tables[0].Rows[i]["PhuThu"].ToString() != "")
                                {
                                    Decimal phuThu = Convert.ToDecimal(dsTP_PT.Tables[0].Rows[i]["PhuThu"].ToString());
                                    if (phuThu != 0)
                                    {
                                        if (!(dr["ThanhTien"] is DBNull || dr["ThanhTien"] == ""))
                                            phuThu += Convert.ToDecimal(dr["ThanhTien"]);
                                        dr["ThanhTien"] = (phuThu).ToString("###,###,###,###.##");
                                    }
                                }
                            }
                        }
                        dtChartData.Rows.Add(dr);
                        ////////////////////////////

                    }
                    if (dtChartData == null || dtChartData.Rows.Count == 0)
                    {
                        MessageBox.Show("Dữ liệu rỗng! Xin vui lòng chọn lại dữ liệu", "Thông báo",
                            MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                    else
                    {
                        frmChartView ch = new frmChartView(dtChartData, "ByMonth");
                        ch.ShowDialog();
                    }
                }
            }
        }
Esempio n. 18
0
        private bool updateBillDisplay(int IDHoadon)
        {
            //this function will get all infomation about the receipt by its ID
            //txtBilltotal.Text = "0";
            //txtHourMoney.Text = "0";
            //txtProductMoney.Text = "0";
            //get Bill infomation
            if (IDHoadon < 0)
            {
                lbStatus.Text = "Lựa chọn Mã hóa đơn không hợp lệ";
                cboEmployee.SelectedValue = 0;
                txtBilltotal.Text = "0";
                txtProductMoney.Text = "0";
                numExtra.Value = 0;
                numTax.Value = 0;
                numDeposit.Value = 0;
                txtReturnMoney.Text = "0";
                gridBillProduct.DataSource = null;
                txtReturnMoney.Text = "0";
                lbGioMP.Text = "00:00";
                lbGioKT.Text = "00:00";
                return false;
            }
            iCurrentReceiptID = IDHoadon;
            int timeout = 0;
            DataSet dsBill = new DataAccess().getHoadonxuatByIDHoadonXuat(IDHoadon);
            for (timeout = 0; timeout < 20; timeout++)
            {
                if (dsBill.Tables[0].Rows.Count <= 0)
                {
                    System.Threading.Thread.Sleep(500);
                    dsBill = new DataAccess().getLastHoadonxuatByIDPhong(IDHoadon);
                }
                else
                    break;
            }
            if (timeout >= 9)
            {
                MessageBox.Show("Không có Hóa đơn mã số " + IDHoadon.ToString(), "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return false;
            }
            //check the status of this Bill
            // 0 : is open //1: is close //2: could not modify
            int status = Convert.ToInt32(dsBill.Tables[0].Rows[0]["Trangthai"]);
            //get current Bill
            currentReceipt.IDNhanvien = Convert.ToInt32(dsBill.Tables[0].Rows[0]["IDNhanvien"]);
            currentReceipt.IDPhong = -1;
            currentReceipt.Giam = Convert.ToInt32(dsBill.Tables[0].Rows[0]["Giam"]);
            currentReceipt.Thue = Convert.ToInt32(dsBill.Tables[0].Rows[0]["Thue"]);
            currentReceipt.Phuthu = Convert.ToInt32(dsBill.Tables[0].Rows[0]["Phuthu"]);
            currentReceipt.IDGiaLoaiphong = -1;
            currentReceipt.Ngayxuat = Convert.ToDateTime(dsBill.Tables[0].Rows[0]["Ngayxuat"]);
            currentReceipt.GioBD = Convert.ToDateTime(dsBill.Tables[0].Rows[0]["GioBD"]);
            currentReceipt.GioKT = Convert.ToDateTime(dsBill.Tables[0].Rows[0]["GioKT"]);
            currentReceipt.Tratruoc = Convert.ToInt32(dsBill.Tables[0].Rows[0]["Tratruoc"]);
            currentReceipt.Ghichu = Convert.ToString(dsBill.Tables[0].Rows[0]["Ghichu"]);
            currentReceipt.Trangthai = Convert.ToInt32(dsBill.Tables[0].Rows[0]["Trangthai"]);
            currentReceipt.IDHoadonXuat = IDHoadon;
            currentReceipt.IDNhanvien = Convert.ToInt32(dsBill.Tables[0].Rows[0]["IDNhanvien"]);
            currentReceipt.Nhacnho = Convert.ToBoolean(dsBill.Tables[0].Rows[0]["Nhacnho"]);
            currentReceipt.IDKhachhang = Convert.ToInt32(dsBill.Tables[0].Rows[0]["IDKhachhang"]);

            if (status == 0)
            {
                //new bill
                cboEmployee.SelectedValue = currentReceipt.IDNhanvien;
                cboCustomer.SelectedValue = currentReceipt.IDKhachhang;
                numTax.Value = currentReceipt.Thue;
                numExtra.Value = currentReceipt.Phuthu;
                numDeposit.Value = currentReceipt.Tratruoc;

                string strtime = "Ngày " + Convert.ToDateTime(dsBill.Tables[0].Rows[0]["Ngayxuat"]).ToShortDateString();
                strtime = strtime + " - Bắt đầu lúc " + Convert.ToDateTime(dsBill.Tables[0].Rows[0]["GioBD"]).ToShortTimeString();
                lbStatus.Text = strtime;
                lbGioMP.Text = currentReceipt.GioBD.ToString("hh:mm");
                lbGioKT.Text = DateTime.Now.TimeOfDay.Hours.ToString("00") + ":" + DateTime.Now.TimeOfDay.Minutes.ToString("00");
                currentReceipt.GioKT = DateTime.Now;
                if (new DataAccess().updateHoadonxuat(currentReceipt) == false)
                {
                    MessageBox.Show("Lỗi cơ sở dữ liệu!", "Lỗi");
                }
            }
            else
            {
                //old bill

                cboEmployee.SelectedValue = currentReceipt.IDNhanvien;
                cboCustomer.SelectedValue = currentReceipt.IDKhachhang;
                numTax.Value = currentReceipt.Thue;
                numExtra.Value = currentReceipt.Phuthu;

                numDeposit.Value = currentReceipt.Tratruoc;

                string strtime = "Ngày " + Convert.ToDateTime(dsBill.Tables[0].Rows[0]["Ngayxuat"]).ToShortDateString();
                strtime = strtime + " - Bắt đầu: " + Convert.ToDateTime(dsBill.Tables[0].Rows[0]["GioBD"]).ToShortTimeString();
                strtime = strtime + " - Kết thúc: " + Convert.ToDateTime(dsBill.Tables[0].Rows[0]["GioKT"]).ToShortTimeString();
                lbStatus.Text = strtime;
                lbGioMP.Text = currentReceipt.GioBD.ToString("hh:mm");
                lbGioKT.Text = currentReceipt.GioKT.ToString("hh:mm");

            }
            //get all product with this bill
            DataSet dsBillProduct = new DataAccess().getChitietHDXuatByID(IDHoadon);
            gridBillProduct.DataSource = dsBillProduct.Tables[0];
            //calculate money
            int productMoney = 0;
            int i;
            for (i = 0; i < dsBillProduct.Tables[0].Rows.Count; i++)
                productMoney = productMoney + Convert.ToInt32(dsBillProduct.Tables[0].Rows[i]["Thanhtien"]);
            txtProductMoney.Text = productMoney.ToString("###,###,###,##0");
            int totalBill = 0;
            totalBill = productMoney + Convert.ToInt32(numExtra.Value);
            totalBill = Convert.ToInt32(totalBill + totalBill * numTax.Value / 100);
            txtBilltotal.Text = totalBill.ToString("###,###,###,##0");
            txtReturnMoney.Text = (totalBill - Convert.ToInt32(dsBill.Tables[0].Rows[0]["Tratruoc"])).ToString("###,###,##0");
            return true;
        }
Esempio n. 19
0
        private void btnViewChart_Click(object sender, EventArgs e)
        {
            if (rdDate.Checked)
            {//By Date
                if (dtSelectedProduct == null || dtSelectedProduct.Rows.Count <= 0)
                {
                    MessageBox.Show("Bạn chưa chọn sản phẩm cần khảo sát. Vui lòng chọn một vài sản phẩm cần " +
                        "vẽ biều đồ ở khung loại sản phẩm!",
                        "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
                DateTime dtFrom = dtFromByDate.Value;
                DateTime dtTo = dtToByDate.Value;
                if (DateTime.Compare(dtFrom, dtTo) > 0)
                {
                    MessageBox.Show("Ngày bắt đầu lớn hơn ngày kết thúc. Vui lòng chọn lại thông tin ngày tháng",
                        "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
                else
                {
                    DataAccess da = new DataAccess();
                    TimeSpan ts = dtTo - dtFrom;
                    string stridProduct = "";
                    int i = 0, j = 0;
                    DateTime dtCurrent = dtFrom;
                    if (dtChartData != null && dtChartData.Rows.Count > 0)
                        dtChartData.Rows.Clear();
                    if (dtChartData != null && dtChartData.Columns.Count > 0)
                        dtChartData.Columns.Clear();
                    if (listofProductName != null)
                        listofProductName = null;
                    if (listofProductID != null)
                        listofProductID = null;
                    listofProductName = new string[dtSelectedProduct.Rows.Count];
                    listofProductID = new int[dtSelectedProduct.Rows.Count];
                    DataColumn dcdt = new DataColumn("Ngayxuat", Type.GetType("System.String"));
                    dtChartData.Columns.Add(dcdt);
                    for (i = 0; i < dtSelectedProduct.Rows.Count; i++)
                    {
                        DataColumn dc = new DataColumn(Convert.ToString(dtSelectedProduct.Rows[i]["TenSanPham"]),
                            Type.GetType("System.String"));
                        dtChartData.Columns.Add(dc);
                        listofProductName[i] = Convert.ToString(dtSelectedProduct.Rows[i]["TenSanPham"]);
                        listofProductID[i] = Convert.ToInt32(dtSelectedProduct.Rows[i]["IDSanPham"]);
                        if(i == 0){
                            stridProduct += " and (";
                            stridProduct += " SanPham.IDSanPham = " + Convert.ToString(dtSelectedProduct.Rows[i]["IDSanPham"]);
                        }else{
                            stridProduct += " or " + " SanPham.IDSanPham = " + Convert.ToString(dtSelectedProduct.Rows[i]["IDSanPham"]);
                        }
                        if(i == dtSelectedProduct.Rows.Count -1){
                            stridProduct += ")";
                        }

                    }
                    string strWheredate = "";
                    string strQuery = "";
                    for (j = 0; j <= ts.Days; j++)
                    {
                        dtCurrent = dtFrom.AddDays(j);
                        //Get the number of product sold in that day.
                        strWheredate = "And Year(Ngayxuat) = " + dtCurrent.Year +
                            " and Month(Ngayxuat) = " + dtCurrent.Month +
                                " and Day(Ngayxuat) = " + dtCurrent.Day + " ";
                        strQuery = "Select SanPham.IDSanPham, SanPham.TenSanPham, SanPham.DVT, " +
                            "Hoadonxuat.Ngayxuat, Sum(soluong) as TongSoluong " +
                            "From SanPham, ChitietHDXuat, Hoadonxuat " +
                            "Where SanPham.IDSanPham = ChitietHDXuat.IDSanPham and " +
                            "ChitietHDXuat.IDHoadonXuat = Hoadonxuat.IDHoadonXuat " +
                            stridProduct + strWheredate +
                            "Group by SanPham.IDSanPham, SanPham.TenSanPham, " +
                            "SanPham.DVT, Hoadonxuat.Ngayxuat " +
                            "ORDER BY Hoadonxuat.Ngayxuat";
                        DataSet dsTemp = da.getDataByQuery(strQuery);
                        DataRow dr = dtChartData.NewRow();
                        dr["Ngayxuat"] = dtCurrent.ToString("MM/dd/yyyy");
                        if (dsTemp != null)
                        {
                            for (i = 0; i < dsTemp.Tables[0].Rows.Count; i++)
                            {
                                string colName = Convert.ToString(dsTemp.Tables[0].Rows[i]["TenSanPham"]);
                                dr[colName] = Convert.ToString(dsTemp.Tables[0].Rows[i]["TongSoluong"]);
                            }
                            dtChartData.Rows.Add(dr);
                        }
                    }
                    if (dtChartData == null || dtChartData.Rows.Count == 0)
                    {
                        MessageBox.Show("Dữ liệu rỗng! Xin vui lòng chọn lại dữ liệu", "Thông báo",
                            MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                    else
                    {
                        frmChartView ch = new frmChartView(dtChartData, "ByDate", listofProductName);
                        ch.ShowDialog();
                    }
                }
            }
            else if (rdMonth.Checked)
            {//By Month
                if (dtSelectedProduct == null || dtSelectedProduct.Rows.Count <= 0)
                {
                    MessageBox.Show("Bạn chưa chọn sản phẩm cần khảo sát. Vui lòng chọn một vài sản phẩm cần " +
                        "vẽ biều đồ ở khung loại sản phẩm!",
                        "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
                if(cbMonthByMonth.Text == "" || cbToMonthByMonth.Text == "" ||
                    cbYearByMonth.Text == "" || cbToYearByMonth.Text == ""){
                    MessageBox.Show("Bạn chưa thông tin tháng năm. Vui lòng chọn tháng bắt đầu và tháng kết thúc ",
                        "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
                DateTime dtFrom = dtFromByDate.Value;
                DateTime dtTo = dtToByDate.Value;
                int startMonth = Convert.ToInt32(cbMonthByMonth.Text);
                int endMondth = Convert.ToInt32(cbToMonthByMonth.Text);
                int startYear = Convert.ToInt32(cbYearByMonth.Text);
                int endYear = Convert.ToInt32(cbToYearByMonth.Text);
                DateTime start = new DateTime(startYear, startMonth, 1);
                DateTime end = new DateTime(endYear, endMondth, 1);
                if (DateTime.Compare(start, end) > 0)
                {
                    MessageBox.Show("Ngày bắt đầu lớn hơn ngày kết thúc. Vui lòng chọn lại thông tin ngày tháng",
                        "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
                else
                {
                    DataAccess da = new DataAccess();
                    string stridProduct = "";
                    int i = 0, j = 0;
                    DateTime dtCurrent = start;
                    int diff = (endYear - startYear)*12 + (endMondth - startMonth);
                    if (dtChartData != null && dtChartData.Rows.Count > 0)
                        dtChartData.Rows.Clear();
                    if (dtChartData != null && dtChartData.Columns.Count > 0)
                        dtChartData.Columns.Clear();
                    if (listofProductName != null)
                        listofProductName = null;
                    if (listofProductID != null)
                        listofProductID = null;
                    listofProductName = new string[dtSelectedProduct.Rows.Count];
                    listofProductID = new int[dtSelectedProduct.Rows.Count];
                    DataColumn dcdt = new DataColumn("Ngayxuat", Type.GetType("System.String"));
                    dtChartData.Columns.Add(dcdt);
                    for (i = 0; i < dtSelectedProduct.Rows.Count; i++)
                    {
                        DataColumn dc = new DataColumn(Convert.ToString(dtSelectedProduct.Rows[i]["TenSanPham"]),
                            Type.GetType("System.String"));
                        dtChartData.Columns.Add(dc);
                        listofProductName[i] = Convert.ToString(dtSelectedProduct.Rows[i]["TenSanPham"]);
                        listofProductID[i] = Convert.ToInt32(dtSelectedProduct.Rows[i]["IDSanPham"]);
                        if (i == 0)
                        {
                            stridProduct += " and (";
                            stridProduct += " SanPham.IDSanPham = " + Convert.ToString(dtSelectedProduct.Rows[i]["IDSanPham"]);
                        }
                        else
                        {
                            stridProduct += " or " + " SanPham.IDSanPham = " + Convert.ToString(dtSelectedProduct.Rows[i]["IDSanPham"]);
                        }
                        if (i == dtSelectedProduct.Rows.Count - 1)
                        {
                            stridProduct += ")";
                        }

                    }
                    string strWheredate = "";
                    string strQuery = "";
                    for (j = 0; j <= diff; j++)
                    {
                        dtCurrent = start.AddMonths(j);
                        //Get the number of product sold in that day.
                        strWheredate = "And Year(Ngayxuat) = " + dtCurrent.Year +
                            " and Month(Ngayxuat) = " + dtCurrent.Month + " ";
                        strQuery = "Select SanPham.IDSanPham, SanPham.TenSanPham, SanPham.DVT, " +
                            "Hoadonxuat.Ngayxuat, Sum(soluong) as TongSoluong " +
                            "From SanPham, ChitietHDXuat, Hoadonxuat " +
                            "Where SanPham.IDSanPham = ChitietHDXuat.IDSanPham and " +
                            "ChitietHDXuat.IDHoadonXuat = Hoadonxuat.IDHoadonXuat " +
                            stridProduct + strWheredate +
                            "Group by SanPham.IDSanPham, SanPham.TenSanPham, " +
                            "SanPham.DVT, Hoadonxuat.Ngayxuat " +
                            "ORDER BY Hoadonxuat.Ngayxuat";
                        DataSet dsTemp = da.getDataByQuery(strQuery);
                        DataRow dr = dtChartData.NewRow();
                        dr["Ngayxuat"] = dtCurrent.ToString("MM/yyyy");
                        if (dsTemp != null)
                        {
                            for (i = 0; i < dsTemp.Tables[0].Rows.Count; i++)
                            {
                                string colName = Convert.ToString(dsTemp.Tables[0].Rows[i]["TenSanPham"]);
                                dr[colName] = Convert.ToString(dsTemp.Tables[0].Rows[i]["TongSoluong"]);
                            }
                            dtChartData.Rows.Add(dr);
                        }
                    }
                    if (dtChartData == null || dtChartData.Rows.Count == 0)
                    {
                        MessageBox.Show("Dữ liệu rỗng! Xin vui lòng chọn lại dữ liệu", "Thông báo",
                            MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                    else
                    {
                        frmChartView ch = new frmChartView(dtChartData, "ByMonth", listofProductName);
                        ch.ShowDialog();
                    }
                }
            }
        }
Esempio n. 20
0
 private void numTax_ValueChanged(object sender, EventArgs e)
 {
     if (iCurrentReceiptID > -1)
     {
         //check if cached bill is the same
         if (iCurrentReceiptID != currentReceipt.IDHoadonXuat)
             return;
         if ((currentReceipt.Trangthai > 0) && (Program.userLevel != Level.Admin))
         {
             MessageBox.Show("Liên hệ quản lý để thay đổi Hóa đơn này", "Cảnh báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
             return;
         }
         currentReceipt.Thue = Convert.ToInt32(numExtra.Value);
         //update DB
         bool res = new DataAccess().updateHoadonxuat(currentReceipt);
         if (!res)
         {
             MessageBox.Show("Không cập nhật được CSDL", "Lỗi CSDL", MessageBoxButtons.OK, MessageBoxIcon.Error);
             return;
         }
         updateBillDisplay(iCurrentReceiptID);
     }
 }
Esempio n. 21
0
        private void StartNewReceipt()
        {
            //open or close selected room
            //first search if selected room is available

               //in case of the room is available
            //ask to open room and create new receipt for this room
            if (MessageBox.Show("Bạn có muốn mở hóa đơn bán lẻ mới?", "Thông báo", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.Cancel)
                return;
            //get khuyen mai tang gio cua phong
            currentReceipt.Giam = 0;
            currentReceipt.GioBD = DateTime.Now;
            currentReceipt.GioKT = DateTime.Now;
            currentReceipt.Tratruoc = 0;
            currentReceipt.Nhacnho = false;
            currentReceipt.IDPhong = -1;
            currentReceipt.Ngayxuat = DateTime.Now.Date;
            currentReceipt.Phuthu = 0;
            currentReceipt.Thue = 0;
            currentReceipt.Trangthai = 0;
            currentReceipt.Thue = 0;
            currentReceipt.Phuthu = 0;
            currentReceipt.IDNhanvien = 0;
            currentReceipt.IDKhachhang = Convert.ToInt32(cboCustomer.SelectedValue);
            currentReceipt.Ghichu = "";

            int res = new DataAccess().insertHoadonxuat(currentReceipt);
            if (res > -1)
            {
                //wait for databa is update

                iCurrentReceiptID = res;

                //update Hoadon group display
                if (updateBillDisplay(res))
                {
                    updateReceiptGrid(res);

                }
                //btnStart.Image = Karaoke.Properties.Resources.Status_user_busy_icon1;
            }
            else
            {
                MessageBox.Show("Mở Hóa đơn mới không thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Stop);
            }
        }
Esempio n. 22
0
        private void gridViewBillProduct_CellValueChanging(object sender, DevExpress.XtraGrid.Views.Base.CellValueChangedEventArgs e)
        {
            if (e.RowHandle >= 0)
            {
                if ((currentReceipt.Trangthai < 1) || (Program.userLevel == Level.Admin))
                {
                    if (e.Column == colDeleteCTHD)
                    {
                        ////delete here
                        //get the number of avalable product with this bill
                        DataSet dsCTHD = new DataAccess().getChitietHDXuatByIDSanphamAndIDHoadon(Convert.ToInt32(gridViewBillProduct.GetRowCellValue(e.RowHandle, "IDSanpham")), iCurrentReceiptID);
                        int i;
                        int sum = 0;
                        for (i = 0; i < dsCTHD.Tables[0].Rows.Count; i++)
                        {
                            sum = sum + Convert.ToInt32(dsCTHD.Tables[0].Rows[i]["Soluong"]);
                        }
                        ChitietHDXuat obj = new ChitietHDXuat();
                        obj.Giam = Convert.ToInt32(gridViewBillProduct.GetRowCellValue(e.RowHandle, "Giam"));
                        obj.IDGiaxuat = Convert.ToInt32(gridViewBillProduct.GetRowCellValue(e.RowHandle, "IDGiaXuatSP"));
                        obj.IDHoadonXuat = Convert.ToInt32(gridViewBillProduct.GetRowCellValue(e.RowHandle, "IDHoadonXuat"));
                        obj.IDSanpham = Convert.ToInt32(gridViewBillProduct.GetRowCellValue(e.RowHandle, "IDSanpham"));
                        obj.Soluong = Convert.ToInt32(gridViewBillProduct.GetRowCellValue(e.RowHandle, "Soluong"));
                        obj.Bep = Convert.ToBoolean(gridViewBillProduct.GetRowCellValue(e.RowHandle, "Bep"));
                        if (sum <= 0)
                        {
                            MessageBox.Show("Hiện tại không còn sản phầm này trong hóa đơn", "Thông báo");
                            return;
                        }
                        frmReturnProduct rt = new frmReturnProduct(false,sum, Convert.ToString(gridViewBillProduct.GetRowCellValue(e.RowHandle, "TenSanPham")));
                        rt.ShowDialog();
                        int rtnum = rt.getReturnNum();
                        // bool directRet = rt.getDirectRet();
                        string text = rt.getText();
                        rt.Close();
                        if (rtnum <= 0) return;
                        obj.Soluong = -rtnum;
                        obj.Ghichu = text;
                        if (new DataAccess().insertChitietHDXuat(obj) < 0)
                            MessageBox.Show(this, "Trả sản phẩm không thành công", "Thông báo lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        else
                            updateBillDisplay(iCurrentReceiptID);

                    }

                }
                else
                {
                    MessageBox.Show(this, "Hóa đơn đã khóa sổ, không thay đổi được. Liên hệ quản lý để thay đổi", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                }

            }
        }
Esempio n. 23
0
 private void getAllSP()
 {
     DataSet ds = new DataAccess().getAllSanPhamAndIDGia();
     gridControlSanPham.DataSource = ds.Tables[0];
     gridViewSanPham.ExpandAllGroups();
 }
Esempio n. 24
0
        private void AddSP(int num)
        {
            //add a quantity of a product to current bill
            //check if the parameters are legal

            if (gridViewSanPham.FocusedRowHandle >= 0)
            {
                //list all products by ID
                int ID = Convert.ToInt32(gridViewSanPham.GetRowCellValue(gridViewSanPham.FocusedRowHandle, "IDSanPham"));
                iCurrentProductID = ID;
                int IDLoaiSP = Convert.ToInt32(gridViewSanPham.GetRowCellValue(gridViewSanPham.FocusedRowHandle, "IDNhomSP"));
                //DataSet prdPrice = new DataAccess().getGiaXuatSPByIDSanPham(ID);
                //if ((prdPrice != null) && (prdPrice.Tables[0].Rows.Count > 0))
                //{
                //txtPrice.Text = prdPrice.Tables[0].Rows[0][1].ToString();
                if (iCurrentReceiptID >= 0)
                {
                    if (currentReceipt.Trangthai > 1)
                    {
                        MessageBox.Show("Hóa đơn này đã đóng, không được thay đổi", "Thông báo");
                        return;
                    }
                    else if ((currentReceipt.Trangthai > 0) && (Program.userLevel != Level.Admin))
                    {
                        MessageBox.Show("Đăng nhập với quyền Quản lý để thay đổi", "Thông báo");
                        return;
                    }
                    if(currentReceipt.Trangthai > 0)
                    {
                        if (MessageBox.Show("Bạn có muốn thêm sản phẩm vào hóa đơn đã đóng", "Cảnh báo", MessageBoxButtons.YesNo) == DialogResult.No)
                            return;
                    }
                    //get khuyen mai with this product ID
                    DataSet ds = new DataAccess().getKhuyenmaiByIDLoaiSP(IDLoaiSP, DateTime.Now.Date);
                    //if (ds == null)
                    //    return;
                    //if (ds.Tables[0].Rows.Count == 0)
                    //{
                    //get the number of added product
                    frmReturnProduct rt = new frmReturnProduct(true, 0, Convert.ToString(gridViewSanPham.GetRowCellValue(gridViewSanPham.FocusedRowHandle, "TenSanPham")));
                    rt.ShowDialog();
                    int rtnum = rt.getReturnNum();
                    // bool directRet = rt.getDirectRet();
                    string text = rt.getText();
                    rt.Close();
                    if (rtnum <= 0) return;
                    ChitietHDXuat obj = new ChitietHDXuat();
                    obj.IDHoadonXuat = iCurrentReceiptID;
                    obj.IDSanpham = iCurrentProductID;
                    obj.IDGiaxuat = Convert.ToInt32(gridViewSanPham.GetRowCellValue(gridViewSanPham.FocusedRowHandle, "IDGiaXuatSP"));
                    obj.Soluong = rtnum;
                    if (ds != null)
                    {
                        try
                        {
                            obj.Giam = Convert.ToInt32(ds.Tables[0].Rows[0]["Giam"]);
                        }
                        catch (Exception ex)
                        {
                            obj.Giam = 0;
                        }
                    }
                    else
                        obj.Giam = 0;
                    obj.Bep = false;
                    int res = new DataAccess().insertChitietHDXuat(obj);
                    if (res < 0)
                    {
                        MessageBox.Show("Không thêm sản phẩm " + gridViewSanPham.GetRowCellValue(gridViewSanPham.FocusedRowHandle, "TenSanPham") + " vào hóa đơn hiện tại", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        return;
                    }

                    updateBillDisplay(iCurrentReceiptID);
                    int i;
                    for (i = 0; i < gridViewBillProduct.RowCount; i++)
                    {
                        if (Convert.ToInt32(gridViewBillProduct.GetRowCellValue(i, "IDSanpham")) == iCurrentProductID)
                            break;
                    }
                    gridViewBillProduct.Focus();
                    gridViewBillProduct.FocusedRowHandle = i;
                    gridViewBillProduct.FocusedColumn = colBillNum;

                }
            }
        }
Esempio n. 25
0
 private void frmHoaDonNhapDetail_Load(object sender, EventArgs e)
 {
     //Load Data
     DataSet ds = new DataAccess().getAllChiTietHoaDonNhapByIDHoaDonNhap(IDHoaDonNhap);
     gridControlChiTietHoaDonNhap.DataSource = ds.Tables[0];
 }
Esempio n. 26
0
 private void frmChart_Load(object sender, EventArgs e)
 {
     DataSet ds = new DataAccess().getAllSanPham();
     gridControlSanPham.DataSource = ds.Tables[0];
     DataSet ds1 = new DataAccess().getAllPhong();
     gridRoom.DataSource = ds1.Tables[0];
 }
Esempio n. 27
0
        private void InitData()
        {
            DataSet ds = new DataAccess().getAllWarningOpenningHoadonxuat();
            if (ds == null) return;
            if (ds.Tables[0].Rows.Count <= 0) return;
            int i;
            warnReceipt.Clear();
            for (i = 0; i < ds.Tables[0].Rows.Count;i++ )
            {
                DataRow aRow = warnReceipt.NewRow();

                aRow["IDPhong"] = ds.Tables[0].Rows[i]["IDPhong"];
                aRow["IDHoadonXuat"] = ds.Tables[0].Rows[i]["IDHoadonXuat"];
                aRow["TenPhong"] = ds.Tables[0].Rows[i]["TenPhong"];
                aRow["Hoadon"] = ds.Tables[0].Rows[i]["TenHoadon"];
                aRow["Trangthai"] = ds.Tables[0].Rows[i]["Trangthai"];
                aRow["Dongphong"] = true;
                aRow["Taomoi"] = true;
                if (Convert.ToInt32(ds.Tables[0].Rows[i]["Trangthai"]) == 3) //printed receipt
                    aRow["Tinhtrang"] = "Đã in HĐ";
                if (Convert.ToInt32(ds.Tables[0].Rows[i]["Trangthai"]) == 4) //paid receipt
                    aRow["Tinhtrang"] = "Đã thanh toán";
                else
                    aRow["Tinhtrang"] = "Chưa in HĐ";
                if (Convert.ToDateTime(ds.Tables[0].Rows[i]["GioKT"]) <= DateTime.Now)
                    aRow["TgConlai"] = 0;
                else
                {
                    TimeSpan ts = Convert.ToDateTime(ds.Tables[0].Rows[i]["GioKT"]).Subtract(DateTime.Now);
                    aRow["TgConlai"] = ts.Hours*60 + ts.Minutes;
                }
                if(Convert.ToInt32(aRow["TgConlai"]) < 10)
                    warnReceipt.Rows.Add(aRow);
               }
            gridWarning.DataSource = warnReceipt;
        }
Esempio n. 28
0
 private void getAllKhachhang()
 {
     DataSet ds = new DataAccess().getAllKhachhang();
     cboCustomer.DataSource = ds.Tables[0];
     cboCustomer.DisplayMember = "Ten";
     cboCustomer.ValueMember = "IDKhachhang";
 }
Esempio n. 29
0
 private void cboEmployee_SelectedIndexChanged(object sender, EventArgs e)
 {
     if (iCurrentReceiptID > -1)
     {
         //check if cached bill is the same
         if (iCurrentReceiptID != currentReceipt.IDHoadonXuat)
             return;
         if (currentReceipt.Trangthai > 1)
             return;
         currentReceipt.IDNhanvien = Convert.ToInt32(cboEmployee.SelectedValue);
         //update DB
         bool res = new DataAccess().updateHoadonxuat(currentReceipt);
         if (!res)
         {
             MessageBox.Show("Không cập nhật được CSDL", "Lỗi CSDL", MessageBoxButtons.OK, MessageBoxIcon.Error);
             return;
         }
     }
 }
Esempio n. 30
0
 private void getAllNhanvien()
 {
     DataSet ds = new DataAccess().getAllIDandNameNhanvien();
     cboEmployee.DataSource = ds.Tables[0];
     cboEmployee.DisplayMember = "Ten";
     cboEmployee.ValueMember = "IDNhanvien";
 }