public string GetAllProduct(ProductClass pc) { DataTable dt = new DataTable(); try { using (dt = pc.GetAllProduct(pc)) { if (dt != null && dt.Rows.Count > 0) { StringBuilder htmlText = new StringBuilder(); htmlText.AppendLine("<table width='100%' class='table table-striped table-bordered table-hover' id='dataTables-example'>"); htmlText.AppendLine("<thead><tr>"); htmlText.AppendLine( "<th>Mã sản phẩm</th>" + "<th>Tên sản phẩm</th>" + "<th>Nhà cung cấp</th>" + "<th>Loại</th>" + "<th>Đơn vị</th>" + "<th>Nhà sản xuất</th>" + "<th>Hạn sử dụng</th>" + "<th>Giá</th>" + "<th>Số lượng</th>" + "<th>Chức năng</th>"); htmlText.AppendLine("</tr></thead>"); htmlText.AppendLine("<tbody>"); foreach (DataRow dr in dt.Rows)//dt.Rows: Các đối tượng row trong DataTable { string btnSua = "<img src='../Images/edit.png' title='Sửa thông tin' />"; string btnXoa = "<a data-toggle='modal' data-target='#Delete' href=\"javascript:void(0)\" style=\"text-decoration: none;\"><img src=\"../Images/delete.png\" id=\"imgXoa\" class=\"imgbtn\" title=\"Xóa sản phẩm\" alt=\"Delete\" onclick=\"Delete('" + dr["ProductCode"] + "','" + dr["ProductName"] + "')\" /></a>"; htmlText.AppendLine("<tr>"); htmlText.AppendLine("<td>" + dr["ProductCode"] + "</td>"); htmlText.AppendLine("<td>" + dr["ProductName"] + "</td>"); htmlText.AppendLine("<td>" + dr["ProviderName"] + "</td>"); htmlText.AppendLine("<td>" + dr["CategoryName"] + "</td>"); htmlText.AppendLine("<td>" + dr["Unit"] + "</td>"); htmlText.AppendLine("<td>" + dr["Producer"] + "</td>"); htmlText.AppendLine("<td>" + dr["Expiry"] + "</td>"); htmlText.AppendLine("<td>" + dr["Price"] + "</td>"); htmlText.AppendLine("<td>" + dr["Number"] + "</td>"); htmlText.AppendLine("<td style='text-align:center'>" + btnSua + btnXoa + "</td>"); htmlText.AppendLine("</tr>"); } htmlText.AppendLine("</tbody>"); htmlText.AppendLine("</table>"); return(ResultObject.ReturnResult(htmlText.ToString(), true)); } return(ResultObject.ReturnResult("Không có bản ghi nào phù hợp với bộ lọc, hãy kiểm tra lại.", false)); } } catch (SqlException ex) { return(ResultObject.ReturnResult("GetAllProduct-SqlException:" + ex.Message, false)); } catch (ArgumentException ex) { return(ResultObject.ReturnResult("GetAllProduct-ArgumentException:" + ex.Message, false)); } }
/// <summary> /// Hàm thực hiện chức năng xóa Sản phẩm /// </summary> /// <param name="pc">Đối tượng Sản phẩm</param> /// <returns>[Số bản ghi bị xóa]</returns> public int Delete(ProductClass pc) { ConnectionData data = new ConnectionData(); Hashtable ht = new Hashtable(); try { ht.Add("ProductCode", pc.ProductCode); int result = data.ExcNonQuery("sp_Product_Delete", ht);//số bản ghi trong CSDL bị tác động return(result); } catch { throw; } finally { ht = null; } }
public string Delete(ProductClass pc) { string mess = "Xóa thông tin sản phẩm thất bại. Mời thao tác lại!"; try { if (pc.Delete(pc) > 0)//Xóa thành công { mess = "Ok"; } } catch (SqlException ex) { return(ResultObject.ReturnResult("DeleteCustomer-SqlException:" + ex.Message, false)); } catch (ArgumentException ex) { return(ResultObject.ReturnResult("DeleteCustomer-ArgumentException:" + ex.Message, false)); } return(ResultObject.ReturnResult(mess, true)); }
/// <summary> /// Hàm xử lý lấy dữ liệu hiển thị cho bảng sản phẩm /// </summary> /// <param name="pc"> Đối tượng sản phẩm</param> /// <returns></returns> public DataTable GetAllProduct(ProductClass pc) { DataTable dt = new DataTable(); ConnectionData data = new ConnectionData(); Hashtable ht = new Hashtable(); try { ht.Add("ProductName", pc.ProductName); ht.Add("CategoryId", pc.CategoryId); dt = data.ExcuteDataTableStore("sp_Product_GetAllProduct", ht); return(dt); } catch { throw; } finally { ht = null; } }