Exemple #1
0
        private void BtnThem_Clicked(object sender, RoutedEventArgs e)
        {
            double soluong = VND.ConvertToNumber(SoLuong.Text);
            double giatien = VND.ConvertToNumber(GiaTien.Text);
            string tenhang = myAutoTenHang.autoTextBox.Text;

            if (tenhang == null || tenhang == "")
            {
                tenhang = "";
            }
            dataGrid1.Items.Add(new Data
            {
                A       = dataGrid1.Items.Count + 1,
                B       = tenhang,
                C       = soluong.ToString(),
                D       = VND.ConvertToString(giatien),
                E       = VND.ConvertToString(soluong * giatien),
                Barcode = ""
            });
            dataGrid1.ScrollIntoView(dataGrid1.Items[dataGrid1.Items.Count - 1]);

            //update tiendu
            TONGSOTIEN += soluong * giatien;
            double tientra  = VND.ConvertToNumber(TienKhachTra.Text);
            double result   = tientra - TONGSOTIEN;
            string negative = "";

            if (result < 0)
            {
                negative = "-";
            }
            TienDu.Text   = negative + VND.ConvertToString(result);
            TongTien.Text = VND.ConvertToString(TONGSOTIEN);
        }
Exemple #2
0
        private void myAutoTenHang_MouseUp(object sender, MouseButtonEventArgs e)
        {
            IsQuickSelecting = true;
            string findString = myAutoTenHang.autoTextBox.Text;
            bool   found      = false;

            for (int i = 0; i < DataExcel.Rows.Count; i++)
            {
                if (DataExcel.Rows[i][1].ToString() == findString) //tenhang columns
                {
                    GiaTien.Text = VND.ConvertToString(DataExcel.Rows[i][2].ToString());
                    BarCode.Text = DataExcel.Rows[i][3].ToString();
                    found        = true;

                    dgDuLieu.ScrollIntoView(dgDuLieu.Items[i]);
                    dgDuLieu.SelectedIndex = i;

                    break;
                }
            }
            if (!found)
            {
                GiaTien.Text = "";
                BarCode.Text = "";
            }
            IsQuickSelecting = false;
        }
Exemple #3
0
        private void BtXoa_Clicked(object sender, RoutedEventArgs e)
        {
            object item = dataGrid1.SelectedItem;

            if (item == null)
            {
                MessageBox.Show("Không có sản phẩm nào bị xoá. Vui lòng chọn một sản phẩm.", "Thông báo", MessageBoxButton.OK, MessageBoxImage.Warning);
                return;
            }
            int selectedIndex = dataGrid1.SelectedIndex;

            if (selectedIndex >= dataGrid1.Items.Count - 1)
            {
                selectedIndex = dataGrid1.Items.Count - 2;
                //MessageBox.Show(selectedIndex.ToString());
            }

            TONGSOTIEN   -= VND.ConvertToNumber((dataGrid1.SelectedCells[4].Column.GetCellContent(item) as TextBlock).Text);
            TongTien.Text = VND.ConvertToString(TONGSOTIEN);

            double tientra  = VND.ConvertToNumber(TienKhachTra.Text);
            double result   = tientra - TONGSOTIEN;
            string negative = "";

            if (result < 0)
            {
                negative = "-";
            }
            TienDu.Text = negative + VND.ConvertToString(result);

            dataGrid1.Items.Remove(item);
            dataGrid1.SelectedIndex = selectedIndex;
        }
Exemple #4
0
        private void ButtonPrint_MouseUp(object sender, RoutedEventArgs e)
        {
            IsExporting = true;
            //MessageBox.Show("row.count = " + dataGrid1.Items.Count + "\ncol.count = " + dataGrid1.Columns.Count);
            if (dataGrid1.Items.Count <= 0)
            {
                MessageBox.Show("Bạn chưa nhập sản phẩm nào. Vui lòng nhập vào ít nhất một sản phẩm.", "Thông báo");
                return;
            }
            string[] result   = new string[dataGrid1.Items.Count];
            int      totalrow = dataGrid1.Items.Count;
            int      totalcol = dataGrid1.Columns.Count;
            string   dataRow  = "";

            for (int irow = 0; irow < totalrow; irow++)
            {
                dataGrid1.SelectedIndex = irow;
                dataGrid1.ScrollIntoView(dataGrid1.Items[irow]);

                dataRow      = Convert.ToString(irow + 1) + "|"; //STT
                dataRow     += getDataGrid(irow, 1) + "|";       //Ten san pham
                dataRow     += getDataGrid(irow, 2) + "|";       //So luong
                dataRow     += getDataGrid(irow, 4) + "|";       //Thanh tien
                result[irow] = dataRow;
            }

            DanhSachHang = result; //=> Collect all DataGrid items before call printpage windows
            DonHangSo    = donhangso.Text;
            TongSoTien   = VND.ConvertToString(TONGSOTIEN);
            TienKhachDua = VND.ConvertToString(TienKhachTra.Text);
            TienConDu    = (TienDu.Text.Substring(0, 1) == "-" ? "-" : "") + VND.ConvertToString(TienDu.Text);
            NgayBan      = time.Text;

            Statistics.Add(donhangso.Text, TONGSOTIEN.ToString());

            if (((Button)sender).Name == "ButtonPrintPreview")
            {
                IsPrintPreview = true;
            }
            else
            {
                IsPrintPreview = false;
            }
            //myAutoTenHang.autoTextBox.Text

            Window page = new WindowPrintPage();

            page.Show();

            IsExporting = false;
        }
