public string CheckedAll() { try { string connect = Provider.Connecting(); SqlConnection con = new SqlConnection(connect); con.Open(); SqlTransaction sqlTransaction = con.BeginTransaction(); string query = @"update dbo_HoatChat set MacDinh=0"; SqlCommand cmd = new SqlCommand(query, con); cmd.CommandType = CommandType.Text; cmd.Transaction = sqlTransaction; int result = cmd.ExecuteNonQuery(); if (result < 1) { sqlTransaction.Rollback(); sqlTransaction.Dispose(); con.Close(); return(@"Lỗi số 1 : DAOHoatChat ->CheckedAll : Updade dữ liệu đơn vị tính lỗi"); } sqlTransaction.Commit(); sqlTransaction.Dispose(); con.Close(); return("SUCCESS"); } catch (Exception e) { return(@"Lỗi ngoại lệ : DAOHoatChat ->CheckedAll : " + e.Message); } }
public string Update(DTOHoatChat data) { try { string connect = Provider.Connecting(); SqlConnection con = new SqlConnection(connect); con.Open(); SqlTransaction sqlTransaction = con.BeginTransaction(); string query = @"update dbo_HoatChat set HoatChat_Name=N'" + data.Name + "',MacDinh=" + data.MacDinh + " where HoatChat_ID='" + data.ID + "'"; SqlCommand cmd = new SqlCommand(query, con); cmd.CommandType = CommandType.Text; cmd.Transaction = sqlTransaction; int result = cmd.ExecuteNonQuery(); if (result != 1) { sqlTransaction.Rollback(); sqlTransaction.Dispose(); con.Close(); return(@"Lỗi số 1 : DAOHoatChat ->Update : Cập nhật dữ liệu đơn vị tính lỗi"); } sqlTransaction.Commit(); sqlTransaction.Dispose(); con.Close(); return("SUCCESS"); } catch (Exception e) { return(@"Lỗi ngoại lệ : DAOHoatChat ->Update : " + e.Message); } }
public string Delete(DTODieuKienBaoQuan data) { try { string connect = Provider.Connecting(); SqlConnection con = new SqlConnection(connect); con.Open(); SqlTransaction sqlTransaction = con.BeginTransaction(); string query = @"delete dbo_DKBQ where DKBQ_ID= " + data.DKBQ_ID + ""; SqlCommand cmd = new SqlCommand(query, con); cmd.CommandType = CommandType.Text; cmd.Transaction = sqlTransaction; int result = cmd.ExecuteNonQuery(); if (result != 1) { sqlTransaction.Rollback(); sqlTransaction.Dispose(); con.Close(); return(@"Lỗi số 1 : DAOHoatChat ->Update : Cập nhật dữ liệu đơn vị tính lỗi"); } sqlTransaction.Commit(); sqlTransaction.Dispose(); con.Close(); return("SUCCESS"); } catch (Exception e) { return(@"Lỗi ngoại lệ : DAOHoatChat ->Delete : " + e.Message); } }
public string Update(DTONCC data) { try { string connect = Provider.Connecting(); SqlConnection con = new SqlConnection(connect); con.Open(); SqlTransaction sqlTransaction = con.BeginTransaction(); string query = @"update dbo_NCC set NCC_Name=N'" + data.NCC_Name + "',DiaChi=N'" + data.DiaChi + "',Email=N'" + data.Email + "',SDT='" + data.SDT + "',Fax='" + data.Fax + "',MaSoThue='" + data.MaSoThue + "',SoGiayPhepDKKD='" + data.SoGiayPhepDKKD + "',MacDinh=" + data.MacDinh + ",TenNguoiDaiDien=N'" + data.TenNguoiDaiDien + "' where NCC_ID=" + data.NCC_ID + ""; SqlCommand cmd = new SqlCommand(query, con); cmd.CommandType = CommandType.Text; cmd.Transaction = sqlTransaction; int result = cmd.ExecuteNonQuery(); if (result != 1) { sqlTransaction.Rollback(); sqlTransaction.Dispose(); con.Close(); return(@"Lỗi số 1 : DAOUnit ->Update : Cập nhật dữ liệu đơn vị tính lỗi"); } sqlTransaction.Commit(); sqlTransaction.Dispose(); con.Close(); return("SUCCESS"); } catch (Exception e) { return(@"Lỗi ngoại lệ : DAOUnit ->Update : " + e.Message); } }
public string Insert(ref DTOHoatChat data) { try { string connect = Provider.Connecting(); SqlConnection con = new SqlConnection(connect); con.Open(); SqlTransaction sqlTransaction = con.BeginTransaction(); string query = @"insert into dbo_HoatChat(HoatChat_Name,MacDinh) values(N'" + data.Name + "','" + data.MacDinh + "')"; SqlCommand cmd = new SqlCommand(query, con); cmd.CommandType = CommandType.Text; cmd.Transaction = sqlTransaction; int result = cmd.ExecuteNonQuery(); if (result == 1) { query = "SELECT IDENT_CURRENT('dbo_HoatChat')"; SqlCommand cmdID = new SqlCommand(query, con); cmdID.CommandType = CommandType.Text; cmdID.Transaction = sqlTransaction; object id = cmdID.ExecuteScalar(); data.ID = id.ToString(); if (result > 0) { sqlTransaction.Commit(); } else { sqlTransaction.Rollback(); sqlTransaction.Dispose(); con.Close(); return("Lỗi số 2 : DAOHoatChat -> Insert : Lấy mã đơn vị tính lỗi"); } } else { sqlTransaction.Rollback(); sqlTransaction.Dispose(); con.Close(); return(@"Lỗi số 1 : DAOHoatChat ->Insert : Thêm dữ liệu đơn vị tính lỗi "); } sqlTransaction.Dispose(); con.Close(); return("SUCCESS"); } catch (Exception e) { return("Lỗi ngoại lệ: DAOHoatChat -> Insert: " + e.Message); } }
public string Insert(ref DTONCC data) { try { string connect = Provider.Connecting(); SqlConnection con = new SqlConnection(connect); con.Open(); SqlTransaction sqlTransaction = con.BeginTransaction(); string query = @"insert into dbo_NCC(NCC_Name,DiaChi,Email,SDT,Fax,MaSoThue,SoGiayPhepDKKD,MacDinh) values(N'" + data.NCC_Name + "',N'" + data.DiaChi + "','" + data.Email + "','" + data.SDT + "','" + data.Fax + "','" + data.MaSoThue + "','" + data.SoGiayPhepDKKD + "'," + data.MacDinh + ")"; SqlCommand cmd = new SqlCommand(query, con); cmd.CommandType = CommandType.Text; cmd.Transaction = sqlTransaction; int result = cmd.ExecuteNonQuery(); if (result == 1) { query = "SELECT IDENT_CURRENT('dbo_NCC')"; SqlCommand cmdID = new SqlCommand(query, con); cmdID.CommandType = CommandType.Text; cmdID.Transaction = sqlTransaction; object id = cmdID.ExecuteScalar(); data.NCC_ID = id.ToString(); if (result > 0) { sqlTransaction.Commit(); } else { sqlTransaction.Rollback(); sqlTransaction.Dispose(); con.Close(); return("Lỗi số 2 : DAOUnit -> Insert : Lấy mã đơn vị tính lỗi"); } } else { sqlTransaction.Rollback(); sqlTransaction.Dispose(); con.Close(); return(@"Lỗi số 1 : DAOUnit ->Insert : Thêm dữ liệu đơn vị tính lỗi "); } sqlTransaction.Dispose(); con.Close(); return("SUCCESS"); } catch (Exception e) { return("Lỗi ngoại lệ: DAOUnit -> Insert: " + e.Message); } }
public string GetAll(ref DataTable data) { try { string connect = Provider.Connecting(); SqlConnection con = new SqlConnection(connect); con.Open(); string query = "select * from dbo_HoatChat"; SqlCommand cmd = new SqlCommand(query, con); cmd.CommandType = CommandType.Text; SqlDataAdapter adapter = new SqlDataAdapter(cmd); int result = adapter.Fill(data); con.Close(); return("SUCCESS"); } catch (Exception e) { return("Lỗi ngoại lệ : DAOHoatChat ->GetAll : " + e.Message); } }