private void Del() { tblphieunhapkhoBL ctr = new tblphieunhapkhoBL(); string kq = ""; string sidhd = ""; try { sidhd = txtID.Text.Trim(); } catch { } string stientttemp = "N/A"; try { stientttemp = ctr.GetByID(sidhd).tienthanhtoan.ToString(); } catch { } if (MessageBox.Show("Xác nhận xóa dữ liệu?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { UpdateSoLuongMatHang(sidhd); kq = ctr.Delete(sidhd); if (kq.Trim().Equals("") == true) { _ctrlog.Append(Data.use, "Xóa phiếu nhập hàng của nhà cung cấp: " + cbNhaCC.Text.Trim() + " xuất ngày: " + dpkNgayNhap.Value.ToString("dd/MM/yyyy").Trim() + "; id: " + txtID.Text.Trim() + ";\nChi tiết: Tổng tiền hàng: " + txtTongTien.Text + " - Nợ cũ: " + txtNoToaTruoc.Text + " - Tiền thanh toán: " + stientttemp + " - Tổng nợ mới: " + txtConNo.Text); Add(); HienThiDSMatHang(); } else { MessageBox.Show("Xóa phiếu nhập hàng không thành công.\nChi tiết lỗi: " + kq, "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } }
private void FormatGrid() { tblphieunhapkhoBL ctr = new tblphieunhapkhoBL(); for (int i = 0; i < c1FlexGrid1.Cols.Count; i++) { if (i == 0) { c1FlexGrid1[0, i] = "STT"; c1FlexGrid1.Cols[i].Visible = true; c1FlexGrid1.Cols[i].Width = 50; } else if (c1FlexGrid1.Cols[i].Caption.Equals("ngaytt")) { c1FlexGrid1[0, i] = "Ngày thanh toán"; c1FlexGrid1.Cols[i].Visible = true; c1FlexGrid1.Cols["ngaytt"].Format = "dd/MM/yyyy HH:mm:ss"; c1FlexGrid1.Cols[i].WidthDisplay = 210; } else if (c1FlexGrid1.Cols[i].Caption.Equals("tientt")) { c1FlexGrid1[0, i] = "Tiền thanh toán"; c1FlexGrid1.Cols[i].Visible = true; c1FlexGrid1.Cols["tientt"].Format = "N0"; c1FlexGrid1.Cols[i].WidthDisplay = 150; } else if (c1FlexGrid1.Cols[i].Caption.Equals("ghichu")) { c1FlexGrid1[0, i] = "Ghi chú"; c1FlexGrid1.Cols[i].Visible = true; c1FlexGrid1.Cols[i].WidthDisplay = 200; } else { c1FlexGrid1.Cols[i].Visible = false; } c1FlexGrid1.Cols[i].TextAlignFixed = TextAlignEnum.CenterCenter; } Font _font = new Font("Time new Roman", 14); c1FlexGrid1.Font = _font; for (int j = 1; j < c1FlexGrid1.Rows.Count; j++) { c1FlexGrid1[j, 0] = j; c1FlexGrid1[j, "tt"] = 0; //Kiểm tra có phải bản ghi từ hóa đơn không để ko cho sửa ngày thanh toán DateTime datetemp = Convert.ToDateTime(c1FlexGrid1[j, "ngaytt"].ToString().Trim()); if (ctr.CheckExit(sidpn, datetemp) == true) { c1FlexGrid1.Rows[j].AllowEditing = false; } else { c1FlexGrid1.Rows[j].AllowEditing = true; } } c1FlexGrid1.Cols[0].TextAlign = TextAlignEnum.CenterCenter; c1FlexGrid1.AutoSizeCols(); c1FlexGrid1.AutoSizeRows(); }
private List <tienthanhtoanphieunhap> GetListTienThanhToan() { tblphieunhapkhoBL ctrphieunhap = new tblphieunhapkhoBL(); tblphieunhapkho objphieunhap = new tblphieunhapkho(); objphieunhap = ctrphieunhap.GetByID(sidpn); try { List <tienthanhtoanphieunhap> lst = new List <tienthanhtoanphieunhap>(); for (int i = 1; i < c1FlexGrid1.Rows.Count; i++) { tienthanhtoanphieunhap obj = new tienthanhtoanphieunhap(); if (c1FlexGrid1[i, "tt"].ToString().Trim().Equals("0") == false) { if (c1FlexGrid1[i, "tt"].ToString().Trim().Equals("1") == true) { obj.id = Guid.NewGuid().ToString(); } else if (c1FlexGrid1[i, "tt"].ToString().Trim().Equals("2") == true) { obj.id = c1FlexGrid1[i, "id"].ToString().Trim(); } if (sidpn.Trim().Equals("") == true) { MessageBox.Show("Không lấy được thông tin hóa đơn.\nVui lòng tắt chương trình và khởi động lại.", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); c1FlexGrid1.Select(i, c1FlexGrid1.Cols["tientt"].Index); return(null); } try { obj.tientt = Convert.ToDouble(c1FlexGrid1[i, "tientt"].ToString().Trim()); } catch { MessageBox.Show("Tiền thanh toán nhập không đúng", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); c1FlexGrid1.Select(i, c1FlexGrid1.Cols["tientt"].Index); return(null); } if (obj.tientt == 0) { MessageBox.Show("Tiền thanh toán phải lớn hơn 0", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); c1FlexGrid1.Select(i, c1FlexGrid1.Cols["tientt"].Index); return(null); } obj.idpn = sidpn; obj.ngaytt = Convert.ToDateTime(c1FlexGrid1[i, "ngaytt"].ToString().Trim()); if (objphieunhap.ngaytao == obj.ngaytt) { MessageBox.Show("Bản ghi này đã tồn tại.\nVui lòng nhập lại ngày thanh toán", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); c1FlexGrid1.Select(i, c1FlexGrid1.Cols["ngaytt"].Index); return(null); } obj.ghichu = c1FlexGrid1[i, "ghichu"].ToString().Trim(); lst.Add(obj); } } return(lst); } catch { return(null); } }
private void HienThiTT() { try { tblphieunhapkho obj = new tblphieunhapkho(); tblphieunhapkhoBL ctr = new tblphieunhapkhoBL(); obj = ctr.GetByID(txtID.Text.Trim()); dpkNgayNhap.Value = obj.ngaytao; cbNhaCC.SelectedValue = obj.id_nguoicap; txtChietKhau.Text = obj.chietkhau.ToString("N0", CultureInfo.InvariantCulture); txtTienThanhToan.Text = obj.tienthanhtoan.ToString("N0", CultureInfo.InvariantCulture); dpkNgayNhap.Value = obj.ngaytao; txtNoToaTruoc.Text = ctr.GetTienConNo(obj.id_nguoicap, obj.ngaytao).ToString("N0", CultureInfo.InvariantCulture); txtGhiChu.Text = obj.ghichu.Trim(); txtNoiNhap.Text = obj.noinhap.Trim(); } catch { HienThiDSMatHang(); } }
private void cbNhaCC_SelectedIndexChanged(object sender, EventArgs e) { tblphieunhapkhoBL ctrpn = new tblphieunhapkhoBL(); string sidnhacc = ""; try { sidnhacc = cbNhaCC.SelectedValue.ToString().Trim(); } catch { } nhacungcap obj = new nhacungcap(); nhacungcapBL ctr = new nhacungcapBL(); obj = ctr.GetByID(sidnhacc); try { try { txtNoToaTruoc.Text = ctrpn.GetTienConNo(sidnhacc, dpkNgayNhap.Value).ToString("N0", CultureInfo.InvariantCulture); } catch { txtNoToaTruoc.Text = "0"; } txtDiaChi.Text = obj.diachi; txtDienThoai.Text = obj.dienthoai.Trim(); double tongtien = 0; try { tongtien = Convert.ToDouble(txtTongTien.Text); } catch { } double tienconno = 0; try { tienconno = Convert.ToDouble(txtNoToaTruoc.Text); } catch { } double tientt = 0; try { tientt = Convert.ToDouble(txtTienThanhToan.Text); } catch { } double chietkhau = 0; try { chietkhau = Convert.ToDouble(txtChietKhau.Text); } catch { } txtConNo.Text = ((tienconno + tongtien) - (tientt + chietkhau)).ToString("N0", CultureInfo.InvariantCulture); } catch { txtDiaChi.Text = ""; txtDienThoai.Text = ""; txtTongTien.Text = "0"; } }
private void HienThiTTPhieuNhap() { tblphieunhapkho objpn = new tblphieunhapkho(); tblphieunhapkhoBL ctrpn = new tblphieunhapkhoBL(); objpn = ctrpn.GetByID(sidpn); try{ nhacungcap objnhacc = new nhacungcap(); nhacungcapBL ctrnhacc = new nhacungcapBL(); objnhacc = ctrnhacc.GetByID(objpn.id_nguoicap.Trim()); lbDiaChi.Text = objnhacc.diachi; lbDienThoai.Text = objnhacc.dienthoai; lbNgayXuat.Text = objpn.ngaytao.ToString("dd/MM/yyyy HH:mm:ss"); lbTenKH.Text = objnhacc.ten; } catch { lbDiaChi.Text = "-/-"; lbDienThoai.Text = "-/-"; lbNgayXuat.Text = "-/-"; lbTenKH.Text = "-/-"; } }
private void Save() { string kq = ""; tienthanhtoanphieunhapBL ctrtientt = new tienthanhtoanphieunhapBL(); tblmathangBL ctrmathang = new tblmathangBL(); tblphieunhapkhoBL ctrphieu = new tblphieunhapkhoBL(); tblphieunhapkho objphieu = new tblphieunhapkho(); objphieu = GetDataPhieuNhap(); tblhangnhapkhoBL ctrmathangnhap = new tblhangnhapkhoBL(); List<tblhangnhapkho> lstmathang = new List<tblhangnhapkho>(); lstmathang = GetListMatHang(); if (objphieu != null && lstmathang != null) { if (txtID.Text.Trim().Equals("-1") == true) { kq = ctrphieu.Insert(objphieu); if (kq.Trim().Equals("") == true) { tienthanhtoanphieunhap objtientt = new tienthanhtoanphieunhap(); objtientt.id = Guid.NewGuid().ToString().Trim(); objtientt.idpn = objphieu.id; objtientt.ngaytt = objphieu.ngaytao; objtientt.tientt = objphieu.tienthanhtoan; ctrtientt.Insert(objtientt); } } else { kq = ctrphieu.Update(objphieu); tienthanhtoanphieunhap objtientt = new tienthanhtoanphieunhap(); objtientt = ctrtientt.GetByIDPNvsNgayTT(objphieu.id, objphieu.ngaytao); if (objtientt != null) { objtientt.tientt = objphieu.tienthanhtoan; ctrtientt.Update(objtientt); } else { objtientt = new tienthanhtoanphieunhap(); objtientt.id = Guid.NewGuid().ToString().Trim(); objtientt.idpn = objphieu.id; objtientt.ngaytt = objphieu.ngaytao; objtientt.tientt = objphieu.tienthanhtoan; ctrtientt.Insert(objtientt); } _ctrlog.Append(Data.use, "Sửa phiếu nhập kho của nhà cung cấp: " + cbNhaCC.Text.Trim() + " xuất ngày: " + dpkNgayNhap.Value.ToString("dd/MM/yyyy").Trim() + "; id: " + objphieu.id + ";\nChi tiết: Tổng tiền hàng: " + txtTongTien.Text + " - Nợ cũ: " + txtNoToaTruoc.Text + " - Tiền thanh toán: " + txtTienThanhToan.Text + " - Tổng nợ mới: " + txtConNo.Text); } if (kq.Trim().Equals("") == true) { if (lstmathang != null) { if (objphieu != null && lstmathang.Count > 0) { for (int i = 0; i < lstmathang.Count; i++) { tblhangnhapkho temp = new tblhangnhapkho(); temp = ctrmathangnhap.GetByID(lstmathang[i].id); if (temp == null) { lstmathang[i].id_phieunhapkho = objphieu.id; kq = ctrmathangnhap.Insert(lstmathang[i]); if (kq.Trim().Equals("") == false) { ctrphieu.Delete(objphieu.id); break; } else //Thêm số lượng vào trong kho { tblmathang objmathang = new tblmathang(); objmathang = ctrmathang.GetByID(lstmathang[i].id_mathang.Trim()); objmathang.soluong = objmathang.soluong + lstmathang[i].soluong; objmathang.gianhap = lstmathang[i].gianhap; ctrmathang.Update(objmathang); } } else { lstmathang[i].id_phieunhapkho = objphieu.id; kq = ctrmathangnhap.Update(lstmathang[i]); if (kq.Trim().Equals("") == false) { break; } else //Cập nhật lại số lượng còn trong kho { tblmathang objmathang = new tblmathang(); objmathang = ctrmathang.GetByID(lstmathang[i].id_mathang.Trim()); objmathang.soluong = (objmathang.soluong - temp.soluong) + lstmathang[i].soluong; objmathang.gianhap = lstmathang[i].gianhap; ctrmathang.Update(objmathang); } } } if (kq.Trim().Equals("") == false) { MessageBox.Show("Lỗi cập nhật phiếu nhập hàng.\nChi tiết lỗi: " + kq, "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } else { if (txtID.Text.Trim().Equals("-1") == true) { txtID.Text = objphieu.id.Trim(); _ctrlog.Append(Data.use, "Thêm mới phiếu nhập hàng của nhà cung cấp: " + cbNhaCC.Text.Trim() + " xuất ngày: " + dpkNgayNhap.Value.ToString("dd/MM/yyyy").Trim() + "; id: " + objphieu.id + ";\nChi tiết: Tổng tiền hàng: " + txtTongTien.Text + " - Nợ cũ: " + txtNoToaTruoc.Text + " - Tiền thanh toán: " + txtTienThanhToan.Text + " - Tổng nợ mới: " + txtConNo.Text); } } } } } else { MessageBox.Show("Lỗi cập nhật phiếu nhập hàng.\nChi tiết lỗi: " + kq, "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } if (kq.Trim().Equals("") == true && lstmathang != null) { MessageBox.Show("Cập nhật phiếu nhập hàng thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); HienThiTT(); HienThiDSMatHang(); ultraToolbarsManager1.Tools["btn_Del"].SharedProps.Visible = true; } }
private string GenerateWorksheetTKCongNo(WorksheetCollection sheets, DateTime dtdenngay, DataTable dtnhacc, ProgressBar progressBar) { try { tblphieunhapkhoBL ctrpn = new tblphieunhapkhoBL(); tblphieunhapkho objpn = new tblphieunhapkho(); tblhangnhapkhoBL ctrhangnhapkho = new tblhangnhapkhoBL(); tienthanhtoanphieunhapBL ctrtiendatt = new tienthanhtoanphieunhapBL(); Worksheet sheet = sheets.Add("TKCongNoNhapHang"); sheet.Table.DefaultRowHeight = 15F; sheet.Table.ExpandedColumnCount = 5; sheet.Table.ExpandedRowCount = 5 + dtnhacc.Rows.Count; sheet.Table.FullColumns = 1; sheet.Table.FullRows = 1; sheet.Table.Columns.Add(36); sheet.Table.Columns.Add(193); sheet.Table.Columns.Add(149); sheet.Table.Columns.Add(191); sheet.Table.Columns.Add(159); // ----------------------------------------------- #region Add Header WorksheetRow Row0 = sheet.Table.Rows.Add(); Row0.Height = 20; Row0.AutoFitHeight = false; WorksheetCell cell; cell = Row0.Cells.Add(); cell.StyleID = "s75"; cell.Data.Type = DataType.String; cell.Data.Text = "TỔNG HỢP CÔNG NỢ NHẬP HÀNG"; cell.MergeAcross = 4; // ----------------------------------------------- WorksheetRow Row1 = sheet.Table.Rows.Add(); Row1.AutoFitHeight = false; cell = Row1.Cells.Add(); cell.StyleID = "s76"; cell.Data.Type = DataType.String; cell.Data.Text = "(Số liệu tính đến ngày " + dtdenngay.ToString("dd/MM/yyyy") + ")"; cell.MergeAcross = 4; // ----------------------------------------------- WorksheetRow Row2 = sheet.Table.Rows.Add(); Row2.AutoFitHeight = false; cell = Row2.Cells.Add(); cell.StyleID = "m83608040"; cell.Data.Type = DataType.String; cell.Data.Text = "Đơn vị tính: VNĐ"; cell.MergeAcross = 4; // ----------------------------------------------- WorksheetRow Row3 = sheet.Table.Rows.Add(); Row3.AutoFitHeight = false; Row3.Cells.Add("Stt", DataType.String, "s67"); Row3.Cells.Add("Nhà cung cấp", DataType.String, "s67"); Row3.Cells.Add("Điện thoại", DataType.String, "s67"); Row3.Cells.Add("Địa chỉ", DataType.String, "s67"); Row3.Cells.Add("Tổng tiền còn nợ", DataType.String, "s67"); #endregion // ----------------------------------------------- #region Add Content for (int i = 0; i < dtnhacc.Rows.Count; i++) { Application.DoEvents(); progressBar.PerformStep(); Application.DoEvents(); string sidnhacc = ""; try { sidnhacc = dtnhacc.Rows[i]["id"].ToString().Trim(); } catch { sidnhacc = "-/-"; } string stennhacc = ""; try { stennhacc = dtnhacc.Rows[i]["ten"].ToString().Trim(); } catch { stennhacc = "-/-"; } string sdt = ""; try { sdt = dtnhacc.Rows[i]["dienthoai"].ToString().Trim(); } catch { sdt = "-/-"; } string sdiachi = ""; try { sdiachi = dtnhacc.Rows[i]["diachi"].ToString().Trim(); } catch { sdiachi = "-/-"; } if (sidnhacc.Trim().Equals("") == false) { // Lấy hóa đơn gần với ngày thống kê nhất objpn = new tblphieunhapkho(); Application.DoEvents(); progressBar.PerformStep(); Application.DoEvents(); objpn = ctrpn.GetNewFirstByNgayTaovsIDKH(dtdenngay.AddDays(1).ToString("yyyy/MM/dd").Trim(), sidnhacc); if (objpn != null) { double tienmuahang = 0; try { tienmuahang = ctrhangnhapkho.GetTongTienByIDPN(objpn.id); } catch { } //double tientt = 0; //tientt = objpn.tienthanhtoan; double chietkhau = 0; chietkhau = objpn.chietkhau; double tiendatt = 0; try { tiendatt = ctrtiendatt.GetTienDaThanhToan(objpn.id); } catch { } double tienconnotoatruoc = 0; try { tienconnotoatruoc = ctrpn.GetTienConNo(objpn.id_nguoicap, objpn.ngaytao); } catch { } double tienconno = 0; tienconno = ((tienmuahang - tiendatt - chietkhau) + tienconnotoatruoc); Application.DoEvents(); progressBar.PerformStep(); Application.DoEvents(); WorksheetRow Row = sheet.Table.Rows.Add(); Row.Cells.Add((i + 1).ToString(), DataType.Number, "s68"); Row.Cells.Add(stennhacc, DataType.String, "s69"); Row.Cells.Add(sdt, DataType.String, "s69"); Row.Cells.Add(sdiachi, DataType.String, "s69"); Row.Cells.Add(tienconno.ToString().Trim(), DataType.Number, "s70"); } } } #endregion // ----------------------------------------------- #region Tính tổng các dòng WorksheetRow Row7 = sheet.Table.Rows.Add(); Row7.AutoFitHeight = false; cell = Row7.Cells.Add(); cell.StyleID = "m83608060"; cell.Data.Type = DataType.String; cell.Data.Text = "TỔNG CỘNG"; cell.MergeAcross = 3; cell = Row7.Cells.Add(); cell.StyleID = "s74"; cell.Data.Type = DataType.Number; cell.Formula = "=SUM(R[-" + dtnhacc.Rows.Count.ToString() + "]C:R[-1]C)"; #endregion // ----------------------------------------------- // Options // ----------------------------------------------- sheet.Options.Selected = true; sheet.Options.ProtectObjects = false; sheet.Options.ProtectScenarios = false; sheet.Options.PageSetup.Header.Margin = 0.3F; sheet.Options.PageSetup.Footer.Margin = 0.3F; sheet.Options.PageSetup.PageMargins.Bottom = 0.75F; sheet.Options.PageSetup.PageMargins.Left = 0.7F; sheet.Options.PageSetup.PageMargins.Right = 0.7F; sheet.Options.PageSetup.PageMargins.Top = 0.75F; sheet.Options.Print.HorizontalResolution = 300; sheet.Options.Print.VerticalResolution = 0; sheet.Options.Print.ValidPrinterInfo = true; return(""); } catch (Exception ex) { return(ex.Message); } }