예제 #1
0
        private void tựĐộngThanhLýToolStripMenuItem_Click(object sender, EventArgs e)
        {
            int           count = 0;
            List <TaiSan> liTS  = bll.GetListTS_BLL();

            foreach (TaiSan ts in liTS)
            {
                List <DTO.ChungTuGiam> ThongtinCtg = bll.GetThongTinCTGbyMaTS_BLL(ts.MaTaiSan);
                if (ThongtinCtg.Count > 0)
                {
                    continue;
                }

                int nsd = ts.NgayGhiTang.Value.Year;
                int now = DateTime.Now.Year;

                if (ts.TyLeCL - ts.TyLeHM * (now - nsd) == 0)
                {
                    count++;
                    DTO.ChungTuGiam ctg = new DTO.ChungTuGiam();
                    ctg.MaChungTuGiam = "02-TDTL-" + RandomString(8);
                    ctg.MaTaiSan      = ts.MaTaiSan;
                    ctg.NgayGhiGiam   = DateTime.Now;
                    ctg.SoLuong       = ts.SoLuong;
                    ctg.ThanhTien     = ts.ThanhTien;
                    ctg.NoiDung       = "Thanh lý hao mòn dưới 0%";
                    ctg.GhiChu        = "ghi chu 1";
                    bll.UpdateSL(ctg.MaTaiSan, 0, 0);
                    bll.AddChungTuGiam_BLL(ctg);
                }
            }
            addCTG();
            addVePhong();
            MessageBox.Show("Đã thanh lý " + count.ToString() + " tài sản có tỷ lệ còn lại dưới 0%!");
        }
        private void buttonOK_Click(object sender, EventArgs e)
        {
            bool isGoodToGo = true;


            if (String.IsNullOrEmpty(textBoxMaCTG.Text.Trim()))
            {
                MessageBox.Show("Nhập lại mã chứng từ giảm", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                isGoodToGo = false;
            }

            foreach (string ob in bll.GetListMaCTT_BLL())
            {
                if (textBoxMaCTG.Text.Equals(ob.ToString()))
                {
                    MessageBox.Show("Nhập lại mã chứng từ giảm", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    isGoodToGo = false;
                    break;
                }
            }

            if (isGoodToGo)
            {
                DTO.ChungTuGiam myTS = new DTO.ChungTuGiam();
                //string mats= bll.GetMTS_BLL(bll.GetMaPhong_BLL(cbbPhong.SelectedItem.ToString()), cbbTenTS.SelectedItem.ToString());
                string matsruong = bll.GetMaTSTruong_BLL(cbbTenTS.SelectedItem.ToString());
                string mats      = matsruong.Substring(0, 3) + "-" + bll.GetMaKhoa_BLL(cbbKhoa.SelectedItem.ToString()) + "-" + bll.GetMaPhong_BLL(cbbPhong.SelectedItem.ToString());
                myTS.MaTaiSan      = mats;
                myTS.MaChungTuGiam = textBoxMaCTG.Text.ToString();
                myTS.SoLuong       = int.Parse(numericUpDownSoLuong.Value.ToString());
                myTS.NgayGhiGiam   = dateTimePickerGhiGiam.Value;
                myTS.ThanhTien     = 10 * int.Parse(numericUpDownSoLuong.Value.ToString());
                myTS.NoiDung       = textBoxNoiDung.Text;
                myTS.GhiChu        = textBoxGhiChu.Text;
                bll.AddChungTuGiam_BLL(myTS);
                int slPhong = bll.GetSL_BLL(mats) - myTS.SoLuong;
                bll.UpdateSL(mats, slPhong, slPhong * 10);
                d();

                this.Close();
                MessageBox.Show("Thêm tài sản thành công !", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }