public void CheckConflictUpdate() { try { cl = new Server_Client.Client(); // gán TCPclient this.client1 = cl.Connect(Luu.IP, Luu.Ports); // khởi tạo biến truyền vào với hàm khởi tạo Entities.TKKeToan pb = new Entities.TKKeToan("Select"); // khởi tạo mảng đối tượng để hứng giá trị tk1 = new Entities.TKKeToan[1]; clientstream = cl.SerializeObj(this.client1, "TKKeToan", pb); // đổ mảng đối tượng vào datagripview tk1 = (Entities.TKKeToan[])cl.DeserializeHepper1(clientstream, tk1); if (tk1 != null) { for (int j = 0; j < tk1.Length; j++) { if (tk1[j].MaTKKeToan == maTK) { kt = Check(tk1[j]); break; } else { kt = "ok"; } } } } catch { } }
public void Delete(Entities.TKKeToan tk1) { try { TKKT = new Constants.TKKeToan(); Entities.TKKeToan phieuthu = new Entities.TKKeToan(); Sql = new Constants.Sql(); string sql = Sql.DeleteTKKeToan; Connection conn = new Connection(); SqlConnection cn = conn.openConnection(); SqlCommand cmd = new SqlCommand(sql, cn); cmd.Parameters.Add(TKKT.HanhDong, SqlDbType.NVarChar, 20).Value = tk1.HanhDong; cmd.Parameters.Add(TKKT.TKKeToanID, SqlDbType.Int).Value = tk1.TKKeToanID; cmd.ExecuteNonQuery(); cmd.Connection.Dispose(); cn.Close(); conn.closeConnection(); cn = null; conn = null; } catch (Exception ex) { string s = ex.Message; } }
public int InsertUpdate(Entities.TKKeToan tk1) { TKKT = new Constants.TKKeToan(); Sql = new Constants.Sql(); string sql = Sql.InsertUpdateTKKeToan; Connection conn = new Connection(); SqlConnection cn = conn.openConnection(); SqlCommand cmd = new SqlCommand(sql, cn); cmd.Parameters.Add(TKKT.HanhDong, SqlDbType.NVarChar, 20).Value = tk1.HanhDong; cmd.Parameters.Add(TKKT.TKKeToanID, SqlDbType.Int).Value = tk1.TKKeToanID; cmd.Parameters.Add(TKKT.MaTKKeToan, SqlDbType.NVarChar, 20).Value = tk1.MaTKKeToan; cmd.Parameters.Add(TKKT.MaNhomTKKT, SqlDbType.NVarChar, 20).Value = tk1.NhomTKKT; cmd.Parameters.Add(TKKT.TenTaiKhoan, SqlDbType.NVarChar, 200).Value = tk1.TenTaiKhoan; cmd.Parameters.Add(TKKT.GhiChu, SqlDbType.NVarChar, 100).Value = tk1.GhiChu; cmd.Parameters.Add(TKKT.Deleted, SqlDbType.Bit).Value = tk1.Deleted; int i = cmd.ExecuteNonQuery(); cmd.Connection.Dispose(); cn.Close(); conn.closeConnection(); cn = null; conn = null; return(i); }
private void tsslThem_Click(object sender, EventArgs e) { if (Validate()) { CheckConflictInsert(); if (kt == "ok") { Server_Client.Client cl = new Server_Client.Client(); this.client1 = cl.Connect(Luu.IP, Luu.Ports); NhomTKKeToan ntk = (NhomTKKeToan)cbbNhomTK.SelectedItem; Entities.TKKeToan tkkt = new Entities.TKKeToan("Insert", 1, txtmatkkt.Text, txttentkkt.Text, ntk.MaNhomTKKeToan, txtghichu.Text, false, Common.Utilities.User.NhanVienID, Common.Utilities.User.TenDangNhap); clientstream = cl.SerializeObj(this.client1, "TKKeToan", tkkt); int msg = 0; msg = (int)cl.DeserializeHepper(clientstream, msg); if (msg == 1) { txttentkkt.Text = ""; txtmatkkt.Text = ""; txtghichu.Text = ""; cbbNhomTK.Text = ""; frmQuanLyTaiKhoanKeToan.KiemTra = "insert"; this.Close(); } else { MessageBox.Show("Insert that bai"); } } } }
public Entities.TKKeToan[] Select() { Entities.TKKeToan[] arrC = null; try { TKKT = new Constants.TKKeToan(); Sql = new Constants.Sql(); string sql = Sql.SelectAllTKKeToan; conn = new Connection(); cn = conn.openConnection(); cmd = new SqlCommand(sql, cn); dr = cmd.ExecuteReader(CommandBehavior.CloseConnection); arr = new ArrayList(); while (dr.Read()) { Entities.TKKeToan tkketoan = new Entities.TKKeToan(); tkketoan.TKKeToanID = Convert.ToInt32(dr[TKKT.TKKeToanID].ToString()); tkketoan.MaTKKeToan = dr[TKKT.MaTKKeToan].ToString(); tkketoan.TenTaiKhoan = dr[TKKT.TenTaiKhoan].ToString(); tkketoan.NhomTKKT = dr[TKKT.MaNhomTKKT].ToString(); tkketoan.GhiChu = dr[TKKT.GhiChu].ToString(); tkketoan.Deleted = (Boolean)dr[TKKT.Deleted]; arr.Add(tkketoan); } int n = arr.Count; if (n == 0) { return(null); } arrC = new Entities.TKKeToan[n]; for (int i = 0; i < n; i++) { arrC[i] = (Entities.TKKeToan)arr[i]; } } catch (Exception ex) { string s = ex.Message.ToString(); } finally { cmd.Connection.Dispose(); cn.Close(); conn.closeConnection(); } return(arrC); }
/// <summary> /// Lấy Nợ Tài Khoản /// </summary> /// <returns></returns> public Entities.TKKeToan[] LayNoTK() { Entities.TKKeToan[] arrC = null; try { TKKT = new Constants.TKKeToan(); Sql = new Constants.Sql(); string sql = Sql.LayNoTK; conn = new Connection(); cn = conn.openConnection(); cmd = new SqlCommand(sql, cn); dr = cmd.ExecuteReader(CommandBehavior.CloseConnection); arr = new ArrayList(); while (dr.Read()) { Entities.TKKeToan tkketoan = new Entities.TKKeToan(); tkketoan.MaTKKeToan = dr[TKKT.MaTKKeToan].ToString(); Boolean kt = tkketoan.Deleted = (Boolean)dr[TKKT.Deleted]; if (kt == false) { arr.Add(tkketoan); } } int n = arr.Count; if (n == 0) { return(null); } arrC = new Entities.TKKeToan[n]; for (int i = 0; i < n; i++) { arrC[i] = (Entities.TKKeToan)arr[i]; } } catch { } finally { cmd.Connection.Dispose(); cn.Close(); conn.closeConnection(); } return(arrC); }
public void CheckConflictInsert() { try { cl = new Server_Client.Client(); // gán TCPclient this.client1 = cl.Connect(Luu.IP, Luu.Ports); // khởi tạo biến truyền vào với hàm khởi tạo Entities.TKKeToan pb = new Entities.TKKeToan("Select"); // khởi tạo mảng đối tượng để hứng giá trị Entities.TKKeToan[] tk1 = new Entities.TKKeToan[1]; clientstream = cl.SerializeObj(this.client1, "TKKeToan", pb); // đổ mảng đối tượng vào datagripview tk1 = (Entities.TKKeToan[])cl.DeserializeHepper1(clientstream, tk1); if (tk1 != null) { for (int j = 0; j < tk1.Length; j++) { if (tk1[j].MaTKKeToan == txtmatkkt.Text) { MessageBox.Show("Mã tài khoản đã có trong dữ liệu - mời nhập lại để insert"); kt = "ko"; txtmatkkt.Text = ""; break; } else { kt = "ok"; } } } else { kt = "ok"; } } catch { } }
private void tsslSua_Click(object sender, EventArgs e) { if (Validate()) { CheckConflictUpdate(); if (kt == "ok") { Server_Client.Client cl = new Server_Client.Client(); this.client1 = cl.Connect(Luu.IP, Luu.Ports); NhomTKKeToan ntk = (NhomTKKeToan)cbbNhomTK.SelectedItem; Entities.TKKeToan tkkt1 = new Entities.TKKeToan("Update", Convert.ToInt32(txtID.Text), txtmatkkt.Text.Trim(), txttentkkt.Text.Trim(), ntk.MaNhomTKKeToan.Trim(), txtghichu.Text.Trim(), false, Common.Utilities.User.NhanVienID, Common.Utilities.User.TenDangNhap); clientstream = cl.SerializeObj(this.client1, "TKKeToan", tkkt1); int msg = 0; try { msg = (int)cl.DeserializeHepper(clientstream, msg); } catch { } if (msg == 1) { // MessageBox.Show("Update thanh cong ..."); this.Close(); } else { MessageBox.Show("Cập nhật thất bại!\r\nvui lòng kiểm tra lại đường truyền tới server hoặc tài khoản kế toán đang được sử dụng không thể sửa hoặc xóa!"); } tentk = txttentkkt.Text; ghichu = txtghichu.Text; } else if (kt == "null") { MessageBox.Show("Bản Ghi đã bị xóa trước khi cập nhật! Vui lòng thao tác lại !"); this.Close(); } } }
public string Check(Entities.TKKeToan tk) { string gt = "ok"; if (tentk != tk.TenTaiKhoan) { tentk = txttentkkt.Text = tk.TenTaiKhoan; gt = "ko"; } if (ghichu != tk.GhiChu) { ghichu = txtghichu.Text = tk.GhiChu; gt = "ko"; } if (gt == "ko") { MessageBox.Show("Dữ liệu đã có thay đổi trước, ấn ok để cập nhật lại."); } return(gt); }
private void tsslThem_Click(object sender, EventArgs e) { if (Validate()) { CheckConflictInsert(); if (kt == "ok") { Server_Client.Client cl = new Server_Client.Client(); this.client1 = cl.Connect(Luu.IP, Luu.Ports); NhomTKKeToan ntk = (NhomTKKeToan)cbbNhomTK.SelectedItem; Entities.TKKeToan tkkt = new Entities.TKKeToan("Insert", 1, txtmatkkt.Text, txttentkkt.Text, ntk.MaNhomTKKeToan, txtghichu.Text, false,Common.Utilities.User.NhanVienID, Common.Utilities.User.TenDangNhap); clientstream = cl.SerializeObj(this.client1, "TKKeToan", tkkt); int msg = 0; msg = (int)cl.DeserializeHepper(clientstream, msg); if (msg == 1) { txttentkkt.Text = ""; txtmatkkt.Text = ""; txtghichu.Text = ""; cbbNhomTK.Text = ""; frmQuanLyTaiKhoanKeToan.KiemTra = "insert"; this.Close(); } else MessageBox.Show("Insert that bai"); } } }
private void txtTimKiem_TextChanged(object sender, EventArgs e) { if (rdbTen.Checked == true) { if (TKKT_Search == null) { TKKeToan[] tkkt = new TKKeToan[0]; dataGridView1.DataSource = tkkt; FixDataGridView(); toolStripStatus_Sua.Enabled = false; toolStripStatus_Xoa.Enabled = false; } else if (TKKT_Search != null) { if (txtTimKiem.Text.Length == 0) { TKKeToan[] tkkt = new TKKeToan[0]; dataGridView1.DataSource = tkkt; FixDataGridView(); toolStripStatus_Sua.Enabled = false; toolStripStatus_Xoa.Enabled = false; } else { int TKKT1_search_count = 0; for (int i = 0; i < TKKT_Search.Length; i++) { int index = -1; index = TKKT_Search[i].TenTaiKhoan.ToLower().IndexOf(txtTimKiem.Text.Trim().ToLower()); if (index >= 0) { TKKT1_search_count++; } } TKKeToan[] TKKT1_search = new TKKeToan[TKKT1_search_count]; TKKT1_search_count = 0; for (int i = 0; i < TKKT_Search.Length; i++) { int index = -1; index = TKKT_Search[i].TenTaiKhoan.ToLower().IndexOf(txtTimKiem.Text.Trim().ToLower()); if (index >= 0) { TKKT1_search[TKKT1_search_count] = TKKT_Search[i]; TKKT1_search_count++; } } if (TKKT1_search_count == 0) { toolStripStatus_Sua.Enabled = false; toolStripStatus_Xoa.Enabled = false; } else { toolStripStatus_Sua.Enabled = true; toolStripStatus_Xoa.Enabled = true; } dataGridView1.DataSource = TKKT1_search; FixDataGridView(); } } } else if (rdbMa.Checked == true) { if (TKKT_Search == null) { TKKeToan[] tkkt = new TKKeToan[0]; dataGridView1.DataSource = tkkt; FixDataGridView(); toolStripStatus_Sua.Enabled = false; toolStripStatus_Xoa.Enabled = false; } else if (TKKT_Search != null) { if (txtTimKiem.Text.Length == 0) { TKKeToan[] tkkt = new TKKeToan[0]; dataGridView1.DataSource = tkkt; FixDataGridView(); toolStripStatus_Sua.Enabled = false; toolStripStatus_Xoa.Enabled = false; } else { int NV1_Search_count = 0; for (int i = 0; i < TKKT_Search.Length; i++) { int index = -1; index = TKKT_Search[i].MaTKKeToan.ToLower().IndexOf(txtTimKiem.Text.Trim().ToLower()); if (index >= 0) { NV1_Search_count++; } } TKKeToan[] NV1_search = new TKKeToan[NV1_Search_count]; NV1_Search_count = 0; for (int i = 0; i < TKKT_Search.Length; i++) { int index = -1; index = TKKT_Search[i].MaTKKeToan.ToLower().IndexOf(txtTimKiem.Text.Trim().ToLower()); if (index >= 0) { NV1_search[NV1_Search_count] = TKKT_Search[i]; NV1_Search_count++; } } if (NV1_Search_count == 0) { toolStripStatus_Sua.Enabled = false; toolStripStatus_Xoa.Enabled = false; } else { toolStripStatus_Sua.Enabled = true; toolStripStatus_Xoa.Enabled = true; } dataGridView1.DataSource = NV1_search; FixDataGridView(); } } } }
private void toolStripStatus_Xoa_Click(object sender, EventArgs e) { if (!frmDangNhap.User.Administrator && !CheckQuyen(this.Name, 3)) { MessageBox.Show("Bạn Không có quyền vào chức năng này."); return; } DialogResult dlgResult = MessageBox.Show("Bạn Có Chắc Chắn muốn Xóa không?", "Đồng ý?", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (dlgResult == DialogResult.Yes) { try { bool ktdelete = false; int idcurent = int.Parse(dataGridView1.CurrentRow.Cells["TKKeToanID"].Value.ToString()); string maCurrent=dataGridView1.CurrentRow.Cells["MaTKKeToan"].Value.ToString(); hienthi(); for (int j = 0; j < TKKT_Search.Length; j++) { if (TKKT_Search[j].Deleted == false) if (TKKT_Search[j].TKKeToanID == idcurent) { ktdelete = true; break; } } if (ktdelete == true) { try { if (new Check().CheckReference("TKKeToan",maCurrent )) { Server_Client.Client cl = new Server_Client.Client(); this.client1 = cl.Connect(Luu.IP, Luu.Ports); Entities.TKKeToan tkkt = new TKKeToan("Delete", idcurent,maCurrent, "", "", "", false,Common.Utilities.User.NhanVienID,Common.Utilities.User.TenDangNhap); clientstrem = cl.SerializeObj(this.client1, "TKKeToan", tkkt); //MessageBox.Show("Xoa Thanh Cong..."); } else { MessageBox.Show("Tài Khoản Kế Toán Này Hiện Đang Có Giao Dịch - Không Thể Xóa","Hệ thống cảnh báo"); } } catch { } } hienthi(); } catch (Exception ex) { MessageBox.Show("Lỗi Hệ Thống- Liên Hệ nhà Quản Trị"); } } }
public void hienthi() { Server_Client.Client cl = new Server_Client.Client(); this.client1 = cl.Connect(Luu.IP, Luu.Ports); ntkkt = new TKKeToan("Select"); clientstrem = cl.SerializeObj(this.client1, "TKKeToan", ntkkt); TKKeToan[] pb1 = new TKKeToan[1]; pb1[0] = new TKKeToan(1, "a", "a", "a", "a", false); pb1 = (TKKeToan[])cl.DeserializeHepper1(clientstrem, pb1); if (pb1 == null) { Entities.TKKeToan [] tk= new TKKeToan [0]; TKKT_Search = tk; dataGridView1.DataSource = tk; FixDataGridView(); toolStripStatus_Sua.Enabled = false; toolStripStatus_Xoa.Enabled = false; } else { TKKT_Search = pb1; dataGridView1.DataSource = pb1; FixDataGridView(); toolStripStatus_Sua.Enabled = true; toolStripStatus_Xoa.Enabled = true; } }
public void CheckConflictInsert() { try { cl = new Server_Client.Client(); // gán TCPclient this.client1 = cl.Connect(Luu.IP, Luu.Ports); // khởi tạo biến truyền vào với hàm khởi tạo Entities.TKKeToan pb = new Entities.TKKeToan("Select"); // khởi tạo mảng đối tượng để hứng giá trị Entities.TKKeToan[] tk1 = new Entities.TKKeToan[1]; clientstream = cl.SerializeObj(this.client1, "TKKeToan", pb); // đổ mảng đối tượng vào datagripview tk1 = (Entities.TKKeToan[])cl.DeserializeHepper1(clientstream, tk1); if (tk1 != null) { for (int j = 0; j < tk1.Length; j++) { if (tk1[j].MaTKKeToan == txtmatkkt.Text) { MessageBox.Show("Mã tài khoản đã có trong dữ liệu - mời nhập lại để insert"); kt = "ko"; txtmatkkt.Text = ""; break; } else kt = "ok"; } } else kt = "ok"; } catch { } }
public Entities.TKKeToan[] Select() { Entities.TKKeToan[] arrC = null; try { TKKT = new Constants.TKKeToan(); Sql = new Constants.Sql(); string sql = Sql.SelectAllTKKeToan; conn = new Connection(); cn = conn.openConnection(); cmd = new SqlCommand(sql, cn); dr = cmd.ExecuteReader(CommandBehavior.CloseConnection); arr = new ArrayList(); while (dr.Read()) { Entities.TKKeToan tkketoan = new Entities.TKKeToan(); tkketoan.TKKeToanID = Convert.ToInt32(dr[TKKT.TKKeToanID].ToString()); tkketoan.MaTKKeToan = dr[TKKT.MaTKKeToan].ToString(); tkketoan.TenTaiKhoan = dr[TKKT.TenTaiKhoan].ToString(); tkketoan.NhomTKKT = dr[TKKT.MaNhomTKKT].ToString(); tkketoan.GhiChu = dr[TKKT.GhiChu].ToString(); tkketoan.Deleted = (Boolean)dr[TKKT.Deleted]; arr.Add(tkketoan); } int n = arr.Count; if (n == 0) { return null; } arrC = new Entities.TKKeToan[n]; for (int i = 0; i < n; i++) { arrC[i] = (Entities.TKKeToan)arr[i]; } } catch (Exception ex) { string s = ex.Message.ToString(); } finally { cmd.Connection.Dispose(); cn.Close(); conn.closeConnection(); } return arrC; }
private void tsslSua_Click(object sender, EventArgs e) { if (Validate()) { CheckConflictUpdate(); if (kt == "ok") { Server_Client.Client cl = new Server_Client.Client(); this.client1 = cl.Connect(Luu.IP, Luu.Ports); NhomTKKeToan ntk = (NhomTKKeToan)cbbNhomTK.SelectedItem; Entities.TKKeToan tkkt1 = new Entities.TKKeToan("Update", Convert.ToInt32(txtID.Text), txtmatkkt.Text.Trim(), txttentkkt.Text.Trim(), ntk.MaNhomTKKeToan.Trim(), txtghichu.Text.Trim(), false, Common.Utilities.User.NhanVienID, Common.Utilities.User.TenDangNhap); clientstream = cl.SerializeObj(this.client1, "TKKeToan", tkkt1); int msg = 0; try { msg = (int)cl.DeserializeHepper(clientstream, msg); } catch { } if (msg == 1) { // MessageBox.Show("Update thanh cong ..."); this.Close(); } else MessageBox.Show("Cập nhật thất bại!\r\nvui lòng kiểm tra lại đường truyền tới server hoặc tài khoản kế toán đang được sử dụng không thể sửa hoặc xóa!"); tentk = txttentkkt.Text; ghichu = txtghichu.Text; } else if (kt=="null") { MessageBox.Show("Bản Ghi đã bị xóa trước khi cập nhật! Vui lòng thao tác lại !"); this.Close(); } } }
/// <summary> /// Lấy Nợ Tài Khoản /// </summary> /// <returns></returns> public Entities.TKKeToan[] LayNoTK() { Entities.TKKeToan[] arrC = null; try { TKKT = new Constants.TKKeToan(); Sql = new Constants.Sql(); string sql = Sql.LayNoTK; conn = new Connection(); cn = conn.openConnection(); cmd = new SqlCommand(sql, cn); dr = cmd.ExecuteReader(CommandBehavior.CloseConnection); arr = new ArrayList(); while (dr.Read()) { Entities.TKKeToan tkketoan = new Entities.TKKeToan(); tkketoan.MaTKKeToan = dr[TKKT.MaTKKeToan].ToString(); Boolean kt = tkketoan.Deleted = (Boolean)dr[TKKT.Deleted]; if (kt == false) { arr.Add(tkketoan); } } int n = arr.Count; if (n == 0) { return null; } arrC = new Entities.TKKeToan[n]; for (int i = 0; i < n; i++) { arrC[i] = (Entities.TKKeToan)arr[i]; } } catch { } finally { cmd.Connection.Dispose(); cn.Close(); conn.closeConnection(); } return arrC; }
public void CheckConflictUpdate() { try { cl = new Server_Client.Client(); // gán TCPclient this.client1 = cl.Connect(Luu.IP, Luu.Ports); // khởi tạo biến truyền vào với hàm khởi tạo Entities.TKKeToan pb = new Entities.TKKeToan("Select"); // khởi tạo mảng đối tượng để hứng giá trị tk1 = new Entities.TKKeToan[1]; clientstream = cl.SerializeObj(this.client1, "TKKeToan", pb); // đổ mảng đối tượng vào datagripview tk1 = (Entities.TKKeToan[])cl.DeserializeHepper1(clientstream, tk1); if (tk1 != null) { for (int j = 0; j < tk1.Length; j++) { if (tk1[j].MaTKKeToan == maTK) { kt = Check(tk1[j]); break; } else kt = "ok"; } } } catch { } }