Exemple #5
0
        private void dataGrid1_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (IsExporting)
            {
                return;
            }
            object item = dataGrid1.SelectedItem;

            if (item != null)
            {
                myAutoTenHang.autoTextBox.Text = (dataGrid1.SelectedCells[1].Column.GetCellContent(item) as TextBlock).Text;
                SoLuong.Text = (dataGrid1.SelectedCells[2].Column.GetCellContent(item) as TextBlock).Text;
                string giatien = (dataGrid1.SelectedCells[3].Column.GetCellContent(item) as TextBlock).Text;
                GiaTien.Text = VND.ConvertToNumber(giatien).ToString();
            }
        }
Exemple #6
0
        private void dgDuLieu_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (IsQuickSelecting)
            {
                return;
            }
            object item = dgDuLieu.SelectedItem;

            if (item == null)
            {
                return;
            }
            myAutoTenHang.autoTextBox.Text = (dgDuLieu.SelectedCells[1].Column.GetCellContent(item) as TextBlock).Text;
            GiaTien.Text = VND.ConvertToString((dgDuLieu.SelectedCells[2].Column.GetCellContent(item) as TextBlock).Text);
            BarCode.Text = (dgDuLieu.SelectedCells[3].Column.GetCellContent(item) as TextBlock).Text;
        }
Exemple #7
0
        private void TienKhachTra_KeyUp(object sender, KeyEventArgs e)
        {
            double tientra  = VND.ConvertToNumber(TienKhachTra.Text);
            double result   = tientra - TONGSOTIEN;
            string negative = "";

            if (result < 0)
            {
                negative = "-";
            }
            TienDu.Text = negative + VND.ConvertToString(result);

            if (e.Key == Key.Enter)
            {
                TienKhachTra.Text = VND.ConvertToString(TienKhachTra.Text);
                ButtonPrint.Focus();
            }
        }
Exemple #8
0
        private void QueryData_dgDuLieu(string sFile)
        {
            while (dgDuLieu.Items.Count != 0)
            {
                dgDuLieu.Items.RemoveAt(0);
            }
            DataExcel.Clear();
            DataExcel = ImportSheet(sFile);
            int count = DataExcel.Rows.Count;

            for (int i = 0; i < count; i++)
            {
                dgDuLieu.Items.Add(new Data {
                    A = i + 1,
                    B = DataExcel.Rows[i][1].ToString(),
                    C = VND.ConvertToString(DataExcel.Rows[i][2].ToString()),
                    D = DataExcel.Rows[i][3].ToString()
                });
            }
        }
Exemple #9
0
        private void OnKeyDownHandler(object sender, KeyEventArgs e)
        {
            if (e.Key != Key.Enter)
            {
                return;
            }

            bool found = false;

            for (int i = 0; i < DataExcel.Rows.Count; i++)
            {
                string BarCode = DataExcel.Rows[i][3].ToString();
                if (BarCode == barcode.Text)
                {
                    string tenhang = DataExcel.Rows[i][1].ToString();
                    string giatien = DataExcel.Rows[i][2].ToString();
                    dataGrid1.Items.Add(new Data
                    {
                        A       = dataGrid1.Items.Count + 1,
                        B       = tenhang,
                        C       = "1",
                        D       = VND.ConvertToString(giatien),
                        E       = VND.ConvertToString(giatien),
                        Barcode = BarCode
                    });
                    TONGSOTIEN   += VND.ConvertToNumber(giatien);
                    TongTien.Text = VND.ConvertToString(TONGSOTIEN);

                    dataGrid1.ScrollIntoView(dataGrid1.Items[dataGrid1.Items.Count - 1]);

                    found = true;
                    break;
                }
            }
            barcode.SelectAll();
            barcode.Focus();
            if (!found)
            {
                MessageBox.Show("Không tìm thấy mã vạch: \n\"" + barcode.Text + "\"\n\nVui lòng cập nhật cơ sở dữ liệu để thanh toán sản phẩm này.", "Thông báo");
            }
        }
