C#操作Excel数据增删改查示例(3)


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using MyStudy.Model;
using MyStudy.DAL;
using System.Data.OleDb;

namespace MyStudy.BLL
{
/// <summary>
/// 订单业务类
/// </summary>
public class OrderBLL
{
/// <summary>
/// 查询订单列表
/// </summary>
public List<Order> GetOrderList()
{
List<Order> orderList = new List<Order>();
string sql = "SELECT * FROM [Order$]";
DataSet dateSet = ExcelHelper.GetReader(sql);
orderList = Order.ToList(dateSet);
return orderList;
}

/// <summary>
/// 获取订单总数
/// </summary>
public int GetOrderCount()
{
int result = 0;
string sql = "SELECT COUNT(*) FROM [Order$]";
result = ExcelHelper.GetScalar(sql);
return result;
}

/// <summary>
/// 新增订单
/// </summary>
public int AddOrder(Order param)
{
int result = 0;
string sql = "INSERT INTO [Order$](OrderNo,ProductName,Quantity,Money,SaleDate) VALUES(@OrderNo,@ProductName,@Quantity,@Money,@SaleDate)";
OleDbParameter[] oleDbParam = new OleDbParameter[]
{
new OleDbParameter("@OrderNo", param.OrderNo),
new OleDbParameter("@ProductName", param.ProductName),
new OleDbParameter("@Quantity", param.Quantity),
new OleDbParameter("@Money",param.Money),
new OleDbParameter("@SaleDate",param.SaleDate)
};
result = ExcelHelper.ExecuteCommand(sql, oleDbParam);
return result;
}

/// <summary>
/// 修改订单
/// </summary>
public int UpdateOrder(Order param)
{
int result = 0;
if (!String.IsNullOrEmpty(param.OrderNo))
{
string sql = "UPDATE [Order$] SET ProductName=@ProductName,Quantity=@Quantity,Money=@Money WHERE OrderNo=@OrderNo";
OleDbParameter[] sqlParam = new OleDbParameter[]
{
new OleDbParameter("@OrderNo",param.OrderNo),
new OleDbParameter("@ProductName",param.ProductName),
new OleDbParameter("@Quantity", param.Quantity),
new OleDbParameter("@Money", param.Money)
};
result = ExcelHelper.ExecuteCommand(sql, sqlParam);
}
return result;
}

/// <summary>
/// 删除订单
/// </summary>
public int DeleteOrder(Order param)
{
int result = 0;
if (!String.IsNullOrEmpty(param.OrderNo))
{
string sql = "DELETE [Order$] WHERE OrderNo=@OrderNo";
OleDbParameter[] sqlParam = new OleDbParameter[]
{
new OleDbParameter("@OrderNo",param.OrderNo),
};
result = ExcelHelper.ExecuteCommand(sql, sqlParam);
}
return result;
}
}
}

您可能感兴趣的文章:

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wjgzdy.html