using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Reflection;
using System.Text;

namespace CallCenterApi.BLL
{
    /// <summary>
    ///订单表
    /// </summary>
    public partial class orders
    {
        //private readonly Model.sysconfig sysConfig = new BLL.sysconfig().loadConfig();//获得系统配置信息
        private readonly CallCenterApi.DAL.orders dal;

        public orders()
        {
            dal = new CallCenterApi.DAL.orders();
        }

        #region 基本方法================================
        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(int id)
        {
            return dal.Exists(id);
        }

        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(Model.orders model)
        {
            return dal.Add(model);
        }

        ///// <summary>
        ///// 更新一条数据
        ///// </summary>
        //public bool Update(Model.orders model)
        //{
        //    //计算订单总金额:商品总金额+配送费用+支付手续费
        //    model.order_amount = model.real_amount + model.express_fee + model.payment_fee + model.invoice_taxes;
        //    return dal.Update(model);
        //}

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(int id)
        {
            return dal.Delete(id);
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Model.orders GetModel(int id)
        {
            return dal.GetModel(id);
        }

        /// <summary>
        /// 获得前几行数据
        /// </summary>
        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            return dal.GetList(Top, strWhere, filedOrder);
        }

        ///// <summary>
        ///// 获得查询分页数据
        ///// </summary>
        //public DataSet GetList(int pageSize, int pageIndex, string strWhere, string filedOrder, out int recordCount)
        //{
        //    return dal.GetList(pageSize, pageIndex, strWhere, filedOrder, out recordCount);
        //}
        #endregion

        #region 扩展方法================================
        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(string order_no)
        {
            return dal.Exists(order_no);
        }

        /// <summary>
        /// 根据订单号返回一个实体
        /// </summary>
        public Model.orders GetModel(string order_no)
        {
            return dal.GetModel(order_no);
        }

        /// <summary>
        /// 根据订单号获取支付方式ID
        /// </summary>
        public int GetPaymentId(string order_no)
        {
            return dal.GetPaymentId(order_no);
        }

        /// <summary>
        /// 返回数据数
        /// </summary>
        public int GetCount(string strWhere)
        {
            return dal.GetCount(strWhere);
        }

        /// <summary>
        /// 修改一列数据
        /// </summary>
        public void UpdateField(int id, string strValue)
        {
            dal.UpdateField(id, strValue);
        }

        /// <summary>
        /// 修改一列数据
        /// </summary>
        public bool UpdateField(string order_no, string strValue)
        {
            return dal.UpdateField(order_no, strValue);
        }
        #endregion
        public List<Model.orders> DataTableToList(DataTable dt)
        {
            List<Model.orders> list = new List<Model.orders>();
            int rowsCount = dt.Rows.Count;
            if (rowsCount > 0)
            {
                CallCenterApi.Model.orders model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = new CallCenterApi.Model.orders();
                    if (dt.Rows[n]["id"] != null && dt.Rows[n]["id"].ToString() != "")
                    {
                        model.id = int.Parse(dt.Rows[n]["id"].ToString());
                    }
                    if (dt.Rows[n]["order_no"] != null && dt.Rows[n]["order_no"].ToString() != "")
                    {
                        model.order_no = dt.Rows[n]["order_no"].ToString();
                    }
                    if (dt.Rows[n]["user_id"] != DBNull.Value && dt.Rows[n]["user_id"].ToString() != "")
                    {
                        model.user_id = int.Parse(dt.Rows[n]["user_id"].ToString());
                    }
                    else
                    {
                        model.user_id = null;

                    }
                    if (dt.Rows[n]["user_name"] != null && dt.Rows[n]["user_name"].ToString() != "")
                    {
                        model.user_name = dt.Rows[n]["user_name"].ToString();
                    }
                    if (dt.Rows[n]["express_id"] != null && dt.Rows[n]["express_id"].ToString() != "")
                    {
                        model.express_id = int.Parse(dt.Rows[n]["express_id"].ToString());
                    }
                    if (dt.Rows[n]["express_no"] != null && dt.Rows[n]["express_no"].ToString() != "")
                    {
                        model.express_no = dt.Rows[n]["express_no"].ToString();
                    }
                    if (dt.Rows[n]["accept_name"] != null && dt.Rows[n]["accept_name"].ToString() != "")
                    {
                        model.accept_name = dt.Rows[n]["accept_name"].ToString();
                    }
                    if (dt.Rows[n]["post_code"] != null && dt.Rows[n]["post_code"].ToString() != "")
                    {
                        model.post_code = dt.Rows[n]["post_code"].ToString();
                    }
                    if (dt.Rows[n]["telphone"] != null && dt.Rows[n]["telphone"].ToString() != "")
                    {
                        model.telphone = dt.Rows[n]["telphone"].ToString();
                    }
                    if (dt.Rows[n]["mobile"] != null && dt.Rows[n]["mobile"].ToString() != "")
                    {
                        model.mobile = dt.Rows[n]["mobile"].ToString();
                    }
                    if (dt.Rows[n]["address"] != null && dt.Rows[n]["address"].ToString() != "")
                    {
                        model.address = dt.Rows[n]["address"].ToString();
                    }
                    if (dt.Rows[n]["remark"] != null && dt.Rows[n]["remark"].ToString() != "")
                    {
                        model.remark = dt.Rows[n]["remark"].ToString();
                    }

                    list.Add(model);
                }
            }
            return list;
        }
    }
}