Commit b1766434 authored by 黄奎's avatar 黄奎

页面修改

parent c7819a02
......@@ -46,6 +46,7 @@ namespace Test.DBHelper
PrepareCommand(cmd, connection, null, cmdType, cmdText, commandParameters);
//Execute the command
int val = cmd.ExecuteNonQuery();
cmd.Parameters.Clear();
return val;
......
using Newtonsoft.Json.Linq;
using MySql.Data.MySqlClient;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.IO;
......@@ -6,7 +7,7 @@ using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using Test.DBHelper;
namespace Test.Helper
{
......@@ -25,11 +26,18 @@ namespace Test.Helper
public static void GetCategoryList()
{
string url = ApiUrl + "/apiv1/Category/get_category_list";
string jsonData = HttpGet(url, cookie);
string jsonData = HttpPost(url, cookie, "");
var list = ParseCategoryList(jsonData);
List<brandItem> brandList = new List<brandItem>();
if (list != null && list.Count > 0)
{
//string deleteSql = " TRUNCATE TABLE RB_Assess_Category; ";
//Test.DBHelper.MySqlHelper.ExecuteNonQuery(Test.DBHelper.MySqlHelper.defaultConnection, System.Data.CommandType.Text, deleteSql, null);
}
foreach (var item in list)
{
//string sql = string.Format("INSERT INTO RB_Assess_Category(Id, Name,Image,CreateDate,UpdateDate) VALUES({0},'{1}','{2}','{3}','{3}')", item.id, item.name, item.logo, DateTime.Now);
//Test.DBHelper.MySqlHelper.ExecuteNonQuery(Test.DBHelper.MySqlHelper.defaultConnection, System.Data.CommandType.Text, sql, null);
GetBrandList(item, brandList);
}
string str = "";
......@@ -73,7 +81,8 @@ namespace Test.Helper
{
category_id = rootItem.id
};
string jsonData = HttpPost(newImaApi, cookie, Newtonsoft.Json.JsonConvert.SerializeObject(data));
var postMsg = new { data };
string jsonData = HttpPost(newImaApi, cookie, Newtonsoft.Json.JsonConvert.SerializeObject(postMsg));
var list = ParseCategory(jsonData);
if (list != null && list.Count > 0)
......@@ -109,17 +118,65 @@ namespace Test.Helper
if (!string.IsNullOrEmpty(jsonData))
{
JObject rootObj = JObject.Parse(jsonData);
if (rootObj != null && !string.IsNullOrEmpty(rootObj["data"].ToString()))
if (rootObj != null && !string.IsNullOrEmpty(rootObj["result"].ToString()))
{
JObject resultObj = JObject.Parse(rootObj["data"].ToString());
if (resultObj != null)
JObject resultObj = JObject.Parse(rootObj["result"].ToString());
if (resultObj != null&&!string.IsNullOrEmpty(resultObj["data"].ToString()))
{
JArray imgArray = JArray.Parse(resultObj["img_array"].ToString());
string upload_remark = resultObj["upload_remark"].ToString();
string remark = resultObj["remark"].ToString();
string bottom_remark = resultObj["bottom_remark"].ToString();
JObject dataObj = JObject.Parse(resultObj["data"].ToString());
if (dataObj != null)
{
JArray imgArray = JArray.Parse(dataObj["img_array"].ToString());
List<object> imgList = new List<object>();
if (imgArray != null && imgArray.Count > 0)
{
foreach (var jItem in imgArray)
{
JObject imgObj = JObject.Parse(Newtonsoft.Json.JsonConvert.SerializeObject(jItem));
string sort = imgObj["sort"].ToString();
Int32.TryParse(sort, out int newSort);
imgList.Add(new
{
Name = imgObj["name"].ToString(),
Path = imgObj["full_image"].ToString(),
Sort = newSort,
});
}
}
string upload_remark = dataObj["upload_remark"].ToString();
string remark = dataObj["remark"].ToString();
string bottom_remark = dataObj["bottom_remark"].ToString();
string selectSql = "SELECT Id FROM rb_assess_brand WHERE Id=" + item.id;
var obj= Test.DBHelper.MySqlHelper.ExecuteScalar(Test.DBHelper.MySqlHelper.defaultConnection, System.Data.CommandType.Text, selectSql,null);
int Id = 0;
if (obj != null && Convert.ToInt32(obj.ToString()) > 0)
{
Id = Convert.ToInt32(obj.ToString());
}
if (Id <= 0)
{
string sql = @" INSERT INTO rb_assess_brand(Id,CategoryId,Name,Logo,PinYin,IsHot,BrandImg,CreateDate,UpdateDate,MoreDesc,RemarkDesc) ";
sql += string.Format(@" VALUES(@Id,@CategoryId,@Name,@Logo,@PinYin,@IsHot,@BrandImg,@CreateDate,@UpdateDate,@MoreDesc,@RemarkDesc) ");
var parameters = new List<MySqlParameter>();
parameters.Add(new MySqlParameter() { ParameterName = "Id", Value = item.id });
parameters.Add(new MySqlParameter() { ParameterName = "CategoryId", Value = item.category_id });
parameters.Add(new MySqlParameter() { ParameterName = "Name", Value = item.brand_name });
parameters.Add(new MySqlParameter() { ParameterName = "Logo", Value = item.logo });
parameters.Add(new MySqlParameter() { ParameterName = "PinYin", Value = item.initial });
parameters.Add(new MySqlParameter() { ParameterName = "IsHot", Value = item.ishot });
parameters.Add(new MySqlParameter() { ParameterName = "BrandImg", Value = Newtonsoft.Json.JsonConvert.SerializeObject(imgList) });
parameters.Add(new MySqlParameter() { ParameterName = "CreateDate", Value = DateTime.Now });
parameters.Add(new MySqlParameter() { ParameterName = "UpdateDate", Value = DateTime.Now });
parameters.Add(new MySqlParameter() { ParameterName = "MoreDesc", Value = bottom_remark });
parameters.Add(new MySqlParameter() { ParameterName = "RemarkDesc", Value = remark });
var res = Test.DBHelper.MySqlHelper.ExecuteNonQuery(Test.DBHelper.MySqlHelper.defaultConnection, System.Data.CommandType.Text, sql, parameters.ToArray());
}
else
{
string str = "";
}
}
}
}
}
......@@ -145,6 +202,10 @@ namespace Test.Helper
var hotList = Newtonsoft.Json.JsonConvert.DeserializeObject<List<brandItem>>(hotListStr);
if (hotList != null && hotList.Count > 0)
{
foreach (var item in hotList)
{
item.ishot = 1;
}
list.AddRange(hotList);
}
}
......@@ -173,29 +234,6 @@ namespace Test.Helper
return list;
}
/// <summary>
/// Get获取数据
/// </summary>
/// <param name="url">url地址</param>
/// <param name="encode">编码方式</param>
/// <param name="Source">来源</param>
/// <returns></returns>
static string HttpGet(string url, string cookie)
{
HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(url);
myRequest.Headers.Add("Cookie", cookie);
myRequest.Headers.Add("X-Requested-With", "XMLHttpRequest");
myRequest.Method = "GET";
HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse();
StreamReader reader = new StreamReader(myResponse.GetResponseStream(), Encoding.UTF8);
string content = reader.ReadToEnd();
reader.Close();
return content;
}
/// <summary>
/// Post提交数据
/// </summary>
......@@ -274,5 +312,10 @@ namespace Test.Helper
public string name { get; set; }
/// <summary>
/// 是否热门
/// </summary>
public int ishot { get; set; }
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment