public PhieuCamDo(string ma) { InitializeComponent(); Hang_Hoa(); db = new DB_Quan_Ly_Cam_DoDataContext(SqlHelper.ConnectionString); bbiTaoMoi_ItemClick(this, null); _mColumn = new Column(); _mColumn = Column.None; tinh_trang = "sua"; bm.SetPopupContextMenu(gcList, pm); var ct = (from c in db.CHUNG_TUs where c.Ma_Chung_Tu == ma select c).FirstOrDefault(); txtMaChungTu.Text = ct.Ma_Chung_Tu; txtMaChungTu.Properties.ReadOnly = true; txtSo.Text = ct.So; txtNgay.EditValue = ct.Ngay; txtKhachHang.Text = ct.Ten_Khach_Hang; txtCMNDSo.Text = ct.So_CMND; txtNgayCap.Text = ct.Ngay_Cap_CMND; txtNoiCap.Text = ct.Noi_Cap; txtNgaySinh.Text = ct.Ngay_Sinh; txtDiaChi.Text = ct.Dia_Chi; txtSoDienThoai.Text = ct.So_Dien_Thoai; txtChuTiem.Text = ct.Chu_Tiem; txtSoTienCam.Value = ct.So_Tien_Cam ?? 0; txtTuNgay.Text = ct.Tu_Ngay; txtDenNgay.Text = ct.Den_Ngay; txtGhiChu.Text = ct.Ghi_Chu; //txtChungTuGoc.Text = ct.Chung_Tu_Goc; //txtTienLaiCu.Value = ct.Tien_Lai_Cu ?? 0; cHUNG_TU_CHI_TIETTableAdapter.Connection.ConnectionString = SqlHelper.ConnectionString; cHUNG_TU_CHI_TIETTableAdapter.ClearBeforeFill = true; cHUNG_TU_CHI_TIETTableAdapter.Fill(dsCamDo.CHUNG_TU_CHI_TIET, txtMaChungTu.Text); gbList_HangHoa.ShownEditor += (s, e) => { var view = s as GridView; view.ActiveEditor.DoubleClick += Chon_Hang_Hoa; }; }
public PhieuCamDo() { InitializeComponent(); Hang_Hoa(); db = new DB_Quan_Ly_Cam_DoDataContext(SqlHelper.ConnectionString); bbiTaoMoi_ItemClick(this, null); _mColumn = new Column(); _mColumn = Column.None; tinh_trang = "them"; bm.SetPopupContextMenu(gcList, pm); gbList_HangHoa.ShownEditor += (s, e) => { var view = s as GridView; view.ActiveEditor.DoubleClick += Chon_Hang_Hoa; }; NapDanhSachKhachHang(); NapDanhSachDiaChi(); NapDanhSachHangHoa(); }
public frmChiTietTinhTienLoi(string ma, DateTime ngayTinhLai) { InitializeComponent(); DB_Quan_Ly_Cam_DoDataContext db = new DB_Quan_Ly_Cam_DoDataContext(SqlHelper.ConnectionString); txtMaChungTuCamDo.Properties.ReadOnly = true; txtSo.Properties.ReadOnly = true; txtTenKhachhang.Properties.ReadOnly = true; var ctcd = (from cd in db.CHUNG_TUs where cd.Ma_Chung_Tu == ma select cd).FirstOrDefault(); if (ctcd != null) { txtSo.Text = ctcd.So; txtTenKhachhang.Text = ctcd.Ten_Khach_Hang; txtSoCMND.Text = ctcd.So_CMND; txtLaiSuatThang.Value = ctcd.Lai_Suat_Thang ?? 0; txtSoTienCam.Value = ctcd.So_Tien_Cam ?? 0; txtNgayCamDo.DateTime = ctcd.Ngay ?? DateTime.MinValue; txtMaChungTuCamDo.Text = ma; txtGhi_Chu.Text = ctcd.Ghi_Chu; } machungtucamdo = txtMaChungTuCamDo.Text; socamdo = txtSo.Text; ngayghisocamdo = txtNgayCamDo.DateTime; socmnd = txtSoCMND.Text; tenkhachhang = txtTenKhachhang.Text; string sql = @" --DECLARE @Ma_CT VARCHAR(200) --DECLARE @Ngay_Tinh_Lai DATETIME -- --SET @Ma_CT = 'test' --SET @Ngay_Tinh_Lai = GETDATE() DECLARE @Chi_Tiet_Tinh_Tien_Lai TABLE ( Ma VARCHAR(200) NULL, Ngay_Ghi_So DATETIME NULL, So_Tien_Thu MONEY NULL, So_Tien_Chi MONEY NULL, Ma_Phan_Loai VARCHAR(200) NULL, So_Thang_Cam MONEY NULL, So_Ngay_Cam MONEY NULL, So_Tien_Cam MONEY NULL, Tien_Lai MONEY NULL, Ghi_Chu NVARCHAR(250) NULL ) DECLARE @So_Tien_Cam_Do MONEY DECLARE @Ngay_Ghi_So_Cam_Do DATETIME DECLARE @Lai_Suat_Thang_Cam_Do MONEY DECLARE @Lai_Suat_Ngay_Cam_Do MONEY DECLARE @Ngay_Ghi_So_Cuoi_Cung DATETIME SELECT @So_Tien_Cam_Do = ct.So_Tien_Cam, @Ngay_Ghi_So_Cam_Do = ct.Ngay, @Lai_Suat_Thang_Cam_Do = ct.Lai_Suat_Thang, @Lai_Suat_Ngay_Cam_Do = ct.Lai_Suat_Ngay, @Ngay_Ghi_So_Cuoi_Cung = ct.Ngay FROM CHUNG_TU ct WHERE ct.Ma_Chung_Tu = @Ma_CT DECLARE @Ma VARCHAR(200) DECLARE @Ngay_Ghi_So DATETIME DECLARE @So_Tien_Thu MONEY DECLARE @So_Tien_Chi MONEY DECLARE @Ma_Phan_Loai VARCHAR(200) DECLARE @Ghi_Chu NVARCHAR(250) DECLARE @Tien_Lai_Tam MONEY DECLARE @Tien_Cam_Do_Tam MONEY SET @Tien_Lai_Tam = 0 SET @Tien_Cam_Do_Tam = @So_Tien_Cam_Do DECLARE db_cursor CURSOR FOR SELECT cttc.Ma, cttc.Ngay_Ghi_So, cttc.So_Tien_Thu, cttc.So_Tien_Chi, cttc.Ma_Phan_Loai, cttc.Ghi_Chu FROM CHUNG_TU_THU_CHI cttc WHERE cttc.Ma_Chung_Tu_Cam_Do = @Ma_CT ORDER BY cttc.Ngay_Ghi_So OPEN db_cursor FETCH NEXT FROM db_cursor INTO @Ma,@Ngay_Ghi_So,@So_Tien_Thu, @So_Tien_Chi, @Ma_Phan_Loai, @Ghi_Chu WHILE @@FETCH_STATUS = 0 BEGIN IF (@Ma_Phan_Loai != 'Loi') BEGIN SET @Tien_Lai_Tam = ( @Tien_Cam_Do_Tam / 100 * @Lai_Suat_Thang_Cam_Do * dbo.Lay_Thang(@Ngay_Ghi_So_Cuoi_Cung, @Ngay_Ghi_So) ) + ( @Tien_Cam_Do_Tam / 100 * @Lai_Suat_Ngay_Cam_Do * dbo.Lay_Ngay(@Ngay_Ghi_So_Cuoi_Cung, @Ngay_Ghi_So) ) IF (@Ma_Phan_Loai = 'Them' OR @Ma_Phan_Loai = 'Bot') BEGIN SET @Tien_Cam_Do_Tam = @Tien_Cam_Do_Tam + (@So_Tien_Chi - @So_Tien_Thu) --SET @Ngay_Ghi_So_Cuoi_Cung = @Ngay_Ghi_So END END INSERT INTO @Chi_Tiet_Tinh_Tien_Lai ( Ma, Ngay_Ghi_So, So_Tien_Thu, So_Tien_Chi, Ma_Phan_Loai, So_Thang_Cam, So_Ngay_Cam, So_Tien_Cam, Tien_Lai, Ghi_Chu ) VALUES ( @Ma, @Ngay_Ghi_So, @So_Tien_Thu, @So_Tien_Chi, @Ma_Phan_Loai, dbo.Lay_Thang(@Ngay_Ghi_So_Cuoi_Cung, @Ngay_Ghi_So), dbo.Lay_Ngay(@Ngay_Ghi_So_Cuoi_Cung, @Ngay_Ghi_So), @Tien_Cam_Do_Tam, @Tien_Lai_Tam, @Ghi_Chu ) IF (@Ma_Phan_Loai = 'Them' OR @Ma_Phan_Loai = 'Bot') BEGIN --SET @Tien_Cam_Do_Tam = @Tien_Cam_Do_Tam + (@So_Tien_Chi - @So_Tien_Thu) SET @Ngay_Ghi_So_Cuoi_Cung = @Ngay_Ghi_So END SET @Tien_Lai_Tam = 0 FETCH NEXT FROM db_cursor INTO @Ma,@Ngay_Ghi_So,@So_Tien_Thu, @So_Tien_Chi, @Ma_Phan_Loai, @Ghi_Chu END CLOSE db_cursor DEALLOCATE db_cursor /*them 1 dong tinh tien lai cuoi cung*/ ------------------------------------------------------------------- SET @Tien_Lai_Tam = ( @Tien_Cam_Do_Tam / 100 * @Lai_Suat_Thang_Cam_Do * dbo.Lay_Thang(@Ngay_Ghi_So_Cuoi_Cung, @Ngay_Tinh_Lai) ) + ( @Tien_Cam_Do_Tam / 100 * @Lai_Suat_Ngay_Cam_Do * dbo.Lay_Ngay(@Ngay_Ghi_So_Cuoi_Cung, @Ngay_Tinh_Lai) ) INSERT INTO @Chi_Tiet_Tinh_Tien_Lai ( Ma, Ngay_Ghi_So, So_Tien_Thu, So_Tien_Chi, Ma_Phan_Loai, So_Thang_Cam, So_Ngay_Cam, So_Tien_Cam, Tien_Lai, Ghi_Chu ) VALUES ( CAST(NULL AS VARCHAR(200)), --@Ma, @Ngay_Tinh_Lai, --@Ngay_Ghi_So, CAST(NULL AS MONEY), --@So_Tien_Thu, CAST(NULL AS MONEY), --@So_Tien_Chi, CAST(NULL AS VARCHAR(5)), --@Ma_Phan_Loai, dbo.Lay_Thang(@Ngay_Ghi_So_Cuoi_Cung, @Ngay_Tinh_Lai), --dbo.Lay_Thang(@Ngay_Ghi_So_Cam_Do, @Ngay_Ghi_So), dbo.Lay_Ngay(@Ngay_Ghi_So_Cuoi_Cung, @Ngay_Tinh_Lai), --dbo.Lay_Ngay(@Ngay_Ghi_So_Cam_Do, @Ngay_Ghi_So), @Tien_Cam_Do_Tam, @Tien_Lai_Tam, N'Tiền lãi khi chuộc' --@Ghi_Chu ) ------------------------------------------------------------------- SELECT *, @Ngay_Ghi_So_Cuoi_Cung, @Tien_Cam_Do_Tam FROM @Chi_Tiet_Tinh_Tien_Lai ctttl --DECLARE @Tong_Tien_Lai MONEY --DECLARE @Tong_Thu_Tien_Lai MONEY -- --SELECT @Tong_Tien_Lai = SUM(ctttl.Tien_Lai) --FROM @Chi_Tiet_Tinh_Tien_Lai ctttl -- --SELECT @Tong_Thu_Tien_Lai = SUM(cttc.So_Tien_Thu) --FROM CHUNG_TU_THU_CHI cttc --WHERE cttc.Ma_Chung_Tu_Cam_Do = @Ma_CT -- AND cttc.Ma_Phan_Loai = 'Loi' -- --SELECT ROUND( -- (ISNULL(@Tong_Tien_Lai, 0) - ISNULL(@Tong_Thu_Tien_Lai, 0)) + ( -- dbo.Lay_Thang(@Ngay_Ghi_So_Cuoi_Cung, @Ngay_Tinh_Lai) * (@Tien_Cam_Do_Tam / 100) -- * @Lai_Suat_Thang_Cam_Do -- ) + ( -- dbo.Lay_Ngay(@Ngay_Ghi_So_Cuoi_Cung, @Ngay_Tinh_Lai) * (@Tien_Cam_Do_Tam / 100) -- * @Lai_Suat_Ngay_Cam_Do -- ),-3 -- ) "; dsThuChi.CHI_TIET_TINH_TIEN_LAI.Rows.Clear(); SqlConnection conn = new SqlConnection(SqlHelper.ConnectionString); SqlCommand cmd = new SqlCommand(sql, conn); cmd.CommandType = CommandType.Text; cmd.CommandTimeout = 0; cmd.Parameters.AddWithValue("@Ma_CT", ma); cmd.Parameters.AddWithValue("@Ngay_Tinh_Lai", ngayTinhLai); try { conn.Open(); dsThuChi.CHI_TIET_TINH_TIEN_LAI.Load(cmd.ExecuteReader()); conn.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message); } gbList.BestFitColumns(); }
private void bbiXoa_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { if (MessageBox.Show("Khi xóa chứng từ thì tất cả các phiếu thu liên quan sẽ được xóa theo.\nBạn có muốn xóa không?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.No) return; gbList.Focus(); int[] selectedRows = gbList.GetSelectedRows(); string[] chungtu = new string[selectedRows.Length]; for (int i = selectedRows.Length; i > 0; i--) { var arg = gbList.GetRowCellValue(selectedRows[i - 1], colMa_Chung_Tu); if (arg == null) continue; if (!KiemTraPhieuDaChuoc(arg.ToString())) continue; chungtu[i - 1] = arg.ToString(); } var db = new DB_Quan_Ly_Cam_DoDataContext(SqlHelper.ConnectionString); try { db.Connection.Open(); System.Data.Common.DbTransaction transaction = db.Connection.BeginTransaction(); db.Transaction = transaction; var ct = from c in db.CHUNG_TUs where chungtu.Contains(c.Ma_Chung_Tu) select c; foreach (var c in ct) { db.CHUNG_TUs.DeleteOnSubmit(c); var chung_tu_thu_chi = from cttcs in db.CHUNG_TU_THU_CHIs where cttcs.Ma_Chung_Tu_Cam_Do == c.Ma_Chung_Tu select cttcs; foreach (var cttc in chung_tu_thu_chi) { db.CHUNG_TU_THU_CHIs.DeleteOnSubmit(cttc); } } db.SubmitChanges(); db.Transaction.Commit(); db.Connection.Close(); bbiXem_ItemClick(this, null); } catch (Exception ex) { db.Transaction.Rollback(); MessageBox.Show(ex.Message); } }
private void bbiXoa_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { if (MessageBox.Show("Có muốn xóa không?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.No) return; gbList.Focus(); int[] selectedRows = gbList.GetSelectedRows(); string[] chungtuthuchi = new string[selectedRows.Length]; for (int i = selectedRows.Length; i > 0; i--) { var arg = gbList.GetRowCellValue(selectedRows[i - 1], colMa); if (arg == null) continue; chungtuthuchi[i - 1] = arg.ToString(); } DB_Quan_Ly_Cam_DoDataContext db = new DB_Quan_Ly_Cam_DoDataContext(SqlHelper.ConnectionString); var cttc = from ct in db.CHUNG_TU_THU_CHIs where chungtuthuchi.Contains(ct.Ma) select ct; foreach (var c in cttc) { db.CHUNG_TU_THU_CHIs.DeleteOnSubmit(c); } try { db.SubmitChanges(); bbiXem_ItemClick(this, null); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
public rptPhieuInCamDo(string maphieu, bool inthongtinrutgon) { InitializeComponent(); Ten_Tiem.Value = SqlHelper.TenTiem; BenB.Value = string.IsNullOrEmpty(SqlHelper.BienNhanCamDoBenB) ? "....................................................................." : SqlHelper.BienNhanCamDoBenB; Dia_Chi_Tiem.Value = SqlHelper.DiaChi; Dien_Thoai_Tiem.Value = SqlHelper.DienThoai; DataSet ds = new DataSet(); ds = dsCamDo1.Copy(); ds.Tables[dsCamDo1.CHUNG_TU_CHI_TIET.TableName].Rows.Clear(); var database = new DB_Quan_Ly_Cam_DoDataContext(SqlHelper.ConnectionString); var chungtu = (from ct in database.CHUNG_TUs where ct.Ma_Chung_Tu == maphieu select ct).FirstOrDefault(); if (chungtu != null) { Ma_Chung_Tu.Value = chungtu.Ma_Chung_Tu; So.Value = chungtu.So; Lien.Value = chungtu.Lien; Ngay.Value = chungtu.Ngay; Ten_Khach_Hang.Value = chungtu.Ten_Khach_Hang; So_CMND.Value = string.IsNullOrEmpty(chungtu.So_CMND) ? "......................................" : chungtu.So_CMND; Ngay_Cap_CMND.Value = string.IsNullOrEmpty(chungtu.Ngay_Cap_CMND) ? "......................................" : chungtu.Ngay_Cap_CMND; Noi_Cap_CMND.Value = string.IsNullOrEmpty(chungtu.Noi_Cap) ? "..................................." : chungtu.Noi_Cap; Dia_Chi.Value = string.IsNullOrEmpty(chungtu.Dia_Chi) ? "......................................" : chungtu.Dia_Chi; So_Dien_Thoai.Value = string.IsNullOrEmpty(chungtu.So_Dien_Thoai) ? "......................................" : chungtu.So_Dien_Thoai; So_Tien_Cam.Value = chungtu.So_Tien_Cam; So_Tien_Cam_Bang_Chu.Value = TinhToan.DocChu(String.Format("{0:##,##0}",chungtu.So_Tien_Cam)); Tu_Ngay.Value = string.IsNullOrEmpty(chungtu.Tu_Ngay) ? ".........................." : chungtu.Tu_Ngay; Den_Ngay.Value = string.IsNullOrEmpty(chungtu.Den_Ngay) ? ".........................." : chungtu.Den_Ngay; Lai_Suat_Ngay.Value = chungtu.Lai_Suat_Ngay; Lai_Suat_Thang.Value = chungtu.Lai_Suat_Thang; thong_tin_rut_gon_khach_hang = ""; thong_tin_rut_gon_khach_hang += "Mã: " + chungtu.Ma_Chung_Tu + " - Số: " + chungtu.So + " - Ngày: " + String.Format("{0:dd/MM/yyyy}", chungtu.Ngay) + "\n"; thong_tin_rut_gon_khach_hang += "Tên: " + chungtu.Ten_Khach_Hang + "\n"; thong_tin_rut_gon_khach_hang += "Số Tiền: " + String.Format("{0:##,##0.###}", chungtu.So_Tien_Cam) + "\n"; } string[] myPara = { "@Ma_Chung_Tu" }; object[] myValue = { maphieu }; string sql = @" SELECT * FROM CHUNG_TU_CHI_TIET ctct WHERE ctct.Ma_Chung_Tu = @Ma_Chung_Tu "; var mySql = new SqlHelper(); ds.Tables[dsCamDo1.CHUNG_TU_CHI_TIET.TableName].Merge(mySql.ExecuteDataTable(sql, myPara, myValue)); dsCamDo1.Merge(ds); if (inthongtinrutgon) { if (ds != null) { for (int i = 0; i < ds.Tables[dsCamDo1.CHUNG_TU_CHI_TIET.TableName].Rows.Count; i++) { thong_tin_rut_gon_tai_san += "- " + ds.Tables[dsCamDo1.CHUNG_TU_CHI_TIET.TableName].Rows[i]["Ten_Tai_San"].ToString() + " - " + ds.Tables[dsCamDo1.CHUNG_TU_CHI_TIET.TableName].Rows[i]["Loai_Vang"].ToString() + " - " + ds.Tables[dsCamDo1.CHUNG_TU_CHI_TIET.TableName].Rows[i]["Trong_Luong"].ToString(); if (i < ds.Tables[dsCamDo1.CHUNG_TU_CHI_TIET.TableName].Rows.Count - 1) { thong_tin_rut_gon_tai_san += "\n"; } } } Thong_Tin_Rut_Gon_Khach_Hang.Value = thong_tin_rut_gon_khach_hang; Thong_Tin_Rut_Gon_Tai_San.Value = thong_tin_rut_gon_tai_san; xrtbThongTinRutGon.Visible = true; } RequestParameters = false; }
bool Kiem_Tra() { if (!txtMa.Properties.ReadOnly) { DB_Quan_Ly_Cam_DoDataContext db = new DB_Quan_Ly_Cam_DoDataContext(SqlHelper.ConnectionString); var cttc = (from ct in db.CHUNG_TU_THU_CHIs where ct.Ma == txtMa.Text select ct); if (cttc.Count() > 0) { if (MessageBox.Show("Mã trùng. Bạn có muốn đổi mã khác hay không ?", "Cảnh báo", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes) { txtMa.Text = SqlHelper.GenCode("CHUNG_TU_THU_CHI", "Ma", "PT", 1); } return false; } } if (string.IsNullOrEmpty(txtMa.Text)) { MessageBox.Show("Mã không được rỗng.", "Cảnh báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); return false; } if (string.IsNullOrEmpty(txtMaChungTuCamDo.Text) && cbLoai.Text != "Thu tiền khác") { MessageBox.Show("Mã chứng từ cầm đồ không được rỗng.", "Cảnh báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); return false; } if (txtSoTien.Value <= 0) { MessageBox.Show("Số tiền phải lớn hơn 0.", "Cảnh báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); return false; } return true; }
public PhieuThu(string ma) { InitializeComponent(); bbiTaoMoi_ItemClick(this, null); DB_Quan_Ly_Cam_DoDataContext db = new DB_Quan_Ly_Cam_DoDataContext(SqlHelper.ConnectionString); var cttc = (from ct in db.CHUNG_TU_THU_CHIs where ct.Ma == ma select ct).FirstOrDefault(); int loai = 0; if (cttc.Ma_Phan_Loai == "Chuoc") { loai = 0; } else if (cttc.Ma_Phan_Loai == "Loi") { loai = 1; } else if (cttc.Ma_Phan_Loai == "Bot") { loai = 2; } else if (cttc.Ma_Phan_Loai == "Thu Khac") { loai = 3; } cbLoai.SelectedIndex = loai; txtMaChungTuCamDo.Properties.ReadOnly = true; txtSo.Properties.ReadOnly = true; txtTenKhachhang.Properties.ReadOnly = true; var ctcd = (from cd in db.CHUNG_TUs where cd.Ma_Chung_Tu == cttc.Ma_Chung_Tu_Cam_Do select cd).FirstOrDefault(); if (ctcd != null) { txtSo.Text = ctcd.So; txtTenKhachhang.Text = ctcd.Ten_Khach_Hang; txtSoCMND.Text = ctcd.So_CMND; txtLaiSuatThang.Value = ctcd.Lai_Suat_Thang ?? 0; txtSoTienCam.Value = TinhToan.So_Tien_Cam(cttc.Ma_Chung_Tu_Cam_Do); txtNgayCamDo.DateTime = ctcd.Ngay ?? DateTime.MinValue; } txtMa.Text = cttc.Ma; txtMa.Properties.ReadOnly = true; txtNgay.DateTime = cttc.Ngay; txtNgayGhiSo.DateTime = cttc.Ngay_Ghi_So ?? Convert.ToDateTime(null); txtMaChungTuCamDo.Text = cttc.Ma_Chung_Tu_Cam_Do; if (cttc.Ma_Phan_Loai == "Thu Khac") { txtSoTienCam.Value = cttc.So_Tien_Cam ?? 0; } txtTienLai.Value = cttc.Tien_Lai ?? 0; txtSoTien.Value = cttc.So_Tien_Thu ?? 0; txtGhi_Chu.Text = cttc.Ghi_Chu; machungtucamdo = txtMaChungTuCamDo.Text; socamdo = txtSo.Text; ngayghisocamdo = txtNgayCamDo.DateTime; socmnd = txtSoCMND.Text; tenkhachhang = txtTenKhachhang.Text; tinh_trang = "sua"; }
private void bbiLuu_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { if (!Kiem_Tra()) { return; } string phan_loai = ""; string ma_phan_loai = ""; switch (cbLoai.Text) { case "Thu tiền khách chuộc đồ": phan_loai = "Chuộc"; ma_phan_loai = "Chuoc"; break; case "Thu tiền khách trả tiền lời": phan_loai = "Trả tiền lời"; ma_phan_loai = "Loi"; break; case "Thu tiền khách trả bớt tiền": phan_loai = "Trả bớt tiền"; ma_phan_loai = "Bot"; break; default: phan_loai = "Thu khác"; ma_phan_loai = "Thu Khac"; break; } try { DB_Quan_Ly_Cam_DoDataContext db = new DB_Quan_Ly_Cam_DoDataContext(SqlHelper.ConnectionString); if (tinh_trang == "them") { CHUNG_TU_THU_CHI cttc = new CHUNG_TU_THU_CHI(); cttc.Ma = txtMa.Text; cttc.Ngay = txtNgay.DateTime; cttc.Ngay_Ghi_So = txtNgayGhiSo.DateTime; cttc.Ma_Chung_Tu_Cam_Do = txtMaChungTuCamDo.Text; cttc.Loai = "Thu"; cttc.Ma_Phan_Loai = ma_phan_loai; cttc.Phan_Loai = phan_loai; cttc.Ten_Loai = cbLoai.Text; cttc.So_Tien_Cam = txtSoTienCam.Value; cttc.Tien_Lai = txtTienLai.Value; cttc.So_Tien_Thu = txtSoTien.Value; cttc.So_Tien_Chi = 0; cttc.Ghi_Chu = txtGhi_Chu.Text; cttc.Sap_Xep = 0; db.CHUNG_TU_THU_CHIs.InsertOnSubmit(cttc); } else { var cttc = (from ct in db.CHUNG_TU_THU_CHIs where ct.Ma == txtMa.Text select ct).FirstOrDefault(); cttc.Ma = txtMa.Text; cttc.Ngay = txtNgay.DateTime; cttc.Ngay_Ghi_So = txtNgayGhiSo.DateTime; cttc.Ma_Chung_Tu_Cam_Do = txtMaChungTuCamDo.Text; cttc.Loai = "Thu"; cttc.Ma_Phan_Loai = ma_phan_loai; cttc.Phan_Loai = phan_loai; cttc.Ten_Loai = cbLoai.Text; cttc.So_Tien_Cam = txtSoTienCam.Value; cttc.Tien_Lai = txtTienLai.Value; cttc.So_Tien_Thu = txtSoTien.Value; cttc.So_Tien_Chi = 0; cttc.Ghi_Chu = txtGhi_Chu.Text; cttc.Sap_Xep = 0; } db.SubmitChanges(); CapNhatCMNDPhieuCamDo(); RaiseReloadEventHander(); Close(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
public void CapNhatCMNDPhieuCamDo() { if (cbCapNhatCMND.Checked && !string.IsNullOrEmpty(txtSoCMND.Text.Trim())) { try { DB_Quan_Ly_Cam_DoDataContext db = new DB_Quan_Ly_Cam_DoDataContext(SqlHelper.ConnectionString); var chung_tu_cam_do = (from ct in db.CHUNG_TUs where ct.Ma_Chung_Tu == txtMaChungTuCamDo.Text select ct).First(); chung_tu_cam_do.So_CMND = txtSoCMND.Text; db.SubmitChanges(); } catch (Exception ex) { MessageBox.Show(ex.Message); } } }
string Luu_Chi_Tiet(DB_Quan_Ly_Cam_DoDataContext database) { var ket_qua = "OK"; var dt = dsCamDo.CHUNG_TU_CHI_TIET; var id = ""; var row = 0; for (var i = 0; i < dt.Rows.Count; i++) { if (dt.Rows[i].RowState != DataRowState.Deleted) { if (dt.Rows[i]["Ten_Tai_San"] == DBNull.Value || string.IsNullOrEmpty(dt.Rows[i]["Ten_Tai_San"].ToString())) { MessageBox.Show("Tên tài sản không được rỗng.", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); ket_qua = "Tên tài sản không được rỗng."; gbList.FocusedRowHandle = row; gbList.SetColumnError(colTen_Tai_San, "Tên tài sản không được rỗng."); return ket_qua; } id = dt.Rows[i]["Ma_Chi_Tiet"].ToString(); row++; } var dr = dt.Rows[i]; switch (dr.RowState) { case DataRowState.Added: var chung_tu_chi_tiet = new CHUNG_TU_CHI_TIET { Ma_Chi_Tiet = Guid.NewGuid(), Ma_Chung_Tu = txtMaChungTu.Text, Ten_Tai_San = dt.Rows[i]["Ten_Tai_San"].ToString(), Loai_Vang = dt.Rows[i]["Loai_Vang"].ToString(), Trong_Luong_Vang_18k = Convert.ToDecimal(dt.Rows[i][colTrong_Luong_Vang_18k.FieldName] == DBNull.Value ? 0 : dt.Rows[i][colTrong_Luong_Vang_18k.FieldName]), Trong_Luong_Vang_24k = Convert.ToDecimal(dt.Rows[i][colTrong_Luong_Vang_24k.FieldName] == DBNull.Value ? 0 : dt.Rows[i][colTrong_Luong_Vang_24k.FieldName]), Trong_Luong_Khac = Convert.ToDecimal(dt.Rows[i][colTrong_Luong_Khac.FieldName] == DBNull.Value ? 0 : dt.Rows[i][colTrong_Luong_Khac.FieldName]), Trong_Luong = dt.Rows[i]["Trong_Luong"].ToString(), Chuan_Do = dt.Rows[i]["Chuan_Do"].ToString(), Gia_Tri_Vat_Cam = Convert.ToDecimal(dt.Rows[i]["Gia_Tri_Vat_Cam"] == DBNull.Value ? 0 : dt.Rows[i]["Gia_Tri_Vat_Cam"]), Sap_Xep = 0 }; database.CHUNG_TU_CHI_TIETs.InsertOnSubmit(chung_tu_chi_tiet); break; case DataRowState.Modified: var chi_tiet_sua = (from ctct in database.CHUNG_TU_CHI_TIETs where ctct.Ma_Chi_Tiet == new Guid(id) select ctct).FirstOrDefault(); chi_tiet_sua.Ma_Chi_Tiet = new Guid(id); chi_tiet_sua.Ma_Chung_Tu = txtMaChungTu.Text; chi_tiet_sua.Ten_Tai_San = dt.Rows[i]["Ten_Tai_San"].ToString(); chi_tiet_sua.Loai_Vang = dt.Rows[i]["Loai_Vang"].ToString(); chi_tiet_sua.Trong_Luong_Vang_18k = Convert.ToDecimal(dt.Rows[i][colTrong_Luong_Vang_18k.FieldName] == DBNull.Value ? 0 : dt.Rows[i][colTrong_Luong_Vang_18k.FieldName]); chi_tiet_sua.Trong_Luong_Vang_24k = Convert.ToDecimal(dt.Rows[i][colTrong_Luong_Vang_24k.FieldName] == DBNull.Value ? 0 : dt.Rows[i][colTrong_Luong_Vang_24k.FieldName]); chi_tiet_sua.Trong_Luong_Khac = Convert.ToDecimal(dt.Rows[i][colTrong_Luong_Khac.FieldName] == DBNull.Value ? 0 : dt.Rows[i][colTrong_Luong_Khac.FieldName]); chi_tiet_sua.Trong_Luong = dt.Rows[i]["Trong_Luong"].ToString(); chi_tiet_sua.Chuan_Do = dt.Rows[i]["Chuan_Do"].ToString(); chi_tiet_sua.Gia_Tri_Vat_Cam = Convert.ToDecimal(dt.Rows[i]["Gia_Tri_Vat_Cam"] == DBNull.Value ? 0 : dt.Rows[i]["Gia_Tri_Vat_Cam"]); chi_tiet_sua.Sap_Xep = 0; break; case DataRowState.Deleted: var chi_tiet_xoa = (from ctct in database.CHUNG_TU_CHI_TIETs where ctct.Ma_Chi_Tiet == new Guid(dt.Rows[i]["Ma_Chi_Tiet", DataRowVersion.Original].ToString()) select ctct).FirstOrDefault(); database.CHUNG_TU_CHI_TIETs.DeleteOnSubmit(chi_tiet_xoa); break; } database.SubmitChanges(); } return ket_qua; }
//string Luu_Lam_Giay_Moi(DB_Quan_Ly_Cam_DoDataContext database) //{ // var chung_tu = (from ct in database.CHUNG_TUs // where ct.Ma_Chung_Tu == txtChungTuGoc.Text // select ct).FirstOrDefault(); // if (chung_tu == null) // return "Không tìm thấy phiếu " + txtChungTuGoc.Text; // chung_tu.Da_Lam_Lai_Giay = true; // database.SubmitChanges(); // return "OK"; //} bool Kiem_Tra() { if (!txtMaChungTu.Properties.ReadOnly) { DB_Quan_Ly_Cam_DoDataContext database = new DB_Quan_Ly_Cam_DoDataContext(SqlHelper.ConnectionString); var chung_tu = (from ct in database.CHUNG_TUs where ct.Ma_Chung_Tu == txtMaChungTu.Text select ct); if (chung_tu.Count() > 0) { if (MessageBox.Show("Mã trùng. Bạn có muốn đổi mã khác hay không ?", "Cảnh báo", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes) { txtMaChungTu.Text = SqlHelper.GenCode("CHUNG_TU", "Ma_Chung_Tu", "CD", 1); } return false; } } if (string.IsNullOrEmpty(txtMaChungTu.Text)) { MessageBox.Show("Mã chứng từ rỗng.", "Cảnh báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); txtMaChungTu.Focus(); return false; } if (string.IsNullOrEmpty(txtKhachHang.Text)) { MessageBox.Show("Khách hàng rỗng.", "Cảnh báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); txtKhachHang.Focus(); return false; } if (txtSoTienCam.Value == 0) { MessageBox.Show("Số tiền bằng 0.", "Cảnh báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); txtSoTienCam.Focus(); return false; } if (dsCamDo.CHUNG_TU_CHI_TIET.Rows.Count == 0) { MessageBox.Show("Phiếu rỗng", "Cảnh báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); return false; } if (!KiemTraPhieuDaChuoc(txtMaChungTu.Text)) { return false; } return true; }
private void bbiLuu_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { gbList.FocusedRowHandle += 1; gbList.UpdateCurrentRow(); if (!Kiem_Tra()) { return; } DB_Quan_Ly_Cam_DoDataContext database = new DB_Quan_Ly_Cam_DoDataContext(SqlHelper.ConnectionString); try { database.Connection.Open(); System.Data.Common.DbTransaction transaction = database.Connection.BeginTransaction(); database.Transaction = transaction; if (tinh_trang == "them") { CHUNG_TU chung_tu = new CHUNG_TU { Ma_Chung_Tu = txtMaChungTu.Text, So = txtSo.Text, Lien = txtLien.Text, Ngay = txtNgay.DateTime, Ten_Khach_Hang = txtKhachHang.Text, So_CMND = txtCMNDSo.Text, Ngay_Cap_CMND = txtNgayCap.Text, Noi_Cap = txtNoiCap.Text, Ngay_Sinh = txtNgaySinh.Text, Dia_Chi = txtDiaChi.Text, So_Dien_Thoai = txtSoDienThoai.Text, Chu_Tiem = txtChuTiem.Text, So_Tien_Cam = txtSoTienCam.Value, Tu_Ngay = txtTuNgay.Text, Den_Ngay = txtDenNgay.Text, Lai_Suat_Ngay = txtLaiSuatNgay.Value, Lai_Suat_Thang = txtLaiSuatThang.Value, Da_Chuoc = false, Ghi_Chu = txtGhiChu.Text, //Tien_Lai_Cu = txtTienLaiCu.Value, //Chung_Tu_Goc = txtChungTuGoc.Text, Da_Lam_Lai_Giay = false, Mat_Giay = false, Sap_Xep = 0 }; database.CHUNG_TUs.InsertOnSubmit(chung_tu); } else { var chung_tu = (from ct in database.CHUNG_TUs where ct.Ma_Chung_Tu == txtMaChungTu.Text select ct).FirstOrDefault(); chung_tu.Ma_Chung_Tu = txtMaChungTu.Text; chung_tu.So = txtSo.Text; chung_tu.Lien = txtLien.Text; chung_tu.Ngay = txtNgay.DateTime; chung_tu.Ten_Khach_Hang = txtKhachHang.Text; chung_tu.So_CMND = txtCMNDSo.Text; chung_tu.Ngay_Cap_CMND = txtNgayCap.Text; chung_tu.Noi_Cap = txtNoiCap.Text; chung_tu.Ngay_Sinh = txtNgaySinh.Text; chung_tu.Dia_Chi = txtDiaChi.Text; chung_tu.So_Dien_Thoai = txtSoDienThoai.Text; chung_tu.Chu_Tiem = txtChuTiem.Text; chung_tu.So_Tien_Cam = txtSoTienCam.Value; chung_tu.Tu_Ngay = txtTuNgay.Text; chung_tu.Den_Ngay = txtDenNgay.Text; chung_tu.Lai_Suat_Ngay = txtLaiSuatNgay.Value; chung_tu.Lai_Suat_Thang = txtLaiSuatThang.Value; chung_tu.Da_Chuoc = false; chung_tu.Ghi_Chu = txtGhiChu.Text; //chung_tu.Tien_Lai_Cu = txtTienLaiCu.Value; //chung_tu.Chung_Tu_Goc = txtChungTuGoc.Text; chung_tu.Da_Lam_Lai_Giay = false; chung_tu.Mat_Giay = false; chung_tu.Sap_Xep = 0; } string ket_qua = ""; //if (lcChungTuGoc.Visibility == DevExpress.XtraLayout.Utils.LayoutVisibility.Always && !string.IsNullOrEmpty(txtChungTuGoc.Text)) //{ // ket_qua = Luu_Lam_Giay_Moi(database); // if (ket_qua != "OK") // { // database.Transaction.Rollback(); // MessageBox.Show(ket_qua); // } //} ket_qua = Luu_Chi_Tiet(database); if (ket_qua == "OK") { database.SubmitChanges(); database.Transaction.Commit(); database.Connection.Close(); if (InPhieu) { var rpt = new rptPhieuInCamDo(txtMaChungTu.Text, cbInThongTinRutGon.Checked); //rpt.AssignPrintTool(new ReportPrintTool(rpt)); rpt.CreateDocument(); //rpt.ShowPreview(); int lien = 0; if (int.TryParse(txtLien.Text, out lien)) { for (int i = 0; i < lien - 1; i++) { var rpt_add = new rptPhieuInCamDo(txtMaChungTu.Text, false); rpt_add.CreateDocument(); rpt.Pages.AddRange(rpt_add.Pages); } } rpt.PrintingSystem.ContinuousPageNumbering = true; ReportPrintTool printTool = new ReportPrintTool(rpt); printTool.ShowPreview(); } InPhieu = false; RaiseReloadEventHander(); Close(); } else { database.Transaction.Rollback(); MessageBox.Show(ket_qua); } } catch (Exception ex) { database.Transaction.Rollback(); MessageBox.Show(ex.ToString()); } }