FrmFarmMain.cs
上传用户:xhd1221
上传日期:2022-05-28
资源大小:186k
文件大小:62k
源码类别:

外挂编程

开发平台:

C/C++

  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Text;
  7. using System.Windows.Forms;
  8. using System.Threading;
  9. using System.Web;
  10. using System.IO;
  11. using System.Collections;
  12. using Json;
  13. namespace QQWinFarm
  14. {
  15.     public partial class FrmFarmMain : Form
  16.     {
  17.         #region 变量定义
  18.         NewsBog newsbog = new NewsBog();
  19.         private System.Net.CookieContainer cookie = new System.Net.CookieContainer();
  20.         JsonObject _status_filter = new JsonObject("{}");//可操作好友列表
  21.         JsonObject model; //json模板
  22.         JsonObject _status; //用户农场信息
  23.         JsonObject _qzonefriends; //QQ空间 好友列表
  24.         string _qzonefriendsIds = ""; //QQ空间 好友 ID集合
  25.         JsonObject _xiaoyoufriends; //校友 好友列表
  26.         string _xiaoyoufriendsIds = "";//校友 好友 ID集合
  27.         JsonObject _shop; //商店
  28.         Thread thread1, thread2; //进程 1  可操作好友查询  2 操作好友
  29.         string _uid = "0"; //user id
  30.         bool _autoweed = true; //自动除草 
  31.         bool _autonorm = true; //自动杀虫 
  32.         bool _autowater = true; //自动浇水 
  33.         bool _autoplant = true; //自动种植
  34.         bool _autosteal = true; //自动收获
  35.         bool _autoscarify = true; //自动翻地
  36.         bool _autoseed = true; //自动购买种子
  37.         bool _autobag = true; //查看背包
  38.         bool _autodog = true;
  39.         int _userInfoTime = 0;//用户信息刷新执行时间
  40.         int _userInfoUpTime = 60 * 5;//用户信息刷新时间
  41.         bool _autoWookBool = true; //是否工作
  42.         int _aotuWookTime = 0;//工作执行时间
  43.         int updateTime = 0;  //更新时间
  44.         string _autourl = "";//默认获取地址
  45.         string _autoxiaoyouurl = "http://happyfarm.xiaoyou.qq.com";//校友api URL
  46.         string _autoqzoneurl = "http://happyfarm.qzone.qq.com";//校友api URL
  47.         int setUpTime = 0; //执行的时间
  48.         string xiaoyouUrl = "http://nc.xiaoyou.qq.com";//校友地址
  49.         string qzoneUrl = "http://nc.qzone.qq.com";//QQ空间地址
  50.         string runUrl = ""; //操作好友时 运行的url
  51.         int runFriends = 0;
  52.         #endregion
  53.         #region 构造方法
  54.         public FrmFarmMain()
  55.         {
  56.             InitializeComponent();
  57.         }
  58.         public FrmFarmMain(System.Net.CookieContainer cookie)
  59.         {
  60.             InitializeComponent();
  61.             this.cookie = cookie;
  62.         }
  63.         #endregion
  64.         #region 页面打开和关闭
  65.         private void FrmFarmMain_Load(object sender, EventArgs e)
  66.         {
  67.             runFriends = Convert.ToInt32(txtFriends.Text.Trim());
  68.             updateTime = Convert.ToInt32(upTime.Text.Trim());
  69.             setUpTime = updateTime;
  70.             PanelError();
  71.             thread1 = new Thread(new ThreadStart(this.BindUserInfo));
  72.             thread1.Start();
  73.         }
  74.         private void FrmFarmMain_FormClosed(object sender, FormClosedEventArgs e)
  75.         {
  76.             Dispose();
  77.             System.Environment.Exit(System.Environment.ExitCode);
  78.             #region 说明
  79.             /*
  80.             System.Environment.Exit(System.Environment.ExitCode);  
  81.             this.Dispose();
  82.             this.Close();
  83.             还有一种方法:  System.Threading.Thread.CurrentThread.Abort();
  84.             或者          Process.GetCurrentProcess().Kill() 
  85.             或者        Application.ExitThread();
  86.             或者        Application.ExitThread() 
  87.             Application.Exit(); 方法停止在所有线程上运行的所有消息循环,并关闭应用程序的所有窗口
  88.             Application.Exit 是一种强行退出方式,就像 Win32 的 PostQuitMessage()。它意味着放弃所有消息泵,展开调用堆栈,并将执行返回给系统。
  89.              */
  90.             #endregion
  91.         }
  92.         #endregion
  93.         #region 扫描好友
  94.         private void timer1_Tick(object sender, EventArgs e)
  95.         {
  96.             if (txtFriends.Text.Trim() == "")
  97.             {
  98.                 txtFriends.Text = "0";
  99.             }
  100.             //runFriends = Convert.ToInt32(txtFriends.Text.Trim());
  101.             if (thread2 == null)
  102.             {
  103.                 thread2 = new Thread(new ThreadStart(this.AutoRun));
  104.             }
  105.             if (thread1.IsAlive || thread2.IsAlive)
  106.             {
  107.                 return;
  108.             }
  109.             if (_status_filter.Count >0)
  110.             {
  111.                 return;
  112.             }
  113.             if (runFriends >= Convert.ToInt32(txtFriends.Text.Trim()))
  114.             {
  115.                 //ChangeTSSL("");
  116.                 runFriends = 0;
  117.                 thread1 = new Thread(new ThreadStart(this.statusFilter));
  118.                 thread1.Start();
  119.             }
  120.             else
  121.             {
  122.                 runFriends++;
  123.                 int shengyu = (Convert.ToInt32(txtFriends.Text.Trim()) - runFriends) + 1;
  124.                 ChangeTSSL("距离下次执行时间还有:" + shengyu + "秒");
  125.             }
  126.         }
  127.         #endregion
  128.         #region timer2 执行好友
  129.         private void timer2_Tick(object sender, EventArgs e)
  130.         {
  131.            
  132.             if(upTime.Text.Trim()=="")
  133.             {
  134.                 upTime.Text="0";
  135.             }
  136.             updateTime = Convert.ToInt32(upTime.Text.Trim());
  137.             if (thread2 == null)
  138.             {
  139.                 thread2 = new Thread(new ThreadStart(this.AutoRun));
  140.             }
  141.             if (thread1.IsAlive || thread2.IsAlive)
  142.             {
  143.                 return;
  144.             }
  145.             if (_status_filter.Count <1)
  146.             {
  147.                 return;
  148.             }
  149.             if (setUpTime >= updateTime)
  150.             {
  151.                 //ChangeTSSL("");
  152.                 setUpTime = 0;
  153.                 thread2 = new Thread(new ThreadStart(this.AutoRun));
  154.                 thread2.Start();
  155.             }
  156.             else
  157.             {
  158.                 setUpTime++;
  159.                 int shengyu = (updateTime - setUpTime) + 1;
  160.                 ChangeTSSL("距离下次执行时间还有:" + shengyu + "秒");
  161.             }
  162.         } 
  163.         #endregion
  164.         #region 格式化等级经验显示
  165.         /// <summary> 
  166.         /// 格式化等级经验显示 
  167.         /// </summary> 
  168.         /// <param name="exp"></param> 
  169.         /// <param name="lv"></param> 
  170.         /// <returns></returns> 
  171.         private string FormatExp(int exp, out int lv)
  172.         {
  173.             int level = 0;
  174.             while (exp > (level * 200) + 200)
  175.             {
  176.                 exp -= (level * 200) + 200;
  177.                 level++;
  178.             }
  179.             lv = level;
  180.             return exp + "/" + ((level * 200) + 200);
  181.         }  
  182.         #endregion
  183.         #region 绑定用户信息
  184.         /// <summary> 
  185.         /// 绑定用户信息 
  186.         /// </summary> 
  187.         private void BindUserInfo()
  188.         {
  189.             ChangeTSSL("正在获取农场信息...");
  190.             if (_uid == "0")
  191.                 GetUsrInfo();
  192.             if (_shop == null)
  193.                 this._shop = new JsonObject(ScanShop());
  194.             if (_qzonefriends == null || _xiaoyoufriends == null)
  195.                 ListFriends();
  196.             ChangeTSSL("成功获取农场信息!");
  197.         }
  198.         #endregion
  199.         #region 运行农场操作
  200.         private void AutoRun()
  201.         {
  202.             _autosteal = chbSteal.Checked;//摘取
  203.             _autoweed = chbClearWeed.Checked;//除草
  204.             _autowater = chbWater.Checked;//浇水
  205.             _autonorm = chbSpraying.Checked;//杀虫 
  206.             _autoscarify = chbScarify.Checked;//铲除
  207.             _autoplant = chbPlant.Checked;//种植
  208.             _autoseed = chbSeed.Checked;//购买
  209.             _autobag = chbBag.Checked;//背包
  210.             _autodog = chkDog.Checked;
  211.             if (_status_filter.Count < 1)
  212.                 thread2.Abort();
  213.             JsonObject _statusModel = _status_filter.GetJson(0);
  214.             JsonObject _statusModel_1 = _statusModel.GetJson(0);
  215.             if (_statusModel_1 == null)
  216.                 thread2.Abort();
  217.             _status_filter.Remove(_statusModel);
  218.            
  219.             /*
  220.             0:1 干旱
  221.             1 > 0有手
  222.             2:1有草
  223.             3:1有虫
  224.              */
  225.             #region 局部变量
  226.             string frienduid = _statusModel_1.Key;
  227.             JsonObject _friends = _xiaoyoufriends;
  228.             string url = _statusModel.GetValue("url");
  229.             string frienduName = "";
  230.             string urlTitle = "";
  231.             string _autostealstr = "";//摘取
  232.             string _autoweedstr = "";//除草
  233.             string _autowaterstr = "";//浇水
  234.             string _autonormstr = "";//杀虫 
  235.             string _autoscarifystr = "";//铲除
  236.             string _autoplantstr = "";//种植
  237.             switch (url)
  238.             {
  239.                 case "xiaoyou":
  240.                     _friends = _xiaoyoufriends;
  241.                     urlTitle = "校友";
  242.                     runUrl = "http://nc.xiaoyou.qq.com";
  243.                     break;
  244.                 case "qzone":
  245.                     _friends = _qzonefriends;
  246.                     urlTitle = "QQ空间";
  247.                     runUrl = "http://nc.qzone.qq.com";
  248.                     break;
  249.             }
  250.             #region 查找好友名称
  251.             string _msg = "";
  252.             if (frienduid != _uid)
  253.             {
  254.                 for (int i = 0; i < _friends.GetCollection().Count; i++)
  255.                 {
  256.                     if (_friends.GetCollection()[i].GetValue("userId") == frienduid)
  257.                     {
  258.                         frienduName = Utils.ConvertUnicodeStringToChinese(_friends.GetCollection()[i].GetValue("userName"));
  259.                         _msg = "查看 " + urlTitle + " 好友【" + frienduName + "】";
  260.                     }
  261.                 }
  262.             }
  263.             else
  264.             {
  265.                 _msg = "查看 自己 农场";
  266.             }
  267.             ChangeLBFM(_msg);
  268.             ChangeTSSL(_msg);
  269.             #endregion
  270.             #endregion
  271.             _statusModel_1 = new JsonObject(_statusModel_1[frienduid]);
  272.             #region 判断是否需要操作
  273.             if (!frienduid.Contains(_uid))
  274.             {
  275.                 bool _autorun = false;
  276.                 string _autostr = "";
  277.                 if (_autowater)
  278.                 {
  279.                     _autostr = _statusModel_1.GetValue("0");
  280.                     if (_autostr != null && Convert.ToInt32(_autostr) > 0)
  281.                         _autorun = true;
  282.                 }
  283.                 if (_autosteal)
  284.                 {
  285.                    
  286.                     _autostr = _statusModel_1.GetValue("1");
  287.                     if (_autostr != null && Convert.ToInt64(_autostr)>0)
  288.                     {
  289.                         _autorun = true;
  290.                         //double times = 0;
  291.                         //double durtime = Convert.ToInt64(times + Convert.ToInt64(_autostr));
  292.                         //if (durtime < now)//成熟 
  293.                         //    _autorun = true;
  294.                     }
  295.                 }
  296.                 if (_autoweed)
  297.                 {
  298.                     _autostr = _statusModel_1.GetValue("2");
  299.                     if (_autostr != null && Convert.ToInt32(_autostr) > 0)
  300.                         _autorun = true;
  301.                 }
  302.                 if (_autonorm)
  303.                 {
  304.                     _autostr = _statusModel_1.GetValue("3");
  305.                     if (_autostr != null && Convert.ToInt32(_autostr) > 0)
  306.                         _autorun = true;
  307.                 }
  308.                 if (!_autorun)
  309.                 {
  310.                     thread2.Abort();
  311.                 }
  312.             } 
  313.             #endregion
  314.           
  315.             
  316.             //加载土地信息
  317.             string result = ShowFriend(frienduid, runUrl);
  318.             JsonObject lands = new JsonObject(result);
  319.           
  320.             double nowtime = (DateTime.Now - new DateTime(1970, 1, 1, 8, 0, 0)).TotalSeconds;
  321.             double servertime = nowtime;
  322.             if (lands.GetJson("user") != null && lands.GetJson("user").GetJson("healthMode") != null)
  323.             {
  324.                 if (lands.GetJson("user").GetJson("healthMode").GetValue("serverTime") != null)
  325.                 {
  326.                     servertime = Convert.ToInt32(lands.GetJson("user").GetJson("healthMode").GetValue("serverTime"));
  327.                 }
  328.             }
  329.             FarmKey.NetworkDelay = nowtime - servertime;
  330.             if (lands.GetValue("pf") != null && lands.GetValue("pf") != "1")
  331.             {
  332.                 if (6 <= DateTime.Now.Hour && DateTime.Now.Hour >= 0)
  333.                 {
  334.                     ChangeLBFM("保护模式");
  335.                 }
  336.             }
  337.             #region 循环 地
  338.             for (int j = 0; j < lands.GetCollection("farmlandStatus").GetCollection().Count; j++)
  339.             {
  340.                 //bool s = false;
  341.                 //double times = 0;
  342.                 /*//if (lands.GetCollection("farmlandStatus").GetCollection()[j].GetValue("j").Equals("0")) 
  343.                 //{ 
  344.                 for (int x = 0; x < _shop.GetCollection().Count; x++)
  345.                 {
  346.                     if (_shop.GetCollection()[x].GetValue("cId").Equals(lands.GetCollection("farmlandStatus").GetCollection()[j].GetValue("a")))//不是空地 
  347.                     {
  348.                         ChangeLBFM("第" + (j + 1) + "块地种植了【" + Utils.ConvertUnicodeStringToChinese(_shop.GetCollection()[x].GetValue("cName")) + "】");
  349.                         s = true;
  350.                         times = Convert.ToInt64(_shop.GetCollection()[x].GetValue("growthCycle"));
  351.                         break;
  352.                     }
  353.                 }
  354.                 //} */
  355.                 #region 是否有庄稼
  356.                 if (Convert.ToInt32(lands.GetCollection("farmlandStatus").GetCollection()[j].GetValue("a")) > 0)
  357.                 {
  358.                     //double durtime = Convert.ToInt64(times + Convert.ToInt64(lands.GetCollection("farmlandStatus").GetCollection()[j].GetValue("b")));
  359.                     //if (durtime < now)//成熟 
  360.                     string farmlandStatus_b = lands.GetCollection("farmlandStatus").GetCollection()[j].GetValue("b");
  361.                     #region 可摘取判断
  362.                     if (farmlandStatus_b == "6")
  363.                     {
  364.                         //ChangeLBFM("第" + (j + 1) + "块地成熟");
  365.                         int farmlandStatus_m = Convert.ToInt32(lands.GetCollection("farmlandStatus").GetCollection()[j].GetValue("m"));//剩余数
  366.                         int farmlandStatus_l = Convert.ToInt32(lands.GetCollection("farmlandStatus").GetCollection()[j].GetValue("l"));//可摘取数
  367.                         JsonObject farmlandStatus_n = lands.GetCollection("farmlandStatus").GetCollection()[j].GetJson("n");//摘取记录
  368.                         string ModelRawjson = "";
  369.                         if (farmlandStatus_n != null)
  370.                         {
  371.                             ModelRawjson = farmlandStatus_n.ToString();
  372.                         }
  373.                         if (frienduid.Contains(_uid)||(farmlandStatus_m > farmlandStatus_l && (farmlandStatus_n == null || !ModelRawjson.Contains(_uid))))//没有偷过 
  374.                         {
  375.                             if (_autosteal)
  376.                             {
  377.                                 ChangeLBFM("第 " + (j+1) + " 块可以采摘,开始摘取...");
  378.                                 bool _rundog = false;
  379.                                 #region 查看是否有狗
  380.                                 if (lands.GetJson("dog") != null)
  381.                                 {
  382.                                     if (lands.GetJson("dog").GetValue("isHungry") == "0")
  383.                                     {
  384.                                         if (_autodog)
  385.                                         {
  386.                                             _rundog = true;
  387.                                             ChangeLBFM("此好友 有狗...");
  388.                                         }
  389.                                         else
  390.                                         {
  391.                                             ChangeLBFM("未开启-不摘有狗");
  392.                                         }
  393.                                     }
  394.                                 }
  395.                                 #endregion
  396.                                 if (frienduid.Contains(_uid))
  397.                                     Harvest(_uid, j.ToString());
  398.                                 else
  399.                                 {
  400.                                     if (!_rundog)
  401.                                         Steal(frienduid, j.ToString());
  402.                                 }
  403.                                 //ChangeLBFM("成功摘取...");
  404.                             }
  405.                             if (_autostealstr != "") _autostealstr += ",";
  406.                             _autostealstr += j.ToString();
  407.                         }
  408.                         //else
  409.                         //{
  410.                         //    ChangeLBFM("已经摘取或到最低限额,不可摘取");
  411.                         //}
  412.                     }
  413.                     //else
  414.                     //{
  415.                     //    ChangeLBFM("未成熟,不可摘取");
  416.                     //} 
  417.                     #endregion
  418.                     #region 判断庄稼枯萎
  419.                     //string farmlandStatus_j = lands.GetCollection("farmlandStatus").GetCollection()[j].GetValue("j");
  420.                     if (farmlandStatus_b == "7")//lands.GetCollection("farmlandStatus").GetCollection()[j].GetValue("j").Equals("1")||
  421.                     {
  422.                         if (_autoscarifystr != "") _autoscarifystr += ",";
  423.                         _autoscarifystr += j.ToString();
  424.                     } 
  425.                     #endregion
  426.                     #region 是否有草判断 //除草 f代表有几棵草 0为没有 k为产量,为0时即尚未成熟 成熟的植物不长草的
  427.                     if (!lands.GetCollection("farmlandStatus").GetCollection()[j].GetValue("f").Equals("0") && lands.GetCollection("farmlandStatus").GetCollection()[j].GetValue("k").Equals("0"))
  428.                     {
  429.                         ChangeLBFM("第 " + (j + 1) + " 块地有草,开始除草...");
  430.                         for (int x = 0; x < Convert.ToInt32(lands.GetCollection("farmlandStatus").GetCollection()[j].GetValue("f")); x++)
  431.                         {
  432.                             if (_autoweed || frienduid.Contains(_uid))
  433.                             {
  434.                                 //ChangeLBFM("第 " + _autoweedstr + " 块地有草,开始除草...");
  435.                                 ClearWeed(frienduid, j.ToString() );
  436.                                 // ChangeLBFM("第 " + _autoweedstr + " 块地 除草成功");
  437.                             }
  438.                             if (_autoweedstr != "") _autoweedstr += ",";
  439.                             _autoweedstr += j.ToString();
  440.                             //ClearWeed(frienduid, j.ToString());
  441.                         }
  442.                         //ChangeLBFM("第 " + (j + 1) + " 块地 除草成功");
  443.                     }
  444.                     #endregion
  445.                     #region 是否需浇水
  446.                     if (!lands.GetCollection("farmlandStatus").GetCollection()[j].GetValue("h").Equals("1"))//浇水 
  447.                     {
  448.                         ChangeLBFM("第 " + (j + 1) + " 块地干燥,开始浇水...");
  449.                         if (_autowater || frienduid.Contains(_uid))
  450.                         {
  451.                             
  452.                            // ChangeLBFM("第 " + _autowaterstr + " 块地干燥,开始浇水...");
  453.                             Water(frienduid, j.ToString());
  454.                             
  455.                         }
  456.                         if (_autowaterstr != "") _autowaterstr += ",";
  457.                         _autowaterstr += j.ToString();
  458.                         
  459.                         //Water(frienduid, j.ToString());
  460.                         //ChangeLBFM("第 " + (j + 1) + " 块地 浇水成功");
  461.                     }
  462.                     #endregion
  463.                     #region 是否需杀虫
  464.                     if (!lands.GetCollection("farmlandStatus").GetCollection()[j].GetValue("g").Equals("0") && lands.GetCollection("farmlandStatus").GetCollection()[j].GetValue("k").Equals("0"))//杀虫 g代表有几条虫 0为没有 k为产量,为0时即尚未成熟 成熟的植物不长虫的 
  465.                     {
  466.                         ChangeLBFM("第 " + (j + 1) + " 块地有虫,开始杀虫...");
  467.                         for (int x = 0; x < Convert.ToInt32(lands.GetCollection("farmlandStatus").GetCollection()[j].GetValue("g")); x++)
  468.                         {
  469.                             if (_autonorm || frienduid.Contains(_uid))
  470.                             {
  471.                                 //ChangeLBFM("第 " + _autonormstr + " 块地有虫,开始杀虫...");
  472.                                 Spraying(frienduid, j.ToString());
  473.                                 //ChangeLBFM("第 " + _autonormstr + " 块地 杀虫成功");
  474.                             }
  475.                             if (_autonormstr != "") _autonormstr += ",";
  476.                             _autonormstr += j.ToString();
  477.                             // Spraying(frienduid, j.ToString());
  478.                         }
  479.                         //ChangeLBFM("第 " + (j + 1) + " 块地 杀虫成功");
  480.                     }
  481.                     #endregion
  482.                 }
  483.                 else
  484.                 {
  485.                     if (frienduid.Contains(_uid))
  486.                     {
  487.                         if (_autoplantstr != "") _autoplantstr += ",";
  488.                         _autoplantstr += j.ToString();
  489.                     }
  490.                 }
  491.                 #endregion
  492.             }
  493.             #endregion
  494.             #region 摘取
  495.             if (_autostealstr != "")
  496.             {
  497.                 if (_autosteal || frienduid.Contains(_uid))
  498.                 {
  499.                     /*
  500.                     ChangeLBFM("第 " + _autostealstr + " 块可以采摘,开始摘取...");
  501.                     bool _rundog = false;
  502.                     #region 查看是否有狗
  503.                     if (lands.GetJson("dog") != null)
  504.                     {
  505.                         if (lands.GetJson("dog").GetValue("isHungry") == "0")
  506.                         {
  507.                             if (_autodog)
  508.                             {
  509.                                 _rundog = true;
  510.                                 ChangeLBFM("此好友 有狗...");
  511.                             }
  512.                             else
  513.                             {
  514.                                 ChangeLBFM("未开启-不摘有狗");
  515.                             }
  516.                         }
  517.                     }
  518.                     #endregion
  519.                     if (frienduid.Contains(_uid))
  520.                         Harvest(_uid, _autostealstr);
  521.                     else
  522.                     {
  523.                         if (!_rundog)
  524.                             Steal(frienduid, _autostealstr);
  525.                     }
  526.                     */
  527.                     //ChangeLBFM("成功摘取...");
  528.                 }
  529.                 else
  530.                 {
  531.                     ChangeLBFM("未开启自动摘取");
  532.                 }
  533.             }
  534.             #endregion
  535.             #region 除草
  536.             if (_autoweedstr != "" )
  537.             {
  538.                 if (_autoweed || frienduid.Contains(_uid))
  539.                 {
  540.                     //ChangeLBFM("第 " + _autoweedstr + " 块地有草,开始除草...");
  541.                     //ClearWeed(frienduid, _autoweedstr);
  542.                     // ChangeLBFM("第 " + _autoweedstr + " 块地 除草成功");
  543.                 }
  544.                 else
  545.                 {
  546.                     ChangeLBFM("未开启自动除草");
  547.                 }
  548.             }
  549.             #endregion
  550.             #region 浇水
  551.             if (_autowaterstr != "" )
  552.             {
  553.                 if (_autowater || frienduid.Contains(_uid))
  554.                 {
  555.                     /*
  556.                     ChangeLBFM("第 " + _autowaterstr + " 块地干燥,开始浇水...");
  557.                     Water(frienduid, _autowaterstr);
  558.                     */
  559.                 }
  560.                 else
  561.                 {
  562.                     ChangeLBFM("未开启自动浇水");
  563.                 }
  564.             }
  565.             #endregion
  566.             #region 杀虫
  567.             if (_autonormstr != "" )
  568.             {
  569.                 if (_autonorm || frienduid.Contains(_uid))
  570.                 {
  571.                     ChangeLBFM("第 " + _autonormstr + " 块地有虫,开始杀虫...");
  572.                     Spraying(frienduid, _autonormstr);
  573.                     //ChangeLBFM("第 " + _autonormstr + " 块地 杀虫成功");
  574.                 }
  575.                 else
  576.                 {
  577.                     ChangeLBFM("未开启自动杀虫");
  578.                 }
  579.             }
  580.             #endregion
  581.             #region 铲除
  582.             if (_autoscarifystr != "")
  583.             {
  584.                 if (frienduid.Contains(_uid))
  585.                 {
  586.                     if (_autoscarify)
  587.                     {
  588.                         ChangeLBFM("第 " + _autoscarifystr + " 块地枯萎,开始翻地...");
  589.                         Scarify(frienduid, _autoscarifystr);
  590.                         _autoplantstr = _autoscarifystr;
  591.                         //ChangeLBFM("第 " + _autonormstr + " 块地 杀虫成功");
  592.                     }
  593.                     else
  594.                     {
  595.                         ChangeLBFM("未开启自动翻地");
  596.                     }
  597.                 }
  598.             }
  599.             #endregion
  600.             #region 种植
  601.             if (_autoplantstr != "")
  602.             {
  603.                 if (_autoplant)
  604.                 {
  605.                     if (frienduid.Contains(_uid))
  606.                     {
  607.                         ChangeLBFM("第 " + _autoplantstr + " 块地是空地");
  608.                         string[] plantIds = _autoplantstr.Split(',');
  609.                         int plantIdsIndex = 0;
  610.                         int number = 0;
  611.                         string key = "";
  612.                         string value = "";
  613.                         Hashtable plantht = new Hashtable();
  614.                         if (_autobag)
  615.                         {
  616.                             JsonObject bag = new JsonObject(GetBag());
  617.                             ChangeLBFM("开始查看背包...");
  618.                             for (int y = 0; y < bag.GetCollection().Count; y++)
  619.                             {
  620.                                 if (plantIdsIndex >= plantIds.Length) break;
  621.                                 if (bag.GetCollection()[y].GetValue("type").Equals("1"))
  622.                                 {
  623.                                     key = bag.GetCollection()[y].GetValue("cId");
  624.                                     value = "";
  625.                                     if (plantht.ContainsKey(key))
  626.                                     {
  627.                                         value = plantht[key].ToString();
  628.                                         plantht.Remove(key);
  629.                                     }
  630.                                     for (int ount = 0; ount < Convert.ToInt32(bag.GetCollection()[y].GetValue("amount")); ount++)
  631.                                     {
  632.                                         if (plantIdsIndex >= plantIds.Length) break;
  633.                                         if (value != "") value += ",";//amount
  634.                                         value += plantIds[plantIdsIndex];
  635.                                         plantIds[plantIdsIndex] = null;
  636.                                         plantIdsIndex++;
  637.                                     }
  638.                                     plantht.Add(key, value);
  639.                                 }
  640.                             }
  641.                         }
  642.                         else
  643.                         {
  644.                             ChangeLBFM("未开启查看背包");
  645.                         }
  646.                         key = "Seed";
  647.                         for (int n = 0; n < plantIds.Length; n++)
  648.                         {
  649.                             if (plantIds[n] != null)
  650.                             {
  651.                                 value = "";
  652.                                 if (plantht.ContainsKey(key))
  653.                                 {
  654.                                     value = plantht[key].ToString();
  655.                                     plantht.Remove(key);
  656.                                 }
  657.                                 if (value != "") value += ",";
  658.                                 value += plantIds[n];
  659.                                 plantht.Add(key, value);
  660.                                 number++;
  661.                             }
  662.                         }
  663.                         if (plantht.ContainsKey(key))
  664.                         {
  665.                             value = plantht[key].ToString();
  666.                             plantht.Remove(key);
  667.                             if (_autoplant)
  668.                             {
  669.                                 key = GetShopLv();
  670.                                 if (key != null)
  671.                                 {
  672.                                     ChangeLBFM("开始购买 " + Utils.NoHTML(Utils.ConvertUnicodeStringToChinese(GetShopModel(key).GetValue("cName"))) + " " + number + "个");
  673.                                     Seed(_uid, key, number);
  674.                                     plantht.Add(key, value);
  675.                                 }
  676.                                 else
  677.                                 {
  678.                                     ChangeLBFM("没有同一等级的种子");
  679.                                 }
  680.                             }
  681.                             else
  682.                             {
  683.                                 ChangeLBFM("未开启自动购买");
  684.                             }
  685.                         }
  686.                         foreach (DictionaryEntry plant in plantht)
  687.                         {
  688.                             ChangeLBFM("开始种地...");
  689.                             Plant(plant.Key.ToString(), _uid, plant.Value.ToString());
  690.                         }
  691.                     }
  692.                 }
  693.                 else
  694.                 {
  695.                     ChangeLBFM("未开启自动种植");
  696.                 } 
  697.             #endregion
  698.             }
  699.             thread2.Abort();
  700.         }
  701.         #endregion
  702.         #region 查看自己购买的物品 
  703.         /// <summary> 
  704.         /// 查看自己购买的物品 
  705.         /// </summary> 
  706.         /// <param name="uid"></param> 
  707.         /// <param name="cid"></param> 
  708.         /// <param name="place"></param> 
  709.         /// <returns></returns> 
  710.         private string GetBag()
  711.         {
  712.             string farmtime = GetFarmTime();
  713.             string url = "http://happyfarm.xiaoyou.qq.com/api.php?mod=repertory&act=getUserSeed";
  714.             string post = "farmKey=" + GetFarmKey(farmtime) + "&farmTime=" + farmtime;
  715.             string result =GetHtml(url, post, true, cookie);
  716.             return result;
  717.         }
  718.         #endregion
  719.         #region  购买种子
  720.         /// <summary>
  721.         /// 购买种子
  722.         /// </summary>
  723.         /// <param name="uid"></param>
  724.         /// <param name="cid"></param>
  725.         /// <param name="number"></param>
  726.         /// <returns></returns>
  727.         private string Seed(string uid, string cid, int number)
  728.         {
  729.             string farmtime = GetFarmTime();
  730.             string url = "http://happyfarm.xiaoyou.qq.com//api.php?mod=repertory&act=buySeed";
  731.             string post = "cId=" + cid + "&uIdx=" + uid + "&number=" + number.ToString() + "&farmKey=" + GetFarmKey(farmtime) + "&farmTime=" + farmtime;
  732.             string result = GetHtml(url, post, true, cookie);
  733.             return result;
  734.         } 
  735.         #endregion
  736.         #region 农场操作方法
  737.         /// <summary> 
  738.         /// 铲除
  739.         /// </summary> 
  740.         /// <param name="uid"></param> farmKey=da2c72dcbc442f97827c9f7eb8d89001&place=4&uIdx=361157088&cropStatus=7&farmTime=1260006806&ownerId=361157088
  741.         /// <param name="place"></param> 
  742.         /// <returns></returns> 
  743.         private string Scarify(string uid, string place)
  744.         {
  745.             string farmtime = GetFarmTime();
  746.             string url = runUrl + "/cgi-bin/cgi_farm_plant?mod=farmlandstatus&act=scarify";
  747.             string post = "uIdx="+uid+"&cropStatus=7&farmKey=" + GetFarmKey(farmtime) + "&place=" + HttpUtility.UrlEncode(place) + "&ownerId=" + _uid + "&farmTime=" + farmtime;
  748.             string result = GetHtml(url, post, true, cookie);
  749.             return result;
  750.         }
  751.          /// <summary> 
  752.         /// 摘取自己菜
  753.         /// </summary> 
  754.         /// <param name="uid"></param> farmKey=9b9f35a6fdc8f0a125051460ec44d29e&uIdx=361157088&farmTime=1259966227&place=6&ownerId=361157088
  755.         /// <param name="place"></param> 
  756.         /// <returns></returns> 
  757.         private string Harvest(string uid, string place)
  758.         {
  759.             string farmtime = GetFarmTime();
  760.             string url = runUrl + "/cgi-bin/cgi_farm_plant?mod=farmlandstatus&act=harvest";
  761.             string post = "farmKey=" + GetFarmKey(farmtime) + "&place=" + HttpUtility.UrlEncode(place) + "&ownerId=" + _uid + "&farmTime=" + farmtime;
  762.             string result = GetHtml(url, post, true, cookie);
  763.             return result;
  764.         }
  765.         /// <summary> 
  766.         /// 偷好友菜 
  767.         /// </summary> 
  768.         /// <param name="uid"></param> 
  769.         /// <param name="place"></param> 
  770.         /// <returns></returns> 
  771.         private string Steal(string uid, string place)
  772.         {
  773.             string farmtime = GetFarmTime();
  774.             string url = runUrl + "/cgi-bin/cgi_farm_steal?mod=farmlandstatus&act=scrounge";
  775.             string post = "farmKey=" + GetFarmKey(farmtime) + "&place=" + HttpUtility.UrlEncode(place) + "&ownerId=" + uid + "&farmTime=" + farmtime;
  776.             string result = GetHtml(url, post, true, cookie);
  777.             return result;
  778.         }
  779.         /// <summary> 
  780.         /// 除草 
  781.         /// </summary> 
  782.         /// <param name="qq"></param> 
  783.         /// <param name="place"></param> 
  784.         /// <returns></returns> /cgi-bin/cgi_farm_steal?mod=farmlandstatus&act=scrounge
  785.         private string ClearWeed(string uid, string place)
  786.         {
  787.             string farmtime = GetFarmTime();
  788.             string url = runUrl + "/cgi-bin/cgi_farm_opt?mod=farmlandstatus&act=clearWeed";
  789.             string post = "farmKey=" + GetFarmKey(farmtime) + "&place=" + HttpUtility.UrlEncode(place) + "&ownerId=" + uid + "&farmTime=" + farmtime;
  790.             string result = GetHtml(url, post, true, cookie);
  791.             return result;
  792.         }
  793.         /// <summary> 
  794.         /// 种植 
  795.         /// </summary> 
  796.         /// <param name="cid"></param> 
  797.         /// <param name="uid"></param> 
  798.         /// <param name="place"></param> 
  799.         /// <returns></returns> 
  800.         private string Plant(string cid, string uid, string place)
  801.         {
  802.             string farmtime = GetFarmTime();
  803.             string url = runUrl + "/cgi-bin/cgi_farm_plant?mod=farmlandstatus&act=planting";
  804.             string post = "cId=" + cid + "&farmKey=" + GetFarmKey(farmtime) + "&place=" +
  805.                  HttpUtility.UrlEncode(place) + "&ownerId=" + uid + "&farmTime=" + farmtime;
  806.             string result = GetHtml(url, post, true, cookie);
  807.             return result;
  808.         }
  809.         /// <summary> 
  810.         /// 浇水 
  811.         /// </summary> 
  812.         /// <param name="uid"></param> 
  813.         /// <param name="place"></param> 
  814.         /// <returns></returns> 
  815.         private string Water(string uid, string place)
  816.         {
  817.             string farmtime = GetFarmTime();
  818.             string url = runUrl + "/cgi-bin/cgi_farm_opt?mod=farmlandstatus&act=water";
  819.             string post = "farmKey=" + GetFarmKey(farmtime) + "&place=" + HttpUtility.UrlEncode(place) + "&ownerId=" + uid + "&farmTime=" + farmtime;
  820.             string result = GetHtml(url, post, true, cookie);
  821.             return result;
  822.             return "";
  823.         }
  824.         /// <summary> 
  825.         /// 杀虫 
  826.         /// </summary> 
  827.         /// <param name="qq"></param> 
  828.         /// <param name="place"></param> 
  829.         /// <returns></returns> 
  830.         private string Spraying(string uid, string place)
  831.         {
  832.             string farmtime = GetFarmTime();
  833.             string url = runUrl + "/cgi-bin/cgi_farm_opt?mod=farmlandstatus&act=spraying";
  834.             string post = "farmKey=" + GetFarmKey(farmtime) + "&place=" + HttpUtility.UrlEncode(place) + "&ownerId=" + uid + "&farmTime=" + farmtime;
  835.             string result = GetHtml(url, post, true, cookie);
  836.             return result;
  837.         }
  838.         #endregion
  839.         #region  获取可操作的用户
  840.         private void addStatus(JsonObject json, string url)
  841.         {
  842.             for (int i = 0; i < _status_filter.Count; i++)
  843.             {
  844.                 if (_status_filter.GetJson(i).GetJson(0).Key == json.Key)
  845.                     return;
  846.             }
  847.             json.Add("url", url);
  848.             _status_filter.Add(json);
  849.         }
  850.         
  851.         /// <summary>
  852.         /// 获取可操作的用户
  853.         /// </summary>
  854.         private void statusFilter()
  855.         {
  856.             BindUserInfo();
  857.             ChangeTSSL("正在获取获取可操作的用户列表...");
  858.             ChangeLBFM();
  859.             string farmtime = GetFarmTime();
  860.             string Url = "";
  861.             string urlNum = "";
  862.             string post = "";
  863.             string result = "";
  864.             JsonObject _model_1 = new JsonObject(""" + _uid + "":{"1":1}");
  865.             if (_model_1.ToString().Contains(_uid))
  866.             {
  867.                 addStatus(_model_1, "qzone");
  868.             }
  869.             Url = xiaoyouUrl;
  870.             urlNum = "/cgi-bin/cgi_farm_getstatus_filter?cmd=1";
  871.             post = "friend%5Fuids=" + HttpUtility.UrlEncode(_xiaoyoufriendsIds) + "&farmTime=" + farmtime + "&farmKey=" + GetFarmKey(farmtime) + "&uIdx=" + _uid;
  872.             result = GetHtml(Url + urlNum, post, true, cookie);
  873.             model = new JsonObject(result);
  874.             model = model.GetJson("status");
  875.             for (int i = 0; i < model.GetCollection().Count; i++)
  876.             {
  877.                 _model_1 = model.GetCollection()[i];
  878.                 addStatus(_model_1, "xiaoyou");
  879.             }
  880.             farmtime = GetFarmTime();
  881.             Url = qzoneUrl;
  882.             post = "friend%5Fuids=" + HttpUtility.UrlEncode(_qzonefriendsIds + "," + _uid) + "&farmTime=" + farmtime + "&farmKey=" + GetFarmKey(farmtime) + "&uIdx=" + _uid;
  883.             result = GetHtml(Url + urlNum, post, true, cookie);
  884.             model = new JsonObject(result);
  885.             model = model.GetJson("status");
  886.             for (int i = 0; i < model.GetCollection().Count; i++)
  887.             {
  888.                 _model_1 = model.GetCollection()[i];
  889.                 addStatus(_model_1, "qzone");
  890.             }
  891.             ChangeTSSL("获取获取可操作的用户列表完成");
  892.         }
  893.         #endregion
  894.         #region 验证
  895.         private string VerifyHtml(string html)
  896.         {
  897.             //{"code":0,"direction":"转换ID失败","poptype":3}
  898.             //{"direction":"系统错误","errorType":"timeOut","poptype":3}
  899.             if (html == "")
  900.                 return "";
  901.             JsonObject model = new JsonObject(html);
  902.             if (model.GetValue("errorType") != null)
  903.             {
  904.                 ChangeError(html);
  905.                 string errorType = model.GetValue("errorType");
  906.                 switch (errorType)
  907.                 {
  908.                     case "validateCode":
  909.                         ChangeInfo(Utils.ConvertUnicodeStringToChinese(model.GetValue("errorContent")) + ",时间:" + DateTime.Now.ToString());
  910.                         this.Invoke((MethodInvoker)delegate
  911.                         {
  912.                             //是否弹出验证码
  913.                             if (chbVerify.Checked)
  914.                             {
  915.                                 FrmFramVerify framverify = new FrmFramVerify(cookie, _uid);
  916.                                 framverify.ShowDialog(this);
  917.                             }
  918.                             else
  919.                             {
  920.                                 FrmRest();
  921.                             }
  922.                         });
  923.                         break;
  924.                         /*
  925.                     case "session":
  926.                         break;
  927.                         this.Invoke((MethodInvoker)delegate
  928.                         {
  929.                             Dispose();
  930.                             if (thread1 != null && thread1.IsAlive)
  931.                                 thread1.Abort();
  932.                             if (thread2 != null && thread2.IsAlive)
  933.                                 thread2.Abort();
  934.                             FrmFarmLogin login = new FrmFarmLogin();
  935.                             login.Show();
  936.                         });
  937.                         
  938.                         break;*/
  939.                     default:
  940.                         if (model.GetValue("errorContent") != null)
  941.                         {
  942.                             ChangeInfo("错误:"+Utils.ConvertUnicodeStringToChinese(model.GetValue("errorContent")));
  943.                         }
  944.                         ChangeInfo("错误类型:" + Utils.ConvertUnicodeStringToChinese(model.GetValue("errorType")));
  945.                         break;
  946.                 }
  947.                 return null;
  948.             }
  949.             string direction = model.GetValue("direction");
  950.             string poptype = model.GetValue("poptype");
  951.             if (poptype != null && poptype=="3"&&direction!=null)
  952.             {
  953.                 ChangeError(html);
  954.                 ChangeInfo("错误:" + direction);
  955.                 return null;
  956.             }
  957.             if (direction != null)
  958.             {
  959.                 ChangeMsg(model);
  960.             }
  961.             else
  962.             {
  963.                 for (int i = 0; i < model.GetCollection().Count; i++)
  964.                 {
  965.                     direction = model.GetCollection()[i].GetValue("direction");
  966.                     if (direction != null)
  967.                     {
  968.                         ChangeMsg(model.GetCollection()[i]);
  969.                     }
  970.                     else break;
  971.                 }
  972.             }
  973.             return html;
  974.         }
  975.         #endregion
  976.         #region 消息加载
  977.         /// <summary>
  978.         /// 消息加载
  979.         /// </summary>
  980.         /// <param name="model"></param>
  981.         private void ChangeMsg(JsonObject model)
  982.         {
  983.            
  984.             string direction = model.GetValue("direction");
  985.             if (direction != null)
  986.             {
  987.                 direction = Utils.NoHTML(Utils.ConvertUnicodeStringToChinese(direction));
  988.                 string exp = model.GetValue("exp");
  989.                 string money = model.GetValue("money");
  990.                 string harvest = model.GetValue("harvest");
  991.                 string cName = model.GetValue("cName");
  992.                 JsonObject _cIdmodel = model.GetJson("status");
  993.                 string cId = model.GetValue("cId");
  994.                 string num = model.GetValue("num");
  995.                 if (exp != null || direction != "")
  996.                 {
  997.                     ChangeLBFM(direction + (exp != null ? " 经验:" + exp : "") + (money != null ? " 金钱:" + money : "") + (harvest!=null?" 果实:"+harvest:""));
  998.                     //自动取消
  999.                     if (direction != "" && exp == "0" && money == "0")
  1000.                     {
  1001.                         this.Invoke((MethodInvoker)delegate
  1002.                         {
  1003.                             if (chbCancel.Checked)
  1004.                             {
  1005.                                 chbClearWeed.Checked = false;
  1006.                                 chbWater.Checked = false;
  1007.                                 chbSpraying.Checked = false;
  1008.                             }
  1009.                         });
  1010.                     }
  1011.                 }
  1012.                 if (cId != null&&cName!=null)
  1013.                 {
  1014.                     ChangeLBFM("购买 " + Utils.NoHTML(Utils.ConvertUnicodeStringToChinese(cName)) + " " + num + "个");
  1015.                 }
  1016.                 if (_cIdmodel!=null)
  1017.                 {
  1018.                     
  1019.                     if (_cIdmodel != null)
  1020.                     {
  1021.                         cId = _cIdmodel.GetValue("cId");
  1022.                         string nNum = null;
  1023.                         if (cId != null)
  1024.                         {
  1025.                             JsonObject _cnamemodel = GetShopModel(cId);
  1026.                             if (_cnamemodel == null) cName = "品种未知";
  1027.                             else cName = _cnamemodel.GetValue("cName");
  1028.                             if (_cIdmodel.GetJson("thief") != null && _cIdmodel.GetJson("thief").ToString().Contains(_uid))
  1029.                             {
  1030.                                 nNum = _cIdmodel.GetJson("thief").GetValue(_uid);
  1031.                             }
  1032.                             newsbog.AddFruit(cId, cName, (harvest != null ? harvest : nNum).ToString());
  1033.                             ChangeLBFM("采得 " + Utils.NoHTML(Utils.ConvertUnicodeStringToChinese(cName)) + "  " + (harvest != null ? harvest : nNum) + "个");
  1034.                         }
  1035.                     }
  1036.                 }
  1037.             }
  1038.         }
  1039.         #endregion
  1040.         #region 获取HTML
  1041.         private Stream GetStream(string url, System.Net.CookieContainer cookieContainer)
  1042.         {
  1043.             Stream html = HttpHelper.GetStream(url, cookieContainer);
  1044.             if (html == null)
  1045.             {
  1046.                 html = GetStream(url, cookieContainer);
  1047.             }
  1048.             return html;
  1049.         }
  1050.         /// <summary>
  1051.         /// 获取HTML
  1052.         /// </summary>
  1053.         /// <param name="url">地址</param>
  1054.         /// <param name="postData">post 提交的字符串</param>
  1055.         /// <param name="isPost">是否是post</param>
  1056.         /// <param name="cookieContainer">CookieContainer</param>
  1057.         /// <returns>html </returns>
  1058.         private string GetHtml(string url, string postData, bool isPost, System.Net.CookieContainer cookieContainer)
  1059.         {
  1060.             string html = VerifyHtml(HttpHelper.GetHtml(url, postData, true, cookieContainer));
  1061.             if (html == null)
  1062.             {
  1063.                 html = GetHtml(url, postData, isPost, cookieContainer);
  1064.             }
  1065.             if (html == "")
  1066.             {
  1067.                 ChangeInfo(url + postData);
  1068.                 html = GetHtml(url, postData, isPost, cookieContainer);
  1069.             }
  1070.             return html;
  1071.         }
  1072.         /// <summary>
  1073.         /// 获取HTML
  1074.         /// </summary>
  1075.         /// <param name="url">地址</param>
  1076.         /// <param name="cookieContainer">CookieContainer</param>
  1077.         /// <returns>HTML</returns>
  1078.         private string GetHtml(string url, System.Net.CookieContainer cookieContainer)
  1079.         {
  1080.             string html = VerifyHtml(HttpHelper.GetHtml(url, cookieContainer));
  1081.             if (html == null)
  1082.             {
  1083.                 html = GetHtml(url, cookieContainer);
  1084.             }
  1085.             if (html == "")
  1086.             {
  1087.                 ChangeInfo(url);
  1088.                 html = GetHtml(url, cookieContainer);
  1089.             }
  1090.             return html;
  1091.         }
  1092.         #endregion
  1093.         #region 获取用户农场信息
  1094.         /// <summary>
  1095.         /// 获取用户农场信息
  1096.         /// </summary>
  1097.         private void TGetUsrInfo()
  1098.         {
  1099.             picHead.Image = null;
  1100.             lblUserName.Text = "";
  1101.             notifyIcon1.Text = "";
  1102.             lblMoney.Text = "";
  1103.             lblExp.Text = "";
  1104.             lblLevel.Text = "";
  1105.             Thread thread3 = new Thread(new ThreadStart(GetUsrInfo));
  1106.             thread3.IsBackground = true;
  1107.             thread3.Start();
  1108.         }
  1109.         private void GetUsrInfo()
  1110.         {
  1111.             string farmtime = GetFarmTime();
  1112.             string url = "http://nc.xiaoyou.qq.com/cgi-bin/cgi_farm_index?mod=user&act=run";
  1113.             string post = "farmKey=" + GetFarmKey(farmtime) + "&farmTime=" + farmtime;
  1114.             string result = GetHtml(url, post, true, cookie);
  1115.             _status = new JsonObject(result);
  1116.             _uid = _status.GetJson("user").GetValue("uId");
  1117.             model = _status;
  1118.             string headPic = model.GetJson("user").GetValue("headPic").Replace("\", "");
  1119.             if (headPic != null)
  1120.             {
  1121.                 Stream stream = GetStream(headPic, cookie);
  1122.                 picHead.Image = Image.FromStream(stream);
  1123.             }
  1124.             this.Invoke((MethodInvoker)delegate
  1125.             {
  1126.                 if (model.GetJson("user").GetValue("userName") != null)
  1127.                 {
  1128.                     string userName = Utils.ConvertUnicodeStringToChinese(model.GetJson("user").GetValue("userName"));
  1129.                     lblUserName.Text = userName;
  1130.                     this.Text = userName + "   --QQ农夫";
  1131.                     notifyIcon1.Text = "(" + (userName) + ")" + notifyIcon1.Text;
  1132.                 }
  1133.                     lblMoney.Text = model.GetJson("user").GetValue("money");
  1134.                 int lv = 0;
  1135.                 lblExp.Text = FormatExp(Convert.ToInt32(model.GetJson("user").GetValue("exp")), out lv);
  1136.                 lblLevel.Text = lv.ToString();
  1137.             });
  1138.         }
  1139.         #endregion
  1140.         #region 获取商店列表
  1141.         /// <summary> 
  1142.         /// 获取商店列表 
  1143.         /// </summary> 
  1144.         /// <returns></returns> 
  1145.         private string ScanShop()
  1146.         {
  1147.             string farmtime = GetFarmTime();
  1148.             string url = "http://happyfarm.xiaoyou.qq.com/api.php?mod=repertory&act=getSeedInfo";
  1149.             string post = "farmKey=" + GetFarmKey(farmtime) + "&farmTime=" + farmtime;
  1150.             string result = GetHtml(url, post, true, cookie);
  1151.             return result;
  1152.         }
  1153.         #endregion
  1154.         #region 获得制定商品信息
  1155.         /// <summary> 
  1156.         /// 获得制定商品信息 
  1157.         /// </summary> 
  1158.         /// <param name="cid"></param> 
  1159.         /// <returns></returns> 
  1160.         private JsonObject GetShopModel(string cid)
  1161.         {
  1162.             for (int x = 0; x < _shop.GetCollection().Count; x++)
  1163.             {
  1164.                 if (_shop.GetCollection()[x].GetValue("cId").Equals(cid))//不是空地 
  1165.                 {
  1166.                     return _shop.GetCollection()[x];
  1167.                 }
  1168.             }
  1169.             return null;
  1170.         }
  1171.         #endregion
  1172.         #region 获取商店中符合自己等级的cid
  1173.         /// <summary>
  1174.         /// 获取商店中符合自己等级的cid
  1175.         /// </summary>
  1176.         /// <returns></returns>
  1177.         private string GetShopLv()
  1178.         {
  1179.             int cLevel = 0;
  1180.             string cid = "";
  1181.             FormatExp(Convert.ToInt32(_status.GetJson("user").GetValue("exp")), out cLevel);
  1182.             for (int x = 0; x < _shop.GetCollection().Count; x++)
  1183.             {
  1184.                 string shopcLevel = _shop.GetCollection()[x].GetValue("cLevel");
  1185.                 if (Convert.ToInt32(shopcLevel)>cLevel)//判断等级
  1186.                 {
  1187.                     break;
  1188.                 }
  1189.                 cid = _shop.GetCollection()[x].GetValue("cId");
  1190.             }
  1191.             return cid;
  1192.         } 
  1193.         #endregion
  1194.         #region 获取所有好友
  1195.         /// <summary>
  1196.         /// 获取所有好友 
  1197.         /// </summary>
  1198.         private void ListFriends()
  1199.         {
  1200.             string url = "http://happyfarm.xiaoyou.qq.com/api.php?mod=friend";
  1201.             string result = GetHtml(url, cookie);
  1202.             this._xiaoyoufriends = new JsonObject(result);
  1203.             for (int i = 0; i < _xiaoyoufriends.GetCollection().Count; i++)
  1204.             {
  1205.                 if (_xiaoyoufriendsIds != "") _xiaoyoufriendsIds += ",";
  1206.                 _xiaoyoufriendsIds += _xiaoyoufriends.GetCollection()[i].GetValue("userId");
  1207.             }
  1208.             url = "http://happyfarm.qzone.qq.com/api.php?mod=friend";
  1209.             result = GetHtml(url, cookie);
  1210.             this._qzonefriends = new JsonObject(result);
  1211.             for (int i = 0; i < _qzonefriends.GetCollection().Count; i++)
  1212.             {
  1213.                 if (_qzonefriendsIds != "") _qzonefriendsIds += ",";
  1214.                 _qzonefriendsIds += _qzonefriends.GetCollection()[i].GetValue("userId");
  1215.             }
  1216.         }
  1217.         #endregion
  1218.         #region 获取某好友信息
  1219.         /// <summary> 
  1220.         /// 获取某好友信息 
  1221.         /// </summary> 
  1222.         /// <param name="uid"></param> 
  1223.         /// <returns></returns> 
  1224.         private string ShowFriend(string uid, string url)
  1225.         {
  1226.             string farmtime = GetFarmTime();
  1227.             string urlnum = url + "/cgi-bin/cgi_farm_index?mod=user&act=run&ownerId=" + uid;
  1228.             string post = "farmKey=" + GetFarmKey(farmtime) + "&farmTime=" + farmtime;
  1229.             string result = GetHtml(urlnum, post, true, cookie);
  1230.             return result;
  1231.         }
  1232.         #endregion
  1233.         #region 修改好友信息
  1234.         /// <summary> 
  1235.         /// 修改好友信息 
  1236.         /// </summary> 
  1237.         /// <param name="msg"></param> 
  1238.         private void ChangeLBFM(string msg)
  1239.         {
  1240.             this.Invoke((MethodInvoker)delegate
  1241.             {
  1242.                 lbFriendsMessage.Items.Add(msg);
  1243.             });
  1244.         }
  1245.         #endregion
  1246.         #region 清空好友信息
  1247.         /// <summary> 
  1248.         /// 清空好友信息 
  1249.         /// </summary> 
  1250.         /// <param name="msg"></param> 
  1251.         private void ChangeLBFM()
  1252.         {
  1253.             this.Invoke((MethodInvoker)delegate
  1254.             {
  1255.                 lbFriendsMessage.Items.Clear();
  1256.             });
  1257.         }
  1258.         #endregion
  1259.         #region 修改状态栏信息
  1260.         /// <summary> 
  1261.         /// 修改状态栏信息 
  1262.         /// </summary> 
  1263.         /// <param name="msg"></param> 
  1264.         private void ChangeTSSL(string msg)
  1265.         {
  1266.             this.Invoke((MethodInvoker)delegate
  1267.             {
  1268.                 tsslMsg.Text = msg;
  1269.             });
  1270.         }
  1271.         #endregion
  1272.         #region 修改状态栏信息
  1273.         /// <summary> 
  1274.         /// 修改状态栏信息 
  1275.         /// </summary> 
  1276.         /// <param name="msg"></param> 
  1277.         private void ChangeError(string msg)
  1278.         {
  1279.             this.Invoke((MethodInvoker)delegate
  1280.             {
  1281.                 txtError.Text += msg + "rn";
  1282.               //   .Text = msg;
  1283.             });
  1284.         }
  1285.         #endregion
  1286.         #region 改变用户消息
  1287.         /// <summary> 
  1288.         /// 改变用户消息 
  1289.         /// </summary> 
  1290.         /// <param name="msg"></param> 
  1291.         private void ChangeInfo(string msg)
  1292.         {
  1293.             this.Invoke((MethodInvoker)delegate
  1294.             {
  1295.                 lbInfo.Items.Add(msg);
  1296.             });
  1297.         }
  1298.         #endregion
  1299.         #region 获得FarmTime
  1300.         /// <summary> 
  1301.         /// 获得FarmTime 
  1302.         /// </summary> 
  1303.         /// <returns></returns> 
  1304.         private string GetFarmTime()
  1305.         {
  1306.             return FarmKey.GetFarmTime();
  1307.         }
  1308.         #endregion
  1309.         #region 获得FarmKey
  1310.         /// <summary> 
  1311.         /// 获得FarmKey 
  1312.         /// </summary> 
  1313.         /// <param name="farmTime"></param> 
  1314.         /// <returns></returns> 
  1315.         private string GetFarmKey(string farmTime)
  1316.         {
  1317.             return FarmKey.GetFarmKey(farmTime);
  1318.         }
  1319.         #endregion
  1320.         #region 按钮事件
  1321.         private void lbtnUpdata_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
  1322.         {
  1323.             TGetUsrInfo();
  1324.         }
  1325.         private void upTime_KeyPress(object sender, KeyPressEventArgs e)
  1326.         {
  1327.             TextBox keyTxt = (TextBox)sender;
  1328.             //阻止从键盘输入键 
  1329.             e.Handled = true;
  1330.             KeyPressEventArgs _e = new KeyPressEventArgs('b');
  1331.             if (e.KeyChar == _e.KeyChar)
  1332.             {
  1333.                 e.Handled = false;
  1334.                 if (keyTxt.Text.Length <= 1)
  1335.                 {
  1336.                     keyTxt.Text = "0";
  1337.                     e.Handled = true;
  1338.                 }
  1339.             }
  1340.             //_e = new KeyPressEventArgs('.');
  1341.             //if (e.KeyChar == _e.KeyChar)
  1342.             //{
  1343.             //    if (keyTxt.Text.Split('.') < 1)
  1344.             //    {
  1345.             //        e.Handled = false;
  1346.             //    }
  1347.             //    return;
  1348.             //}
  1349.             if (e.KeyChar >= '0' && e.KeyChar <= '9')
  1350.             {
  1351.                 if (keyTxt.Text == "0")
  1352.                 {
  1353.                     keyTxt.Text = "";
  1354.                 }
  1355.                 e.Handled = false;
  1356.             }
  1357.         }
  1358.         #region 任务栏显示
  1359.         private void tsmResize_Click(object sender, EventArgs e)
  1360.         {
  1361.             hideFrom();
  1362.         }
  1363.         private void tmiClose_Click(object sender, EventArgs e)
  1364.         {
  1365.             Dispose();
  1366.             System.Environment.Exit(System.Environment.ExitCode);
  1367.         }
  1368.         private void closeMenu_Click(object sender, EventArgs e)
  1369.         {
  1370.             Dispose();
  1371.             System.Environment.Exit(System.Environment.ExitCode);
  1372.         }
  1373.         private void FrmFarmMain_Resize(object sender, EventArgs e)
  1374.         {
  1375.             if (base.WindowState == FormWindowState.Minimized)
  1376.             {
  1377.                 hideFrom();
  1378.             }
  1379.         }
  1380.         /// <summary>
  1381.         /// 最小化窗口到任务栏
  1382.         /// </summary>
  1383.         private void hideFrom()
  1384.         {
  1385.             this.notifyIcon1.Visible = true;
  1386.             base.ShowInTaskbar = false;
  1387.             base.Hide();
  1388.         }
  1389.         public void showFrom()
  1390.         {
  1391.             base.ShowInTaskbar = true;
  1392.             this.notifyIcon1.Visible = false;
  1393.             this.Activate();
  1394.             this.Show();
  1395.             base.WindowState = FormWindowState.Normal;
  1396.         }
  1397.         private void showMenu_Click(object sender, EventArgs e)
  1398.         {
  1399.             showFrom();
  1400.         }
  1401.         private void notifyIcon1_MouseDoubleClick(object sender, MouseEventArgs e)
  1402.         {
  1403.             showFrom();
  1404.         }
  1405.         #endregion
  1406.         private void button1_Click(object sender, EventArgs e)
  1407.         {
  1408.             if (button1.Text == "暂停")
  1409.             {
  1410.                 ChangeTSSL("已暂停");
  1411.                 button1.Text = "开始";
  1412.                 FrmRest();
  1413.                 timer3.Enabled = false;
  1414.             }
  1415.             else
  1416.             {
  1417.                 ChangeTSSL("工作中...");
  1418.                 button1.Text = "暂停";
  1419.                 FrmWook();
  1420.                 timer3.Enabled = true;
  1421.             }
  1422.         }
  1423.         private void button2_Click(object sender, EventArgs e)
  1424.         {
  1425.             lbInfo.Items.Clear();
  1426.         }
  1427.         #endregion
  1428.         #region 工作 ---休息
  1429.         /// <summary>
  1430.         /// 工作开始
  1431.         /// </summary>
  1432.         public void FrmWook()
  1433.         {
  1434.             this.Invoke((MethodInvoker)delegate
  1435.             {
  1436.                 if (tsslMsg.Text == "")
  1437.                 {
  1438.                     ChangeTSSL("工作中...");
  1439.                 }
  1440.                 timer1.Enabled = true;
  1441.                 timer2.Enabled = true;
  1442.                 _autoWookBool = true;
  1443.                 _aotuWookTime = 0;
  1444.             });
  1445.         }
  1446.         /// <summary>
  1447.         /// 休息开始
  1448.         /// </summary>
  1449.         public void FrmRest()
  1450.         {
  1451.             this.Invoke((MethodInvoker)delegate
  1452.             {
  1453.                 timer1.Enabled = false;
  1454.                 timer2.Enabled = false;
  1455.                 _autoWookBool = false;
  1456.                 _aotuWookTime = 0;
  1457.                 if (thread1 != null && thread1.IsAlive)
  1458.                     thread1.Abort();
  1459.                 if (thread2 != null && thread2.IsAlive)
  1460.                     thread2.Abort();
  1461.             });
  1462.         } 
  1463.         #endregion
  1464.         #region 工作监视器
  1465.         private void timer3_Tick(object sender, EventArgs e)
  1466.         {
  1467.             if (chbUpdata.Checked)
  1468.             {
  1469.                 if (_userInfoTime >= _userInfoUpTime)
  1470.                 {
  1471.                     _userInfoTime = 0;
  1472.                     TGetUsrInfo();
  1473.                 }
  1474.                 _userInfoTime++;
  1475.             }
  1476.             if (_autoWookBool)
  1477.             {
  1478.                 
  1479.                 if (_aotuWookTime >= Convert.ToInt32(txtWorkTime.Text.Trim()))
  1480.                 {
  1481.                     //休息开始
  1482.                     FrmRest();
  1483.                     return;
  1484.                 }
  1485.             }
  1486.             else
  1487.             {
  1488.                 if (_aotuWookTime >= Convert.ToInt32(txtRestTime.Text.Trim()))
  1489.                 {
  1490.                     ChangeTSSL("");
  1491.                     //工作开始
  1492.                     FrmWook();
  1493.                     return;
  1494.                 }
  1495.                 ChangeTSSL("距离下次工作,还有" + (Convert.ToInt32(txtRestTime.Text.Trim()) - _aotuWookTime) + "秒...");
  1496.             }
  1497.             _aotuWookTime++;
  1498.         } 
  1499.         #endregion
  1500.         private void tmiError_Click(object sender, EventArgs e)
  1501.         {
  1502.             PanelError();
  1503.         }
  1504.         /// <summary>
  1505.         /// 显示隐藏错误
  1506.         /// </summary>
  1507.         private void PanelError()
  1508.         {
  1509.             if (panel2.Visible)
  1510.             {
  1511.                 panel2.Visible = false;
  1512.                 this.Size = new System.Drawing.Size(this.Size.Width - panel2.Size.Width, this.Size.Height);
  1513.             }
  1514.             else
  1515.             {
  1516.                 panel2.Visible = true;
  1517.                 this.Size = new System.Drawing.Size(this.Size.Width + panel2.Size.Width, this.Size.Height);
  1518.             }
  1519.         }
  1520.         #region 摘取显示
  1521.         private void tsmiNewsBog_Click(object sender, EventArgs e)
  1522.         {
  1523.             FrmBog frmbog = new FrmBog(newsbog);
  1524.             frmbog.ShowDialog();
  1525.         }
  1526.         #endregion
  1527.     }
  1528. }