动态组织SQl语句:助手类

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

namespace EatGood.Model.FoodManage
{
    /// <summary>
    /// 食法要求查询:动态查询Model
    /// 郑松涛
    /// </summary>
   public class SearchFeelKind
    {
        #region  筛选参数
        private string _ShopId = null;
        private string _Kindname = null;
        private string _FeelKindName = null;
        private string _FeelNo = null;
        private string _Feedname = null;

       /// <summary>
       /// 门店ID
       /// </summary>
        public string FShopId
        {
            get
            {
                if (_ShopId.Length != 0)
                {
                    return "and (fshopid in(1050)) ";
                }
                return _ShopId;
            }
            set { _ShopId = value; }
        }
       /// <summary>
       /// 食品大类名
       /// </summary>
        public string Kindname
        {
            get
            {
                //if (_Kindname.Length != 0)
                //{
                //    return "and (kindname in('" + _Kindname + "'))";
                //}
                return _Kindname;
            }
            set { _Kindname = value; }
        }
       /// <summary>
       /// 要去组别名
       /// </summary>
        public string FeelKindName
        {
            get
            {
                //if (_FeelKindName.Length != 0)
                //{
                //    return "and (FeelKindName in('" + _FeelKindName + "'))";
                //}
                //else
                    return _FeelKindName;
            }
            set { _FeelKindName = value; }
        }
       /// <summary>
       /// 口味编号
       /// </summary>
        public string FeelNo
        {
            get
            {
                if (_FeelNo.Length != 0)
                {
                    return "and (feelno in('" + _FeelNo + "'))";
                }
                return _FeelNo;
            }
            set { _FeelNo = value; }
        }

       /// <summary>
       /// 口味名称
       /// </summary>
        public string FeelName
        {
            get
            {
                if (_Feedname.Length != 0)
                {
                    return "and ( feelname in ('" + _Feedname + "'))";
                }
                return _Feedname;
            }
            set
            {
                _Feedname = value;
            }
        }

       

        #endregion

 

        #region SQL模板解释
        public string GetSQLFromTempl()
        {
            string str = null;
            StringBuilder strSql = new StringBuilder();

            strSql.Append(" select r.* from");
            strSql.Append("(select c.fshopid,c.comname,fk.FeelKindName,fk.FeelKind,f.FeelNo,f.FeelName,");
            strSql.Append(" f.CalcType,f.CalcAmt,ct.CalcName,fd.kindname");
            strSql.Append(" from POS_FeelKind fk inner join");
            strSql.Append(" POS_Feels f on fk.FeelKind = f.FeelKind");
            strSql.Append(" and fk.fshopid = f.fshopid and f.isrevoked = 0 inner join");
            strSql.Append(" POS_CalcType ct on f.CalcType = ct.CalcType");
            strSql.Append(" left outer join pos_foodkind fd on f.kindno = fd.kindno");
            strSql.Append(" and f.fshopid = fd.fshopid");
            strSql.Append(" inner join psm_coms c on fk.fshopid = c.fshopid and f.fshopid = c.fshopid) r");
            strSql.Append("  where feelkind > 9  and 1=1");
            str = strSql.ToString();

            //组装第一个参数(%s) -->筛选条件
            string s1 = FShopId + Kindname + FeelKindName + FeelNo + FeelName;
            str = str + s1 + "order by fshopid,feelkind";
            return str;
         
        }
        #endregion
    }
}

posted @ 2012-08-22 13:38  郑松涛  阅读(182)  评论(0编辑  收藏  举报