Exemple #10
0
        private void CapNhatGia()
        {
            int index = dgDuLieu.SelectedIndex;

            if (index < 0)
            {
                MessageBox.Show("Không tìm thấy sản phẩm nào để điều chỉnh. Vui lòng chọn một sản phẩm để điều chỉnh giá.", "Văn Đức > Thông báo", MessageBoxButton.OK, MessageBoxImage.Warning);
                return;
            }

            string tenhang = myAutoTenHang.autoTextBox.Text;
            string giaban  = VND.ConvertToNumber(GiaTien.Text).ToString();
            string barcode = BarCode.Text;

            //Save to Excel file

            if (index >= 0)
            {
                DataExcel.Rows[index][1] = tenhang;
                DataExcel.Rows[index][2] = giaban;
                DataExcel.Rows[index][3] = barcode;
                using (XLWorkbook wb = new XLWorkbook())
                {
                    wb.Worksheets.Add(DataExcel, "HangHoa");
                    wb.SaveAs(DataBaseFile);
                    wb.Dispose();
                }
                object item = dgDuLieu.SelectedItem;

                (dgDuLieu.SelectedCells[1].Column.GetCellContent(item) as TextBlock).Text = tenhang;
                (dgDuLieu.SelectedCells[2].Column.GetCellContent(item) as TextBlock).Text = VND.ConvertToString(giaban);
                (dgDuLieu.SelectedCells[3].Column.GetCellContent(item) as TextBlock).Text = barcode;

                GiaTien.Text = VND.ConvertToString(giaban);
                MessageBox.Show("Đã lưu vào cơ sở dữ liệu của hệ thống. ", "Thông báo", MessageBoxButton.OK, MessageBoxImage.Information);
            }
        }
Exemple #11
0
 private void TienKhachTra_LostFocus(object sender, RoutedEventArgs e)
 {
     TienKhachTra.Text = VND.ConvertToString(TienKhachTra.Text);
 }
Exemple #12
0
        private void BtnSua_Clicked(object sender, RoutedEventArgs e)
        {
            if (IsExporting)
            {
                return;
            }
            object item = dataGrid1.SelectedItem;

            if (item == null)
            {
                MessageBox.Show("Không tìm thấy sản phẩm nào để điều chỉnh. Vui lòng chọn một sản phẩm để điều chỉnh giá.", "Văn Đức > Thông báo", MessageBoxButton.OK, MessageBoxImage.Warning);
                return;
            }


            int    soluong   = Convert.ToInt32(SoLuong.Text);
            double giaban    = VND.ConvertToNumber(GiaTien.Text);
            double thanhtien = giaban * soluong;

            TONGSOTIEN -= VND.ConvertToNumber((dataGrid1.SelectedCells[4].Column.GetCellContent(item) as TextBlock).Text);
            TONGSOTIEN += thanhtien;

            // show message for user
            string [] arr = new string[4];
            arr[0] = (dataGrid1.SelectedCells[1].Column.GetCellContent(item) as TextBlock).Text;
            arr[1] = (dataGrid1.SelectedCells[2].Column.GetCellContent(item) as TextBlock).Text;
            arr[2] = (dataGrid1.SelectedCells[3].Column.GetCellContent(item) as TextBlock).Text;
            arr[3] = (dataGrid1.SelectedCells[4].Column.GetCellContent(item) as TextBlock).Text;
            string[] ARR = new string[4];
            ARR[0] = myAutoTenHang.autoTextBox.Text;
            ARR[1] = SoLuong.Text;
            ARR[2] = VND.ConvertToString(giaban);
            ARR[3] = VND.ConvertToString(thanhtien);

            //update control
            (dataGrid1.SelectedCells[1].Column.GetCellContent(item) as TextBlock).Text = ARR[0];
            (dataGrid1.SelectedCells[2].Column.GetCellContent(item) as TextBlock).Text = ARR[1];
            (dataGrid1.SelectedCells[3].Column.GetCellContent(item) as TextBlock).Text = ARR[2];
            (dataGrid1.SelectedCells[4].Column.GetCellContent(item) as TextBlock).Text = ARR[3];

            //update tong so tien
            TongTien.Text = VND.ConvertToString(TONGSOTIEN);

            //update tien du
            double tientra  = VND.ConvertToNumber(TienKhachTra.Text);
            double result   = tientra - TONGSOTIEN;
            string negative = "";

            if (result < 0)
            {
                negative = "-";
            }
            TienDu.Text = negative + VND.ConvertToString(result);

            MessageBox.Show("Đã điều chỉnh xong!\n\n\n" +
                            "Tên hàng: " + arr[0] + " => " + ARR[0] + "\n" +
                            "Số lượng: " + arr[1] + " => " + ARR[1] + "\n" +
                            "Giá bán: " + arr[2] + " => " + ARR[2] + "\n" +
                            "Thành tiền: " + arr[3] + " => " + ARR[3] + "\n"
                            , "Thông báo", MessageBoxButton.OK, MessageBoxImage.Information);
        }
