コード例 #1
0
        /// <summary>
        /// 组装数据库查询命令
        /// </summary>
        /// <typeparam name="query">查询数据</typeparam>
        /// <param name="sql2">组装的查询命令</param>
        /// <returns>组装的查询命令</returns>
        public static string CreateSqlStr(QueryCmd query, ref string sql2)
        {
            string sql = "";
            Regex  r   = new Regex(@"^([0-9a-fA-F]{2})(([0-9a-fA-F]{2}){5})$");

            if (r.IsMatch(query.data))
            {
                //查询字段为MAC地址
                switch (query.querycmd)
                {
                case 0:    //车间数据
                    sql  = "select * from btlable where onumac = '" + query.data.ToUpper() + "'  order by boxid asc limit " + (query.page - 1) * query.number + "," + query.number;
                    sql2 = "select count(*) from btlable where onumac = '" + query.data.ToUpper() + "' order by OptDate desc";
                    break;

                case 1:    //包装数据
                    sql  = "select * from packing where mac = '" + query.data.ToUpper() + "'  order by boxid asc limit " + (query.page - 1) * query.number + "," + query.number;
                    sql2 = "select count(*) from packing where mac = '" + query.data.ToUpper() + "' order by OptDate desc";
                    break;

                case 2:    //仓库数据
                    sql  = "select * from outbound where mac = '" + query.data.ToUpper() + "'  order by boxid asc limit " + (query.page - 1) * query.number + "," + query.number;
                    sql2 = "select count(*) from outbound where mac = '" + query.data.ToUpper() + "' order by OptDate desc";
                    break;
                }
            }
            else if (query.data.IndexOf("SCDD") != -1)
            {
                //查询字段为orderid
                switch (query.querycmd)
                {
                case 0:    //车间数据

                    break;

                case 1:    //包装数据
                    sql  = "select * from packing where orderid = '" + query.data.ToUpper() + "'  order by boxid asc limit " + (query.page - 1) * query.number + "," + query.number;
                    sql2 = "select count(*) from packing where orderid = '" + query.data.ToUpper() + "' order by OptDate desc";
                    break;

                case 2:    //仓库数据
                    sql  = "select * from outbound where orderid = '" + query.data.ToUpper() + "'  order by boxid asc limit " + (query.page - 1) * query.number + "," + query.number;
                    sql2 = "select count(*) from outbound where orderid = '" + query.data.ToUpper() + "' order by OptDate desc";
                    break;
                }
            }
            else
            {
                //查询字段默认为SN
                switch (query.querycmd)
                {
                case 0:    //车间数据
                    sql  = "select * from btlable where printsn = '" + query.data.ToUpper() + "'  order by boxid asc limit " + (query.page - 1) * query.number + "," + query.number;
                    sql2 = "select count(*) from btlable where printsn = '" + query.data.ToUpper() + "' order by OptDate desc";
                    break;

                case 1:    //包装数据
                    sql  = "select * from packing where sn = '" + query.data.ToUpper() + "'  order by boxid asc limit " + (query.page - 1) * query.number + "," + query.number;
                    sql2 = "select count(*) from packing where sn = '" + query.data.ToUpper() + "' order by OptDate desc";
                    break;

                case 2:    //仓库数据
                    sql  = "select * from outbound where mac = '" + query.data.ToUpper() + "'  order by boxid asc limit " + (query.page - 1) * query.number + "," + query.number;
                    sql2 = "select count(*) from outbound where sn = '" + query.data.ToUpper() + "' order by OptDate desc";
                    break;
                }
            }

            return(sql);
        }