Exemplo n.º 1
0
        public Trial getTrialById(string pltfm, string pdct, string userId, string date)
        {
            Trial ret = null;

            if (con != null)
            {
                try
                {
                    if (con.State != ConnectionState.Open)
                    {
                        con.Open();
                    }

                    string       query = @"select * from tabTrials where 
                                    trialPltfmName=@pltfm and
                                    trialPdctName=@pdct and
                                    trialUserId=@userId and
                                    trialDate=@date;";
                    MySqlCommand cmd   = new MySqlCommand();
                    cmd.Connection  = con;
                    cmd.CommandText = query;
                    cmd.Parameters.AddWithValue("@pltfm", pltfm);
                    cmd.Parameters.AddWithValue("@pdct", pdct);
                    cmd.Parameters.AddWithValue("@userId", userId);
                    cmd.Parameters.AddWithValue("@date", date);

                    using (MySqlDataReader reader = cmd.ExecuteReader())
                    {
                        if (reader.Read())
                        {
                            ret = new Trial();
                        }
                        ret.Id            = reader.GetInt32(0);
                        ret.TrPltfmName   = reader.GetString(1);
                        ret.TrPdctName    = reader.GetString(2);
                        ret.TrUserId      = reader.GetString(3);
                        ret.TrDate        = reader.GetString(4);
                        ret.TrSummaryPath = reader.GetString(5);
                        ret.TrDebugPath   = reader.GetString(6);
                        ret.TrInfo        = reader.GetString(7);
                        ret.TrOperator    = reader.GetString(8);
                        Console.WriteLine(ret);
                    }
                }
                catch (Exception ex)
                {
                    MyLogger.WriteLine(ex.Message);
                }
            }
            return(ret);
        }
Exemplo n.º 2
0
        //获取某条trial 记录
        public Trial getTrialByUidDate(string uid, string datestr)
        {
            Trial ret = new Trial();

            if (con != null)
            {
                try
                {
                    if (con.State != ConnectionState.Open)
                    {
                        con.Open();
                    }
                    MyLogger.WriteLine("date:" + datestr + " userid:" + uid);
                    string       queryPage = @"select * from tabTrials where trialUserId=@userId 
                                         and trialDate=@datestr";
                    MySqlCommand cmd       = new MySqlCommand();
                    cmd.Connection  = con;
                    cmd.CommandText = queryPage;
                    cmd.Parameters.AddWithValue("@userId", uid);
                    cmd.Parameters.AddWithValue("@datestr", datestr);

                    //查询Trial记录,并封装到类
                    using (MySqlDataReader reader = cmd.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            ret.Id            = reader.GetInt32(0);
                            ret.TrPltfmName   = reader.GetString(1);
                            ret.TrPdctName    = reader.GetString(2);
                            ret.TrUserId      = reader.GetString(3);
                            ret.TrDate        = reader.GetString(4);
                            ret.TrSummaryPath = reader.GetString(5);
                            ret.TrDebugPath   = reader.GetString(6);
                            ret.TrInfo        = reader.GetString(7);
                            ret.TrOperator    = reader.GetString(8);
                        }
                        MyLogger.WriteLine("get trial ok!" + ret);
                    }
                }
                catch
                {
                    MyLogger.WriteLine("when query page trial list error!");
                }
            }
            return(ret);
        }
Exemplo n.º 3
0
        public List <Trial> getPageListByuid(int pageNow, int pageSize, string userId, ref int pageCount)
        {
            int          rowCount  = 0;
            List <Trial> trialList = null;

            //防止不正确的页数
            if (pageNow < 1)
            {
                pageNow = 1;
            }

            //开始分页操作
            if (con != null)
            {
                try
                {
                    if (con.State != ConnectionState.Open)
                    {
                        con.Open();
                    }

                    string       query = @"select count(*) from tabTrials where trialUserId=@userId;";
                    MySqlCommand cmd   = new MySqlCommand();
                    cmd.Connection  = con;
                    cmd.CommandText = query;
                    cmd.Parameters.AddWithValue("@userId", userId);

                    //查询记录数
                    using (MySqlDataReader reader = cmd.ExecuteReader())
                    {
                        if (reader.Read())
                        {
                            rowCount = reader.GetInt32(0);
                        }
                        MyLogger.WriteLine("tabTrials has " + rowCount + " lines");
                    }

                    if (rowCount == 0)
                    {
                        return(trialList);
                    }
                    else
                    {
                        trialList = new List <Trial>();
                    }
                }
                catch (Exception ex)
                {
                    MyLogger.WriteLine(ex.Message);
                }

                try
                {
                    //配置要查询的行数,页数
                    pageCount = (rowCount - 1) / pageSize + 1;

                    int rowStart = (pageNow - 1) * pageSize;
                    //查询记录
                    string       queryPage = @"select * from tabTrials where trialUserId=@userId limit @start,@size";
                    MySqlCommand cmd       = new MySqlCommand();
                    cmd.Connection  = con;
                    cmd.CommandText = queryPage;
                    cmd.Parameters.AddRange(new MySqlParameter[] {
                        new MySqlParameter("@userId", userId),
                        new MySqlParameter("@start", rowStart),
                        new MySqlParameter("@size", pageSize),
                    });

                    //查询Trial记录,并封装到类
                    using (MySqlDataReader reader = cmd.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            Trial ret = new Trial();
                            ret.Id            = reader.GetInt32(0);
                            ret.TrPltfmName   = reader.GetString(1);
                            ret.TrPdctName    = reader.GetString(2);
                            ret.TrUserId      = reader.GetString(3);
                            ret.TrDate        = reader.GetString(4);
                            ret.TrSummaryPath = reader.GetString(5);
                            ret.TrDebugPath   = reader.GetString(6);
                            ret.TrInfo        = reader.GetString(7);
                            ret.TrOperator    = reader.GetString(8);
                            trialList.Add(ret);
                        }
                    }
                }
                catch
                {
                    MyLogger.WriteLine("when query page trial list error!");
                }
            }
            return(trialList);
        }