Ejemplo n.º 1
0
        private void LayBienSoXe()
        {
            Utilities.frmMain.lbThongBao.Text = "";

            Utilities.Cam1 = camTruoc.TakeSnapshot();
            Utilities.Cam2 = camSau.TakeSnapshot();
            Utilities.Cam3 = camToanCanh.TakeSnapshot();

            // nhan dien cam truoc
            Recognizer   recognizer = Recognizer.Instance;
            AlprPlateNet plate      = recognizer.Recognize(Utilities.Cam1);

            if (plate != null)
            {
                // hien thi len phieu can
                _frmPhieuCan.TxtBSX.Text = FormatBXS(plate.Characters);
            }
            else
            {
                // nhan dien cam sau - neu cam truoc ko dc
                plate = recognizer.Recognize(Utilities.Cam2);
                _frmPhieuCan.TxtBSX.Text = (plate == null) ? "Lấy biển số lỗi" : FormatBXS(plate.Characters);
            }

            // load cac thong tin liên quan nếu nhận diện được
            if (plate != null)
            {
                XeCtrl xeCtrl = new XeCtrl();
                XeInfo xeInfo = xeCtrl.LayThongTinXe(FormatBXS(plate.Characters));
                if (xeInfo != null)
                {
                    _frmPhieuCan.TxtKhachHang.Text = xeInfo.Khachhang;
                    _frmPhieuCan.TxtTenLaiXe.Text  = xeInfo.TaiXe;
                    _frmPhieuCan.TxtKLCanLan2.Text = xeInfo.TrongLuong.ToString();
                    _frmPhieuCan.TxtKLHang.Text    = (int.Parse(blKLCan.Text) - xeInfo.TrongLuong).ToString();
                    Utilities.XeDaCoTrongCSDL      = true;
                    Utilities.klXe = xeInfo.TrongLuong;
                }
                else
                {
                    frmMain.lbThongBao.Text = "Xe này chưa có trong cơ sở dữ liệu";
                }
            }
        }
        private void btnCan_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(txtBienSoXe.Text))
            {
                MessageBox.Show(this, "Chưa lấy biển số!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            // neu lay bsx loi, van cho can bt
            if (txtBienSoXe.Text.Equals("Lấy biển số lỗi"))
            {
                txtKLTong.Text     = string.Format("{0:#,0}", int.Parse(blKLCan.Text));
                txtGioCanTong.Text = DateTime.Now.ToString();
                return;
            }

            // load thong tin xe da luu csdl
            XeCtrl xeCtrl = new XeCtrl();
            XeInfo xeInfo = xeCtrl.LayThongTinXe(txtBienSoXe.Text);

            if (xeInfo != null) //xe da luu csdl
            {
                txtKhachHang.Text  = xeInfo.Khachhang;
                txtLaiXe.Text      = xeInfo.TaiXe;
                txtKLTong.Text     = string.Format("{0:#,0}", int.Parse(blKLCan.Text));
                txtKLBi.Text       = string.Format("{0:#,0}", xeInfo.TrongLuong);
                txtKLHang.Text     = string.Format("{0:#,0}", (int.Parse(blKLCan.Text) - xeInfo.TrongLuong));
                txtGioCanTong.Text = DateTime.Now.ToString();

                Utilities.XeDaCoTrongCSDL = true;
                Utilities.klXe            = xeInfo.TrongLuong;
            }
            else // xe chua co trong csdl
            {
                // tim phieu can theo bsx
                PhieuCanInfo phieucan = _PhieuCanCtrl.LayPhieuCanTheoBSX(txtBienSoXe.Text);
                // neu da co phieu can (da can lan 1)
                if (phieucan != null)
                {
                    txtMaPhieu.Text   = phieucan.MaPhieu;
                    txtKhachHang.Text = phieucan.KhachHang;
                    txtLaiXe.Text     = phieucan.LaiXe;
                    cbLoaiHang.Text   = phieucan.LoaiHang;
                    txtDonGia.Text    = phieucan.DonGia.ToString();

                    decimal klCanLan1 = phieucan.KLCanLan1;
                    decimal klCan     = decimal.Parse(blKLCan.Text);

                    if (klCan < klCanLan1) // da can tong, chua can bi
                    {
                        txtKLTong.Text     = string.Format("{0:#,0}", klCanLan1);
                        txtKLBi.Text       = string.Format("{0:#,0}", klCan);
                        txtKLHang.Text     = string.Format("{0:#,0}", (klCanLan1 - klCan));
                        txtGioCanTong.Text = phieucan.NgayCanLan1.ToString();
                        txtGioCanBi.Text   = DateTime.Now.ToString();
                    }
                    else // da can bi, chua can tong
                    {
                        txtKLTong.Text     = string.Format("{0:#,0}", klCan);
                        txtKLBi.Text       = string.Format("{0:#,0}", klCanLan1);
                        txtKLHang.Text     = string.Format("{0:#,0}", (klCan - klCanLan1));
                        txtGioCanTong.Text = DateTime.Now.ToString();
                        txtGioCanBi.Text   = phieucan.NgayCanLan1.ToString();
                    }
                    Utilities.klXe = decimal.Parse(txtKLBi.Text);
                }
                else // neu chua co phieu can
                {
                    txtKLTong.Text     = string.Format("{0:#,0}", int.Parse(blKLCan.Text));
                    txtGioCanTong.Text = DateTime.Now.ToString();
                }
            }
            // thanh tien
            txtThanhTien.Text = (string.IsNullOrWhiteSpace(txtDonGia.Text) || string.IsNullOrWhiteSpace(txtKLHang.Text)) ? "" : (decimal.Parse(txtDonGia.Text) * decimal.Parse(txtKLHang.Text)).ToString();
        }