コード例 #1
0
 public void CategoryLoop(long CategoryId, string Path, int Depth)
 {
     string valueByCache = Maticsoft.BLL.SysManage.ConfigSystem.GetValueByCache("OpenAPI_TaoBaoAppkey");
     string appSecret = Maticsoft.BLL.SysManage.ConfigSystem.GetValueByCache("OpenAPI_TaobaoAppsecret");
     string serverUrl = Maticsoft.BLL.SysManage.ConfigSystem.GetValueByCache("OpenAPI_TaobaoApiUrl");
     Maticsoft.Model.SNS.CategorySource model = new Maticsoft.Model.SNS.CategorySource();
     ITopClient client = new DefaultTopClient(serverUrl, valueByCache, appSecret);
     ItemcatsGetRequest request = new ItemcatsGetRequest {
         Fields = "cid,parent_cid,name,is_parent",
         ParentCid = new long?(CategoryId)
     };
     ItemcatsGetResponse response = client.Execute<ItemcatsGetResponse>(request);
     if (response.ItemCats.Count > 0)
     {
         foreach (ItemCat cat in response.ItemCats)
         {
             model.CategoryId = Globals.SafeInt(cat.Cid.ToString(), 0);
             model.ParentID = Globals.SafeInt(cat.ParentCid.ToString(), 0);
             if (!this.Exists(3, model.CategoryId))
             {
                 if (string.IsNullOrEmpty(Path))
                 {
                     model.Path = cat.Cid.ToString();
                 }
                 else
                 {
                     model.Path = Path + "|" + cat.Cid.ToString();
                 }
                 model.Depth = Depth + 1;
                 model.CreatedDate = DateTime.Now;
                 model.CreatedUserID = 1;
                 model.Description = "暂无描述";
                 model.HasChildren = cat.IsParent;
                 model.IsMenu = false;
                 model.MenuIsShow = false;
                 model.MenuSequence = 0;
                 model.Name = cat.Name;
                 model.Status = 1;
                 model.Type = 0;
                 model.SourceId = 3;
                 this.Add(model);
                 this.AddCount++;
             }
             else if (this.IsUpdate((long) model.CategoryId, cat.Name, 3, model.ParentID))
             {
                 if (string.IsNullOrEmpty(Path))
                 {
                     model.Path = cat.Cid.ToString();
                 }
                 else
                 {
                     model.Path = Path + "|" + cat.Cid.ToString();
                 }
                 model.Depth = Depth + 1;
                 model.CreatedDate = DateTime.Now;
                 model.CreatedUserID = 1;
                 model.Description = "暂无描述";
                 model.HasChildren = cat.IsParent;
                 model.IsMenu = false;
                 model.MenuIsShow = false;
                 model.MenuSequence = 0;
                 model.Name = cat.Name;
                 model.Status = 1;
                 model.Type = 0;
                 model.SourceId = 3;
                 this.Update(model);
                 this.UpdateCount++;
             }
             Thread currentThread = Thread.CurrentThread;
             Thread.Sleep(500);
             if (cat.IsParent)
             {
                 this.CategoryLoop(cat.Cid, model.Path, model.Depth);
             }
         }
     }
 }
コード例 #2
0
 public Maticsoft.Model.SNS.CategorySource DataRowToModel(DataRow row)
 {
     Maticsoft.Model.SNS.CategorySource source = new Maticsoft.Model.SNS.CategorySource();
     if (row != null)
     {
         if ((row["SourceId"] != null) && (row["SourceId"].ToString() != ""))
         {
             source.SourceId = int.Parse(row["SourceId"].ToString());
         }
         if ((row["CategoryId"] != null) && (row["CategoryId"].ToString() != ""))
         {
             source.CategoryId = int.Parse(row["CategoryId"].ToString());
         }
         if (row["Name"] != null)
         {
             source.Name = row["Name"].ToString();
         }
         if (row["Description"] != null)
         {
             source.Description = row["Description"].ToString();
         }
         if ((row["ParentID"] != null) && (row["ParentID"].ToString() != ""))
         {
             source.ParentID = int.Parse(row["ParentID"].ToString());
         }
         if (row["Path"] != null)
         {
             source.Path = row["Path"].ToString();
         }
         if ((row["Depth"] != null) && (row["Depth"].ToString() != ""))
         {
             source.Depth = int.Parse(row["Depth"].ToString());
         }
         if ((row["Sequence"] != null) && (row["Sequence"].ToString() != ""))
         {
             source.Sequence = int.Parse(row["Sequence"].ToString());
         }
         if ((row["HasChildren"] != null) && (row["HasChildren"].ToString() != ""))
         {
             if ((row["HasChildren"].ToString() == "1") || (row["HasChildren"].ToString().ToLower() == "true"))
             {
                 source.HasChildren = true;
             }
             else
             {
                 source.HasChildren = false;
             }
         }
         if ((row["IsMenu"] != null) && (row["IsMenu"].ToString() != ""))
         {
             if ((row["IsMenu"].ToString() == "1") || (row["IsMenu"].ToString().ToLower() == "true"))
             {
                 source.IsMenu = true;
             }
             else
             {
                 source.IsMenu = false;
             }
         }
         if ((row["Type"] != null) && (row["Type"].ToString() != ""))
         {
             source.Type = int.Parse(row["Type"].ToString());
         }
         if ((row["MenuIsShow"] != null) && (row["MenuIsShow"].ToString() != ""))
         {
             if ((row["MenuIsShow"].ToString() == "1") || (row["MenuIsShow"].ToString().ToLower() == "true"))
             {
                 source.MenuIsShow = true;
             }
             else
             {
                 source.MenuIsShow = false;
             }
         }
         if ((row["MenuSequence"] != null) && (row["MenuSequence"].ToString() != ""))
         {
             source.MenuSequence = int.Parse(row["MenuSequence"].ToString());
         }
         if ((row["CreatedUserID"] != null) && (row["CreatedUserID"].ToString() != ""))
         {
             source.CreatedUserID = int.Parse(row["CreatedUserID"].ToString());
         }
         if ((row["CreatedDate"] != null) && (row["CreatedDate"].ToString() != ""))
         {
             source.CreatedDate = DateTime.Parse(row["CreatedDate"].ToString());
         }
         if ((row["Status"] != null) && (row["Status"].ToString() != ""))
         {
             source.Status = int.Parse(row["Status"].ToString());
         }
         if ((row["SnsCategoryId"] != null) && (row["SnsCategoryId"].ToString() != ""))
         {
             source.SnsCategoryId = new int?(int.Parse(row["SnsCategoryId"].ToString()));
         }
     }
     return source;
 }