public int InsertUpdate(Entities.KMThuChi km1) { try { Kmtc = new Constants.KMThuChi(); Sql = new Constants.Sql(); string sql = Sql.InsertUpdateKMThuChi; Connection conn = new Connection(); SqlConnection cn = conn.openConnection(); SqlCommand cmd = new SqlCommand(sql, cn); cmd.Parameters.Add(Kmtc.HanhDong, SqlDbType.NVarChar, 20).Value = km1.HanhDong; cmd.Parameters.Add(Kmtc.ThuChiID, SqlDbType.Int).Value = km1.ThuChiID; cmd.Parameters.Add(Kmtc.MaKhoanMuc, SqlDbType.NVarChar, 20).Value = km1.MaKhoanMuc; cmd.Parameters.Add(Kmtc.TenKhoanMuc, SqlDbType.NVarChar, 200).Value = km1.TenKhoanMuc; cmd.Parameters.Add(Kmtc.LoaiKM, SqlDbType.Bit).Value = km1.LoaiKM; cmd.Parameters.Add(Kmtc.DoiTuong, SqlDbType.NVarChar, 200).Value = km1.DoiTuong; cmd.Parameters.Add(Kmtc.NoTK, SqlDbType.VarChar, 20).Value = km1.NoTK; cmd.Parameters.Add(Kmtc.CoTK, SqlDbType.VarChar, 20).Value = km1.CoTK; cmd.Parameters.Add(Kmtc.GhiChu, SqlDbType.NVarChar, 200).Value = km1.GhiChu; cmd.Parameters.Add(Kmtc.Deleted, SqlDbType.Bit).Value = km1.Deleted; int i = cmd.ExecuteNonQuery(); cmd.Connection.Dispose(); cn.Close(); conn.closeConnection(); cn = null; conn = null; return(i); } catch (Exception ex) { string s = ex.Message; return(0); } }
public void Delete(Entities.KMThuChi km1) { try { Kmtc = new Constants.KMThuChi(); Entities.TKNganHang TKNganHang = new Entities.TKNganHang(); Sql = new Constants.Sql(); string sql = Sql.DeleteKMThuChi; Connection conn = new Connection(); SqlConnection cn = conn.openConnection(); SqlCommand cmd = new SqlCommand(sql, cn); cmd.Parameters.Add(Kmtc.HanhDong, SqlDbType.NVarChar, 20).Value = km1.HanhDong; cmd.Parameters.Add(Kmtc.ThuChiID, SqlDbType.Int).Value = km1.ThuChiID; cmd.ExecuteNonQuery(); cmd.Connection.Dispose(); cn.Close(); conn.closeConnection(); cn = null; conn = null; } catch (Exception ex) { string s = ex.Message; } }
private void tsslThem_Click(object sender, EventArgs e) { if (Validate()) { CheckConflictInsert(); if (kt == "ok") { cl = new Server_Client.Client(); this.client1 = cl.Connect(Luu.IP, Luu.Ports); string dt = ""; switch (cbbdoiTuong.Text) { case "Khách Hàng": { dt = "Khach Hang"; break; } case "Nhà Cung Cấp": { dt = "Nha Cung Cap"; break; } case "Nhân Viên": { dt = "Nhan Vien"; break; } } bool LoaiKhoanMuc; if (cbbLoaiKhoanMuc.SelectedIndex == 0) { LoaiKhoanMuc = true; } else { LoaiKhoanMuc = false; } Entities.KMThuChi pb = new Entities.KMThuChi("Insert", 1, txtmaKM.Text, txttenKM.Text, LoaiKhoanMuc, dt, "", "", txtghichu.Text, false, Common.Utilities.User.NhanVienID, Common.Utilities.User.TenDangNhap); clientstream = cl.SerializeObj(this.client1, "KMThuChi", pb); int msg = 0; msg = (int)cl.DeserializeHepper(clientstream, msg); if (msg != 1) { MessageBox.Show("Insert That Bai"); } txttenKM.Text = ""; txtghichu.Text = ""; cbbdoiTuong.SelectedIndex = -1; //cbbNoTK.SelectedIndex = -1; //cbbCoTK.SelectedIndex = -1; txtmaKM.Text = LayID("KMThuChi"); frmQuanlyKMthuchi.KiemTra = "insert"; this.Close(); } } }
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.KMThuChi pt = new Entities.KMThuChi("Select", 1, "", "", ""); // khởi tạo mảng đối tượng để hứng giá trị km1 = new Entities.KMThuChi[1]; clientstream = cl.SerializeObj(this.client1, "KMThuChi", pt); // đổ mảng đối tượng vào datagripview km1 = (Entities.KMThuChi[])cl.DeserializeHepper1(clientstream, km1); if (km1 != null) { for (int j = 0; j < km1.Length; j++) { if (km1[j].MaKhoanMuc == maKhoanMuc) { kt = Check(km1[j]); break; } else { kt = "null"; } } } } catch { } }
/// <summary> /// Lấy Khoản mục thu chi /// </summary> /// <param name="bl"></param> /// <returns></returns> public Entities.KMThuChi[] LayKMThuChi(Boolean bl) { Entities.KMThuChi[] arrC = null; try { Kmtc = new Constants.KMThuChi(); Sql = new Constants.Sql(); string sql = Sql.LayKMThuChi; conn = new Connection(); cn = conn.openConnection(); cmd = new SqlCommand(sql, cn); cmd.Parameters.Add("@Loai", SqlDbType.Bit).Value = bl; dr = cmd.ExecuteReader(CommandBehavior.CloseConnection); arr = new ArrayList(); while (dr.Read()) { Entities.KMThuChi kmtc = new Entities.KMThuChi(); kmtc.ThuChiID = Convert.ToInt32(dr[Kmtc.ThuChiID].ToString()); kmtc.MaKhoanMuc = dr[Kmtc.MaKhoanMuc].ToString(); kmtc.TenKhoanMuc = dr[Kmtc.TenKhoanMuc].ToString(); kmtc.LoaiKM = (bool)dr[Kmtc.LoaiKM]; kmtc.DoiTuong = dr[Kmtc.DoiTuong].ToString(); kmtc.NoTK = dr[Kmtc.NoTK].ToString(); kmtc.CoTK = dr[Kmtc.CoTK].ToString(); kmtc.GhiChu = dr[Kmtc.GhiChu].ToString(); Boolean kt = kmtc.Deleted = (Boolean)dr[Kmtc.Deleted]; if (kt == false) { arr.Add(kmtc); } } int n = arr.Count; if (n == 0) { return(null); } arrC = new Entities.KMThuChi[n]; for (int i = 0; i < n; i++) { arrC[i] = (Entities.KMThuChi)arr[i]; } } catch { } finally { cmd.Connection.Dispose(); cn.Close(); conn.closeConnection(); } return(arrC); }
public string Check(Entities.KMThuChi kmtc) { string gt = "ok"; if (tenKhoanMuc != kmtc.TenKhoanMuc) { tenKhoanMuc = txttenKM.Text = kmtc.TenKhoanMuc; gt = "ko"; } if (loaiKM != kmtc.LoaiKM) { loaiKM = kmtc.LoaiKM; if (loaiKM) { cbbLoaiKhoanMuc.SelectedIndex = 0; } else { cbbLoaiKhoanMuc.SelectedIndex = 1; } gt = "ko"; } if (doiTuong != kmtc.DoiTuong) { doiTuong = cbbdoiTuong.Text = kmtc.DoiTuong; gt = "ko"; } //if (noTK != kmtc.NoTK) //{ // noTK = cbbNoTK.Text = kmtc.NoTK; // gt = "ko"; //} //if (coTK != kmtc.CoTK) //{ // coTK = cbbCoTK.Text = kmtc.CoTK; // gt = "ko"; //} if (ghiChu != kmtc.GhiChu) { ghiChu = txtghichu.Text = kmtc.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); }
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.KMThuChi pt = new Entities.KMThuChi("Select", 1, "", "", ""); // khởi tạo mảng đối tượng để hứng giá trị Entities.KMThuChi[] pt1 = new Entities.KMThuChi[1]; clientstream = cl.SerializeObj(this.client1, "KMThuChi", pt); // đổ mảng đối tượng vào datagripview pt1 = (Entities.KMThuChi[])cl.DeserializeHepper1(clientstream, pt1); if (pt1 != null) { for (int j = 0; j < pt1.Length; j++) { if (pt1[j].MaKhoanMuc == txtmaKM.Text) { MessageBox.Show("cập nhật mã Khoản Mục - kiểm tra lại để insert"); kt = "ko"; txtmaKM.Text = LayID("KMThuChi"); break; } else { kt = "ok"; } } } else { kt = "ok"; } } catch { } }
public Entities.KMThuChi[] Select() { Entities.KMThuChi[] arrC = null; try { Kmtc = new Constants.KMThuChi(); Sql = new Constants.Sql(); string sql = Sql.SelectAllKMThuChi; conn = new Connection(); cn = conn.openConnection(); cmd = new SqlCommand(sql, cn); dr = cmd.ExecuteReader(CommandBehavior.CloseConnection); arr = new ArrayList(); while (dr.Read()) { Entities.KMThuChi kmtc = new Entities.KMThuChi(); kmtc.ThuChiID = Convert.ToInt32(dr[Kmtc.ThuChiID].ToString()); kmtc.MaKhoanMuc = dr[Kmtc.MaKhoanMuc].ToString(); kmtc.TenKhoanMuc = dr[Kmtc.TenKhoanMuc].ToString(); kmtc.LoaiKM = (bool)dr[Kmtc.LoaiKM]; kmtc.DoiTuong = dr[Kmtc.DoiTuong].ToString(); kmtc.NoTK = dr[Kmtc.NoTK].ToString(); kmtc.CoTK = dr[Kmtc.CoTK].ToString(); kmtc.GhiChu = dr[Kmtc.GhiChu].ToString(); kmtc.Deleted = (Boolean)dr[Kmtc.Deleted]; arr.Add(kmtc); } int n = arr.Count; if (n == 0) { return(null); } arrC = new Entities.KMThuChi[n]; for (int i = 0; i < n; i++) { arrC[i] = (Entities.KMThuChi)arr[i]; } for (int i = 0; i < n; i++) { if (arrC[i].LoaiKM == true) { arrC[i].TenLoaiKhoanMuc = "Khoản Mục Thu"; } else { arrC[i].TenLoaiKhoanMuc = "Khoản Mục Chi"; } } } catch (Exception ex) { string s = ex.Message.ToString(); } finally { cmd.Connection.Dispose(); cn.Close(); conn.closeConnection(); } return(arrC); }
public Entities.KMThuChi[] Select() { Entities.KMThuChi[] arrC = null; try { Kmtc = new Constants.KMThuChi(); Sql = new Constants.Sql(); string sql = Sql.SelectAllKMThuChi; conn = new Connection(); cn = conn.openConnection(); cmd = new SqlCommand(sql, cn); dr = cmd.ExecuteReader(CommandBehavior.CloseConnection); arr = new ArrayList(); while (dr.Read()) { Entities.KMThuChi kmtc = new Entities.KMThuChi(); kmtc.ThuChiID = Convert.ToInt32(dr[Kmtc.ThuChiID].ToString()); kmtc.MaKhoanMuc = dr[Kmtc.MaKhoanMuc].ToString(); kmtc.TenKhoanMuc = dr[Kmtc.TenKhoanMuc].ToString(); kmtc.LoaiKM = (bool)dr[Kmtc.LoaiKM]; kmtc.DoiTuong = dr[Kmtc.DoiTuong].ToString(); kmtc.NoTK = dr[Kmtc.NoTK].ToString(); kmtc.CoTK = dr[Kmtc.CoTK].ToString(); kmtc.GhiChu = dr[Kmtc.GhiChu].ToString(); kmtc.Deleted = (Boolean)dr[Kmtc.Deleted]; arr.Add(kmtc); } int n = arr.Count; if (n == 0) { return null; } arrC = new Entities.KMThuChi[n]; for (int i = 0; i < n; i++) { arrC[i] = (Entities.KMThuChi)arr[i]; } for (int i = 0; i < n; i++) { if (arrC[i].LoaiKM==true) { arrC[i].TenLoaiKhoanMuc = "Khoản Mục Thu"; } else { arrC[i].TenLoaiKhoanMuc = "Khoản Mục Chi"; } } } catch (Exception ex) { string s = ex.Message.ToString(); } finally { cmd.Connection.Dispose(); cn.Close(); conn.closeConnection(); } return arrC; }
/// <summary> /// Lấy Khoản mục thu chi /// </summary> /// <param name="bl"></param> /// <returns></returns> public Entities.KMThuChi[] LayKMThuChi(Boolean bl) { Entities.KMThuChi[] arrC = null; try { Kmtc = new Constants.KMThuChi(); Sql = new Constants.Sql(); string sql = Sql.LayKMThuChi; conn = new Connection(); cn = conn.openConnection(); cmd = new SqlCommand(sql, cn); cmd.Parameters.Add("@Loai", SqlDbType.Bit).Value = bl; dr = cmd.ExecuteReader(CommandBehavior.CloseConnection); arr = new ArrayList(); while (dr.Read()) { Entities.KMThuChi kmtc = new Entities.KMThuChi(); kmtc.ThuChiID = Convert.ToInt32(dr[Kmtc.ThuChiID].ToString()); kmtc.MaKhoanMuc = dr[Kmtc.MaKhoanMuc].ToString(); kmtc.TenKhoanMuc = dr[Kmtc.TenKhoanMuc].ToString(); kmtc.LoaiKM = (bool)dr[Kmtc.LoaiKM]; kmtc.DoiTuong = dr[Kmtc.DoiTuong].ToString(); kmtc.NoTK = dr[Kmtc.NoTK].ToString(); kmtc.CoTK = dr[Kmtc.CoTK].ToString(); kmtc.GhiChu = dr[Kmtc.GhiChu].ToString(); Boolean kt = kmtc.Deleted = (Boolean)dr[Kmtc.Deleted]; if (kt == false) { arr.Add(kmtc); } } int n = arr.Count; if (n == 0) { return null; } arrC = new Entities.KMThuChi[n]; for (int i = 0; i < n; i++) { arrC[i] = (Entities.KMThuChi)arr[i]; } } catch { } finally { cmd.Connection.Dispose(); cn.Close(); conn.closeConnection(); } return arrC; }
private void txtTimKiem_TextChanged(object sender, EventArgs e) { if (rdbTen.Checked==true) { if (KM_Search==null) { Entities.KMThuChi[] km = new KMThuChi[0]; dataGridView1.DataSource = km; FixDataGridView(); toolStripStatus_Sua.Enabled = false; toolStripStatus_Xoa.Enabled = false; } else if (KM_Search != null) { if (txtTimKiem.Text.Length == 0) { Entities.KMThuChi[] km = new KMThuChi[0]; dataGridView1.DataSource = km; FixDataGridView(); toolStripStatus_Sua.Enabled = false; toolStripStatus_Xoa.Enabled = false; } else { int tk1_search_count = 0; for (int i = 0; i < KM_Search.Length; i++) { int index = -1; index = KM_Search[i].TenKhoanMuc.ToLower().IndexOf(txtTimKiem.Text.ToLower()); if (index >= 0) { tk1_search_count++; } } KMThuChi[] tk1_search = new KMThuChi[tk1_search_count]; tk1_search_count = 0; for (int i = 0; i < KM_Search.Length; i++) { int index = -1; index = KM_Search[i].TenKhoanMuc.ToLower().IndexOf(txtTimKiem.Text.ToLower()); if (index >= 0) { tk1_search[tk1_search_count] = KM_Search[i]; tk1_search_count++; } } if (tk1_search_count == 0) { toolStripStatus_Sua.Enabled = false; toolStripStatus_Xoa.Enabled = false; } else { toolStripStatus_Sua.Enabled = true; toolStripStatus_Xoa.Enabled = true; } dataGridView1.DataSource = tk1_search; FixDataGridView(); } } } else if (rdbMa.Checked == true) { if (KM_Search == null) { Entities.KMThuChi[] km = new KMThuChi[0]; dataGridView1.DataSource = km; FixDataGridView(); toolStripStatus_Sua.Enabled = false; toolStripStatus_Xoa.Enabled = false; } else if (KM_Search != null) { if (txtTimKiem.Text.Length == 0) { Entities.KMThuChi[] km = new KMThuChi[0]; dataGridView1.DataSource = km; FixDataGridView(); toolStripStatus_Sua.Enabled = false; toolStripStatus_Xoa.Enabled = false; } else { int tk1_search_count = 0; for (int i = 0; i < KM_Search.Length; i++) { int index = -1; index = KM_Search[i].MaKhoanMuc.ToLower().IndexOf(txtTimKiem.Text.ToLower()); if (index >= 0) { tk1_search_count++; } } KMThuChi[] tk1_search = new KMThuChi[tk1_search_count]; tk1_search_count = 0; for (int i = 0; i < KM_Search.Length; i++) { int index = -1; index = KM_Search[i].MaKhoanMuc.ToLower().IndexOf(txtTimKiem.Text.ToLower()); if (index >= 0) { tk1_search[tk1_search_count] = KM_Search[i]; tk1_search_count++; } } if (tk1_search_count == 0) { toolStripStatus_Sua.Enabled = false; toolStripStatus_Xoa.Enabled = false; } else { toolStripStatus_Sua.Enabled = true; toolStripStatus_Xoa.Enabled = true; } dataGridView1.DataSource = tk1_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["ThuChiID"].Value.ToString()); string ten = dataGridView1.CurrentRow.Cells["TenKhoanMuc"].Value.ToString(); string maCurrent = dataGridView1.CurrentRow.Cells["MaKhoanMuc"].Value.ToString(); hienthi(); for (int j = 0; j < KM_Search.Length; j++) { if (KM_Search[j].Deleted == false) if (KM_Search[j].ThuChiID == idcurent) { ktdelete = true; break; } } if (ktdelete == true) { try { if (new Check().CheckReference("KMThuChi", ten)) { Server_Client.Client cl = new Server_Client.Client(); this.client1 = cl.Connect(Luu.IP, Luu.Ports); Entities.KMThuChi nv = new KMThuChi("Delete", idcurent, maCurrent,Common.Utilities.User.NhanVienID,Common.Utilities.User.TenDangNhap); clientstrem = cl.SerializeObj(this.client1, "KMThuChi", nv); //MessageBox.Show("Xoa Thanh Cong..."); } else { MessageBox.Show("Khoản Mục 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); KM = new KMThuChi("Select", 1, "a", "a", true, "a", "a", "a", "a", false," "); clientstrem = cl.SerializeObj(this.client1, "KMThuChi", KM); KMThuChi[] tk1 = new KMThuChi[1]; tk1[0] = new KMThuChi(1, "a", "a", true, "a", "a", "a", "a", false,""); tk1 = (KMThuChi[])cl.DeserializeHepper1(clientstrem, tk1); if (tk1 == null) { Entities.KMThuChi[] km = new KMThuChi[0]; KM_Search = km; dataGridView1.DataSource = km; FixDataGridView(); toolStripStatus_Sua.Enabled = false; toolStripStatus_Xoa.Enabled = false; } else { KM_Search = tk1; dataGridView1.DataSource = tk1; FixDataGridView(); toolStripStatus_Sua.Enabled = true; toolStripStatus_Xoa.Enabled = true; } }
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); string dt = ""; switch (cbbdoiTuong.Text) { case "Khách Hàng": { dt = "Khach Hang"; break; } case "Nhà Cung Cấp": { dt = "Nha Cung Cap"; break; } case "Nhân Viên": { dt = "Nhan Vien"; break; } } bool LoaiKhoanMuc; if (cbbLoaiKhoanMuc.SelectedIndex == 0) { LoaiKhoanMuc = true; } else { LoaiKhoanMuc = false; } Entities.KMThuChi pb = new Entities.KMThuChi("Update", Convert.ToInt32(txtID.Text), txtmaKM.Text, txttenKM.Text, LoaiKhoanMuc, dt, "", "", txtghichu.Text, false, Common.Utilities.User.NhanVienID, Common.Utilities.User.TenDangNhap); clientstream = cl.SerializeObj(this.client1, "KMThuChi", pb); int msg = 0; msg = (int)cl.DeserializeHepper(clientstream, msg); if (msg != 1) { MessageBox.Show("Update That Bai"); } tenKhoanMuc = txttenKM.Text; loaiKM = LoaiKhoanMuc; doiTuong = dt; //noTK = cbbNoTK.Text; //coTK = cbbCoTK.Text; ghiChu = txtghichu.Text; this.Close(); } 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 !"); //tabControl1.Enabled = false; this.Close(); } } }