public static List <KhieuNaiDTO> GetListKhieuNai(ThoiGianDTO model) { var conn = Config.getConnectionKhieuNai(); //Create Command object //SqlCommand nonqueryCommand = conn.CreateCommand(); try { // Open Connection conn.Open(); string sql = ""; if (string.IsNullOrEmpty(model.CHK)) { sql = "SELECT * FROM DT_KHIEUNAI WHERE (NGUOINHAP=@_NGUOINHAP AND NGAYLAP >= @_FromDate AND NGAYLAP <= @_ToDate )"; } else { sql = "SELECT * FROM DT_KHIEUNAI WHERE (NGUOINHAP=@_NGUOINHAP AND NGAYLAP >= @_FromDate AND NGAYLAP <= @_ToDate AND CHK=@_CHK)"; } if (model.UserName == "emscntt9192") { sql = "SELECT * FROM DT_KHIEUNAI WHERE (NGAYLAP >= @_FromDate AND NGAYLAP <= @_ToDate AND CHK=@_CHK)"; } SqlCommand cmd = new SqlCommand(sql, conn); if (model.UserName != "emscntt9192") { cmd.Parameters.AddWithValue("@_NGUOINHAP", model.NguoiNhap); } if (!string.IsNullOrEmpty(model.CHK)) { cmd.Parameters.AddWithValue("@_CHK", model.CHK); } cmd.Parameters.AddWithValue("@_FromDate", model.FromDate); cmd.Parameters.AddWithValue("@_ToDate", model.ToDate); IDataReader reader = (IDataReader)cmd.ExecuteReader(); List <KhieuNaiDTO> result = new List <KhieuNaiDTO>(); if (reader != null) { result = DbExtensions.ToList <KhieuNaiDTO>(reader); } return(result); } catch (SqlException ex) { string err = string.Format("[ERR_KhieuNai] loi get du lieu [DT_KHIEUNAI] - NguoiNhap={0},FromDate={1},ToDate={2},ex={3}", model.NguoiNhap, model.FromDate, model.ToDate, ex.Message); LogHelper.LogInfo(err, "KhieuNai"); return(new List <KhieuNaiDTO>()); } finally { // Close Connection conn.Close(); conn.Dispose(); } }
public static List <KhieuNaiDTO> GetListKhieuNai(ThoiGianDTO model) { var conn = Config.getConnectionKhieuNai(); // Open Connection conn.Open(); string sql = ""; if (string.IsNullOrEmpty(model.NguoiNhap)) { sql = "SELECT * FROM DT_KHIEUNAI WHERE (NGAYLAP >= @_FromDate AND NGAYLAP <= @_ToDate AND CHK=@_CHK)"; } else { if (string.IsNullOrEmpty(model.CHK)) { sql = "SELECT * FROM DT_KHIEUNAI WHERE (NGUOINHAP=@_NGUOINHAP AND NGAYLAP >= @_FromDate AND NGAYLAP <= @_ToDate)"; } else { sql = "SELECT * FROM DT_KHIEUNAI WHERE (NGUOINHAP=@_NGUOINHAP AND NGAYLAP >= @_FromDate AND NGAYLAP <= @_ToDate AND CHK= @_CHK)"; } } SqlCommand cmd = new SqlCommand(sql, conn); if (!string.IsNullOrEmpty(model.NguoiNhap)) { cmd.Parameters.AddWithValue("@_NGUOINHAP", model.NguoiNhap); } if (!string.IsNullOrEmpty(model.CHK)) { cmd.Parameters.AddWithValue("@_CHK", model.CHK); } cmd.Parameters.AddWithValue("@_FromDate", model.FromDate); cmd.Parameters.AddWithValue("@_ToDate", model.ToDate); IDataReader reader = (IDataReader)cmd.ExecuteReader(); List <KhieuNaiDTO> result = new List <KhieuNaiDTO>(); if (reader != null) { result = DbExtensions.ToList <KhieuNaiDTO>(reader); } // Close Connection conn.Close(); conn.Dispose(); return(result); }
public async Task <IHttpActionResult> GetListKhieuNai(DateTime?fromdate, DateTime?todate, string chk, string nguoinhap, string username) { try { await Task.Delay(1000); if (fromdate == null) { return(Ok(new ResponseCode { code = "error", message = "Thời gian từ ngày không được bỏ trống" })); } if (todate == null) { return(Ok(new ResponseCode { code = "error", message = "Thời gian đến ngày không được bỏ trống" })); } if (string.IsNullOrEmpty(nguoinhap)) { return(Ok(new ResponseCode { code = "error", message = "Người nhập nhập không được bỏ trống. Vui lòng nhập lại !" })); } ThoiGianDTO model = new ThoiGianDTO() { FromDate = fromdate, ToDate = todate, CHK = chk, NguoiNhap = nguoinhap, UserName = username }; var data = KhieuNaiBLL.GetListKhieuNai(model); return(Ok(new ResponseCode { code = "success", message = "Lấy danh sách khiếu nại", data = data })); } catch (Exception ex) { string err = string.Format("[ERR_KhieuNai] lỗi get thông tin trong bảng [DT_KHIEUNAI] : ex = {0},FromDate={1},ToDate={2},CHK={3},NguoiNhap={4},username={5}", ex.Message, fromdate, todate, chk, nguoinhap, username); return(Ok(new ResponseCode { code = "error", message = err })); } }
public List <ThoiGianDTO> select() { string query = string.Empty; query += "SELECT [MaThoiGian],[ThangNam]"; query += "FROM [THOIGIAN]"; List <ThoiGianDTO> lsThoiGian = new List <ThoiGianDTO>(); using (SqlConnection con = new SqlConnection(ConnectionString)) { using (SqlCommand cmd = new SqlCommand()) { cmd.Connection = con; cmd.CommandType = System.Data.CommandType.Text; cmd.CommandText = query; try { con.Open(); SqlDataReader reader = null; reader = cmd.ExecuteReader(); if (reader.HasRows == true) { while (reader.Read()) { ThoiGianDTO tg = new ThoiGianDTO(); tg.Mathoigian = int.Parse(reader["MaThoiGian"].ToString()); tg.Thang = int.Parse(reader["ThangNam"].ToString()); lsThoiGian.Add(tg); } } con.Close(); con.Dispose(); } catch (Exception ex) { con.Close(); return(null); } } } return(lsThoiGian); }