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

namespace LYFZ.CloudServerData.DAL
{
    public class ScanProductInfo : BaseDataOperate<LYFZ.CloudServerData.Model.ScanProductInfo>
    {
        public ScanProductInfo(LYFZ.CloudServerData.Model.DBConnection dbConn)
        {
            base.DBConn = dbConn;
        }
        /// <summary>
        /// 获取扫一扫商品数据
        /// </summary>
        /// <param name="proNumber">商品编号</param>
        /// <param name="proType">商品类型</param>
        /// <returns></returns>
        public LYFZ.CloudServerData.Model.ScanProductInfo GetScanProductInfo(string EnterpriseID, string proType, string proNumber, string proName)
        {
            if (!String.IsNullOrEmpty(proNumber) && !string.IsNullOrEmpty(proType))
            {
                string strWhere = "";
                if (!string.IsNullOrEmpty(EnterpriseID))
                {
                    if(!string.IsNullOrEmpty(strWhere))
                    {
                        strWhere += " and ";
                    }
                    strWhere += "  EnterpriseID = '" + EnterpriseID + "'  ";
                }

                if (!string.IsNullOrEmpty(proType))
                {
                    if (!string.IsNullOrEmpty(strWhere))
                    {
                        strWhere += " and ";
                    }
                    strWhere += "  ProType = '" + proType + "'  ";
                }

                if (!string.IsNullOrEmpty(proNumber))
                {
                    if (!string.IsNullOrEmpty(strWhere))
                    {
                        strWhere += " and ";
                    }
                    strWhere += "  ProNumber = '" + proNumber + "'  ";
                }

                if (!string.IsNullOrEmpty(proName))
                {
                    if (!string.IsNullOrEmpty(strWhere))
                    {
                        strWhere += " and ";
                    }
                    strWhere += "  ProName = '" + proName + "'  ";
                }

                return this.GetModel(strWhere);
            }
            else
            {
                return null;
            }
        }
        /// <summary>
        /// 获取扫一扫商品数据
        /// </summary>
        /// <param name="ID"></param>
        /// <returns></returns>
        public LYFZ.CloudServerData.Model.ScanProductInfo GetScanProductInfo(string ID)
        {
            if (!String.IsNullOrEmpty(ID))
            {
                return this.GetModel("ID", ID);
            }
            else
            {
                return new Model.ScanProductInfo();
            }
        }
        /// <summary>
        /// 添加商品信息
        /// </summary>
        /// <param name="EnterpriseID">企业编号</param>
        /// <param name="ProType">商品类型</param>
        /// <param name="ProTypeList">所属分类</param>
        /// <param name="ProNumber">商品编号</param>
        /// <param name="ProName">商品名称</param>
        /// <param name="ProInfo">商品描述</param>
        /// <param name="CreateName">创建人名称</param>
        /// <returns></returns>
        public bool AddScanProductInfo(string EnterpriseID, string ProType, string ProTypeList, string ProNumber, string ProName, string ProInfo, string CreateName, string ImgUrl, decimal SellValue, decimal PQuantity)
        {
            Model.ScanProductInfo model = new Model.ScanProductInfo()
            {
                CreateName = CreateName,
                ProTypeList = ProTypeList,
                ProType = ProType,
                EnterpriseID = EnterpriseID,
                ProNumber = ProNumber,
                ProName = ProName,
                ProInfo = ProInfo,
                CreateTime = DateTime.Now,
                ImgUrl = ImgUrl,
                PQuantity = PQuantity,
                SellValue = SellValue
            };
            return this.Add(model);
        }

        public bool UpdateScanProductInfo(int ID, string EnterpriseID, string ProType, string ProTypeList, string ProNumber, string ProName, string ProInfo, string CreateName, string ImgUrl, decimal SellValue, decimal PQuantity)
        {
            Model.ScanProductInfo model = new Model.ScanProductInfo()
            {
                ID = ID,
                UpdateName = CreateName,
                ProTypeList = ProTypeList,
                ProType = ProType,
                EnterpriseID = EnterpriseID,
                ProNumber = ProNumber,
                ProName = ProName,
                ProInfo = ProInfo,
                UpdateTime = DateTime.Now,
                ImgUrl = ImgUrl,
                PQuantity = PQuantity,
                SellValue = SellValue
            };
            return this.Update(model);
        }



        public bool DeleteByBatchId(string _BatchId)
        {
            bool b = this.DeleteList(_BatchId);
            return b;
        }
    }
}