/// <summary> /// 执行登录函数 /// </summary> private void load() { string type = "2"; //打印店的type为2 List<string> myRem = new List<string>(); //此处可以进行修改和简化 string strusername = printerAcount.Text; //用户名 string strpassword = password.Text; //密码 if (myLogin.Count == 2) { if (myLogin[0].Length != strpassword.Length) { byte[] pword = Encoding.Default.GetBytes(strpassword.Trim()); //进行MD5的加密工作 System.Security.Cryptography.MD5 md5 = new MD5CryptoServiceProvider(); byte[] out1 = md5.ComputeHash(pword); strpassword = BitConverter.ToString(out1).Replace("-", ""); } } else { byte[] pword = Encoding.Default.GetBytes(strpassword.Trim()); //进行MD5的加密工作 System.Security.Cryptography.MD5 md5 = new MD5CryptoServiceProvider(); byte[] out1 = md5.ComputeHash(pword); strpassword = BitConverter.ToString(out1).Replace("-", ""); } if (strusername.Length == 0 || strpassword.Length == 0) { if (error.InvokeRequired) { my1 = new boxDelegate(boxChange); error.Invoke(my1, new object[] {error,"请输入您的个人信息",true,true }); loginbutton.Invoke(my1, new object[] { loginbutton, "登录", true, true }); Thread.Sleep(100); } else //这里并没有看出有什么区别 { error.Text = "请输入您的个人信息"; error.Visible = true; loginbutton.Enabled = true; } } else { //获取token strpassword = strpassword.ToLower(); string js = "type=" + type + "&account=" + strusername + "&pwd=" + strpassword; //POST得到要数据//登陆得到token string r = API.PostMethod("/Token", js, new UTF8Encoding()); //从post得到的数据中得到token Console.WriteLine(r); JObject toke = JObject.Parse(r); ToMyToken my = new ToMyToken(); bool loginOk = r.Contains("token"); if (loginOk == true) { my.token = (string)toke["token"];//也能够得到token my.name = (string)toke["name"]; my.id = (string)toke["id"]; my.version = (float)toke["version"]; //判断是否保存用户名 if (checkbox.Checked) { myRem.Add(strpassword); //myRem.Add(password.Text); myRem.Add(printerAcount.Text); } File.WriteAllText(@"pwd.sjc", ""); remember.WriteListToTextFile(myRem, @"pwd.sjc"); Console.WriteLine(my.token); Console.WriteLine(my.name); Console.WriteLine(my.id); showdownload(my); //传递参数,显示下载控件 autorefresh.Enabled = true; //登录成功后启动计时器 } else { //登录失败 my1 = new boxDelegate(boxChange); if (error.InvokeRequired) { my1 = new boxDelegate(boxChange); error.Invoke(my1, new object[] { error, "登陆失败,请重新登录!", true, true }); loginbutton.Invoke(my1, new object[] { loginbutton, "登录", true, true }); Thread.Sleep(100); } else { error.Text = "登陆失败,请重新登录!"; error.Visible = true; loginbutton.Enabled = true; } } } }
//----------------------------------------------------------------- //panel切换函数 //----------------------------------------------------------------- //private delegate void hidedelegate(); //private void hide(hidedelegate myDelegate) //{ // if (this.InvokeRequired) // { // this.Invoke(myDelegate); // } // else // { // myDelegate(); // } //} private void showdownload(ToMyToken my) { login.Hide(); this.Size = new Size(1300, 400); this.Location = new Point(50, 200); this.FormBorderStyle = FormBorderStyle.Sizable; set_default_printer.Hide(); download.Show(); downloadToken = my.token; printerName = my.name; printerId = my.id; version = my.version; String Date = (DateTime.Now.ToLongDateString()); path = @"D:\云印南开\" + Date; //path = string.Empty; if (!File.Exists("json.sjc")) { File.Create("json.sjc"); } myRefresh(); //获取文件列表 refreshDataGrid(); //初次进入下载界面显示数据 downloadfirst(); }