Exemple #13
0
        private void InputBox_KeyUp(object sender, KeyEventArgs e)
        {
            if (e.Key != Key.Enter)
            {
                return;
            }
            object item = dataGrid1.SelectedItem;

            if (item == null)
            {
                MessageBox.Show("Không tìm thấy sản phẩm nào để điều chỉnh. Vui lòng chọn một sản phẩm để điều chỉnh giá.", "Văn Đức > Thông báo");
                return;
            }

            switch (((TextBox)sender).Name)
            {
            case "TenHang":
                (dataGrid1.SelectedCells[1].Column.GetCellContent(item) as TextBlock).Text = myAutoTenHang.autoTextBox.Text;
                break;

            case "SoLuong":
                double soluong   = VND.ConvertToNumber(SoLuong.Text);
                double giatien   = VND.ConvertToNumber((dataGrid1.SelectedCells[3].Column.GetCellContent(item) as TextBlock).Text);
                double thanhtien = soluong * giatien;

                //update tong so tien
                TONGSOTIEN   -= VND.ConvertToNumber((dataGrid1.SelectedCells[4].Column.GetCellContent(item) as TextBlock).Text);
                TONGSOTIEN   += thanhtien;
                TongTien.Text = VND.ConvertToString(TONGSOTIEN);

                //update soluong + thanh tien
                (dataGrid1.SelectedCells[2].Column.GetCellContent(item) as TextBlock).Text = SoLuong.Text;
                (dataGrid1.SelectedCells[4].Column.GetCellContent(item) as TextBlock).Text = VND.ConvertToString(thanhtien);

                //update tien du
                double tientra  = VND.ConvertToNumber(TienKhachTra.Text);
                double result   = tientra - TONGSOTIEN;
                string negative = "";
                if (result < 0)
                {
                    negative = "-";
                }
                TienDu.Text = negative + VND.ConvertToString(result);

                break;

            case "GiaTien":
                double soluong2   = VND.ConvertToNumber((dataGrid1.SelectedCells[2].Column.GetCellContent(item) as TextBlock).Text);
                double giatien2   = VND.ConvertToNumber(GiaTien.Text);
                double thanhtien2 = soluong2 * giatien2;

                //update tong so tien
                TONGSOTIEN   -= VND.ConvertToNumber((dataGrid1.SelectedCells[4].Column.GetCellContent(item) as TextBlock).Text);
                TONGSOTIEN   += thanhtien2;
                TongTien.Text = VND.ConvertToString(TONGSOTIEN);

                //update giatien + thanh tien
                (dataGrid1.SelectedCells[3].Column.GetCellContent(item) as TextBlock).Text = VND.ConvertToString(giatien2);
                (dataGrid1.SelectedCells[4].Column.GetCellContent(item) as TextBlock).Text = VND.ConvertToString(thanhtien2);

                //update tien du
                double tientra2  = VND.ConvertToNumber(TienKhachTra.Text);
                double result2   = tientra2 - TONGSOTIEN;
                string negative2 = "";
                if (result2 < 0)
                {
                    negative2 = "-";
                }
                TienDu.Text = negative2 + VND.ConvertToString(result2);

                //fix TextBox GiaTien
                GiaTien.Text = VND.ConvertToString(giatien2);
                break;
            }
        }
Exemple #14
0
 private void GiaTien_LostFocus(object sender, RoutedEventArgs e)
 {
     GiaTien.Text = VND.ConvertToString(GiaTien.Text);
 }