/// 
///INTERFACE CLASS FOR TABLE t_tmsLineDetail
///By wm  
///on 07/23/2017
/// 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
namespace DeiNiu.wms.Data.Model
{
    [Serializable]
    public class TmsLineDetail : TmsLineDetail_base
    {
        public TmsLineDetail()
        {
        }
        public TmsLineDetail(int id): base(id)
        {
        }
        public TmsLineDetail(DataRow dr): base(dr)
        {
        }
      protected override void getImp()
        {
            model_imp = new TmsLineDetail_Imp();  
        }
        //begin cust db operation, query, excute sql etc.
     
        public DataTable queryByCustName(string custName)
        {
            cmdParameters[0] = custName;
            return CustQuery(100).Tables[0];
        }
        /// 
        /// get customers not in the line yet
        /// 
        /// 
        /// 
        public DataSet getAvailableCustomers(int lineId, string custName, int startPage, int endPage)
        {
            cmdParameters[0] = lineId;
             cmdParameters[1]  =  "";
            if (!string.IsNullOrEmpty(custName))
            {
                cmdParameters[1] = string.Format(" and custName like '%{0}%'",custName);
            }
            cmdParameters[2] = startPage;
            cmdParameters[3] = endPage;
            return CustQuery(200);
        }
        public DataTable queryByLineID(int lineId)
        {
            cmdParameters[0] = lineId;
            return CustQuery(300).Tables[0];
        }
        public DataTable getLinesByCustId(string custId)
        {
            cmdParameters[0] = custId;
            return CustQuery(500).Tables[0];
        }
        public TmsLineDetail getLineDetailByCustId(string custId)
        {  
            DataTable dt = getLinesByCustId(custId);
            foreach (DataRow dr in dt.Rows)
            {
                return new TmsLineDetail(dr);                
            }
            return new TmsLineDetail();
        }
        public DataTable getLinesByCust(string custName)
        {
            return queryByCustName(custName);
        }
        public int getLineDetailCount(int lineId)
        {
            return queryByLineID(lineId).Rows.Count;
        }
        /// 
        /// update line cust orders
        /// 
        /// 
        /// 
        /// 
        /// 
        public int updateCustOrders(int lineId, int start, int end, int value)
        {
            cmdParameters[0] = lineId;
            cmdParameters[1] = start;
            cmdParameters[2] = end;
            cmdParameters[3] = value; 
            return CustOper(400);
        }
    }
}