コード例 #1
0
        public void queryDB(Dictionary <string, QueryValue> dicts)
        {
            if (qb == null || dicts == null || dicts.Count < 0)
            {
                return;
            }
            DataTable dataTable = new DataTable();

            dataTable.Columns.Add("userId");
            dataTable.Columns.Add("username");
            dataTable.Columns.Add("identityId");
            dataTable.Columns.Add("phoneNum");
            dataTable.Columns.Add("address");
            dataTable.Columns.Add("usertype");
            dataTable.Columns.Add("priceType");
            dataTable.Columns.Add("paytype");
            dataTable.Columns.Add("pursuitTimes");
            dataTable.Columns.Add("pursuitNum");
            dataTable.Columns.Add("paynum");
            dataTable.Columns.Add("time");
            dataTable.Columns.Add("operator");
            List <string> list = new List <string>();
            string        sqlStrForQueryUser = getSqlStrForQueryUser(dicts);
            DataTable     dataTable2;

            if (sqlStrForQueryUser != "")
            {
                foreach (string key in dicts.Keys)
                {
                    QueryValue queryValue = dicts[key];
                    db.AddParameter(key, queryValue.Value);
                }
                dataTable2 = db.ExecuteQuery("SELECT * FROM usersTable WHERE " + sqlStrForQueryUser + " ORDER BY createTime ASC");
                if (dataTable2 != null && dataTable2.Rows != null && dataTable2.Rows.Count > 0)
                {
                    foreach (DataRow row in dataTable2.Rows)
                    {
                        list.Add(row["permanentUserId"].ToString());
                    }
                }
            }
            string text = "";

            if (list.Count > 0)
            {
                for (int i = 0; i < list.Count; i++)
                {
                    string text2 = list[i];
                    db.AddParameter("permanentUserId" + text2, text2);
                    if (i != 0)
                    {
                        text += " OR ";
                    }
                    text = text + "permanentUserId=@permanentUserId" + text2;
                }
            }
            else if (list.Count == 0 && dicts.Count != 0 && sqlStrForQueryUser != "")
            {
                qb.initDGV(initDGV(dataTable));
                return;
            }
            TimeSpan timeSpan  = qb.getStartDT() - WMConstant.DT1970;
            TimeSpan timeSpan2 = qb.getEndDT() - WMConstant.DT1970;

            db.AddParameter("createTimeStart", string.Concat(timeSpan.TotalSeconds));
            db.AddParameter("createTimeEnd", string.Concat(timeSpan2.TotalSeconds));
            db.AddParameter("lastReadInfo", "0");
            string sqlKeys = getQueryConditionEntitys()[7].SqlKeys;

            if (dicts.ContainsKey(sqlKeys))
            {
                QueryValue queryValue2 = dicts[sqlKeys];
                db.AddParameter(sqlKeys, queryValue2.Value);
                string text3 = text;
                text = text3 + ((text == "") ? "" : (" " + queryValue2.AndOr + " ")) + sqlKeys + queryValue2.Oper + "@" + sqlKeys;
            }
            string sqlKeys2 = getQueryConditionEntitys()[8].SqlKeys;

            if (dicts.ContainsKey(sqlKeys2))
            {
                QueryValue queryValue3 = dicts[sqlKeys2];
                db.AddParameter(sqlKeys2, queryValue3.Value);
                string text4 = text;
                text = text4 + ((text == "") ? "" : (" " + queryValue3.AndOr + " ")) + sqlKeys2 + queryValue3.Oper + "@" + sqlKeys2;
            }
            dataTable2 = db.ExecuteQuery("SELECT * FROM userCardLog WHERE " + ((text == "") ? "" : ("(" + text + ") AND ")) + "time>=@createTimeStart AND time<=@createTimeEnd AND lastReadInfo=@lastReadInfo ORDER BY operationId ASC");
            if (dataTable2 != null && dataTable2.Rows != null && dataTable2.Rows.Count > 0)
            {
                foreach (DataRow row2 in dataTable2.Rows)
                {
                    db.AddParameter("permanentUserId", row2["permanentUserId"].ToString());
                    DataRow dataRow3 = db.ExecuteRow("SELECT * FROM usersTable WHERE permanentUserId=@permanentUserId");
                    if (dataRow3 == null)
                    {
                        continue;
                    }
                    db.AddParameter("typeId", dataRow3["userTypeId"].ToString());
                    DataRow dataRow4 = db.ExecuteRow("SELECT * FROM userTypeTable WHERE typeId=@typeId");
                    db.AddParameter("priceConsistId", dataRow3["userPriceConsistId"].ToString());
                    DataRow dataRow5 = db.ExecuteRow("SELECT * FROM priceConsistTable WHERE priceConsistId=@priceConsistId");
                    text = "";
                    db.AddParameter("userCardLogId", row2["operationId"].ToString());
                    string sqlKeys3 = getQueryConditionEntitys()[7].SqlKeys;
                    if (dicts.ContainsKey(sqlKeys3))
                    {
                        QueryValue queryValue4 = dicts[sqlKeys3];
                        string     text5       = "0";
                        switch (queryValue4.Value)
                        {
                        default:
                            text5 = queryValue4.Value;
                            break;

                        case "3":
                            text5 = "5";
                            break;

                        case "5":
                            text5 = "7";
                            break;
                        }
                        db.AddParameter("payType", text5);
                        text = text + "payType" + queryValue4.Oper + "@payType";
                    }
                    string sqlKeys4 = getQueryConditionEntitys()[8].SqlKeys;
                    if (dicts.ContainsKey(sqlKeys4))
                    {
                        QueryValue queryValue5 = dicts[sqlKeys4];
                        db.AddParameter(sqlKeys4, queryValue5.Value);
                        string text6 = text;
                        text = text6 + ((text == "") ? "" : (" " + queryValue5.AndOr + " ")) + sqlKeys4 + queryValue5.Oper + "@" + sqlKeys4;
                    }
                    DataTable dataTable3 = db.ExecuteQuery("SELECT * FROM payLogTable WHERE " + ((text == "") ? "" : (text + " AND ")) + "userCardLogId=@userCardLogId");
                    if (dataTable3 == null || dataTable3.Rows == null || dataTable3.Rows.Count <= 0)
                    {
                        continue;
                    }
                    foreach (DataRow row3 in dataTable3.Rows)
                    {
                        DataRow dataRow7 = dataTable.NewRow();
                        dataRow7["userId"]       = dataRow3["userId"].ToString();
                        dataRow7["username"]     = dataRow3["username"].ToString();
                        dataRow7["identityId"]   = dataRow3["identityId"].ToString();
                        dataRow7["phoneNum"]     = dataRow3["phoneNum"].ToString();
                        dataRow7["address"]      = dataRow3["address"].ToString();
                        dataRow7["usertype"]     = ((dataRow4 == null) ? "" : dataRow4["userType"].ToString());
                        dataRow7["priceType"]    = ((dataRow5 == null) ? "" : dataRow5["priceConstistName"].ToString());
                        dataRow7["paytype"]      = WMConstant.PayTypeList[Convert.ToInt64(row3["payType"])];
                        dataRow7["pursuitTimes"] = row2["consumeTimes"].ToString();
                        dataRow7["pursuitNum"]   = row3["pursuitNum"].ToString();
                        dataRow7["paynum"]       = row3["totalPrice"].ToString();
                        dataRow7["time"]         = WMConstant.DT1970.AddSeconds(ConvertUtils.ToDouble(row2["time"].ToString())).ToString("yyyy-MM-dd HH:mm:ss");
                        dataRow7["operator"]     = row2["operator"].ToString();
                        dataTable.Rows.Add(dataRow7);
                        dataTable.AcceptChanges();
                    }
                }
            }
            qb.initDGV(initDGV(dataTable));
        }