SanhuaMES.cs 3.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. using CCWin;
  2. using Newtonsoft.Json;
  3. using Newtonsoft.Json.Linq;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.ComponentModel;
  7. using System.Data;
  8. using System.Drawing;
  9. using System.IO;
  10. using System.Linq;
  11. using System.Text;
  12. using System.Threading.Tasks;
  13. using System.Windows.Forms;
  14. namespace MOKA_Factory_Tools
  15. {
  16. public partial class SanhuaMES : Skin_Color
  17. {
  18. public SanhuaMES()
  19. {
  20. InitializeComponent();
  21. }
  22. private void SanhuaMES_Load(object sender, EventArgs e)
  23. {
  24. Text_MES_URL.Text = SanhuaMethod.sanhuaLoginInfo.url;
  25. Text_StaffCode.Text = SanhuaMethod.sanhuaLoginInfo.staffCode;
  26. Text_ResuorceCode.Text = SanhuaMethod.sanhuaLoginInfo.resourceCode;
  27. Text_MES_Password.Text = SanhuaMethod.sanhuaLoginInfo.password;
  28. Text_JigEdtion.Text = SanhuaMethod.sanhuaLoginInfo.jigEdtion;
  29. }
  30. private void Btn_MES_Login_Click(object sender, EventArgs e)
  31. {
  32. SanhuaMethod.sanhuaLoginInfo.url = Text_MES_URL.Text;
  33. SanhuaMethod.sanhuaLoginInfo.staffCode = Text_StaffCode.Text;
  34. SanhuaMethod.sanhuaLoginInfo.resourceCode = Text_ResuorceCode.Text;
  35. SanhuaMethod.sanhuaLoginInfo.password = Text_MES_Password.Text;
  36. SanhuaMethod.sanhuaLoginInfo.jigEdtion = Text_JigEdtion.Text;
  37. if ( SanhuaMethod.sanhuaLoginInfo.url.EndsWith("/") )
  38. {
  39. SanhuaMethod.sanhuaLoginInfo.url = SanhuaMethod.sanhuaLoginInfo.url.Replace("/", "");
  40. }
  41. SaveLoginInfo();
  42. if ( SanhuaMethod.CheckLogin(SanhuaMethod.sanhuaLoginInfo.url) )
  43. {
  44. DialogResult = DialogResult.OK;
  45. }
  46. else
  47. {
  48. MessageBox.Show("登录失败,原因请查看日志");
  49. DialogResult = DialogResult.Cancel;
  50. }
  51. }
  52. private void SaveLoginInfo()
  53. {
  54. JObject jObject;
  55. using (StreamReader file = File.OpenText(LocalPath.localpath + "\\Config.json"))
  56. {
  57. using (JsonTextReader reader = new JsonTextReader(file))
  58. {
  59. jObject = (JObject)JToken.ReadFrom(reader);
  60. reader.Close();
  61. if (jObject["SanhuaLoginInfo"] == null)
  62. {
  63. JObject item = new JObject();
  64. item.Add("url", SanhuaMethod.sanhuaLoginInfo.url);
  65. item.Add("staffCode", SanhuaMethod.sanhuaLoginInfo.staffCode);
  66. item.Add("resourceCode", SanhuaMethod.sanhuaLoginInfo.resourceCode);
  67. item.Add("password", SanhuaMethod.sanhuaLoginInfo.password);
  68. item.Add("jigEdtion", SanhuaMethod.sanhuaLoginInfo.jigEdtion);
  69. jObject.Add("SanhuaLoginInfo", item);
  70. }
  71. else
  72. {
  73. jObject["SanhuaLoginInfo"]["url"] = SanhuaMethod.sanhuaLoginInfo.url;
  74. jObject["SanhuaLoginInfo"]["staffCode"] = SanhuaMethod.sanhuaLoginInfo.staffCode;
  75. jObject["SanhuaLoginInfo"]["resourceCode"] = SanhuaMethod.sanhuaLoginInfo.resourceCode;
  76. jObject["SanhuaLoginInfo"]["password"] = SanhuaMethod.sanhuaLoginInfo.password;
  77. jObject["SanhuaLoginInfo"]["jigEdtion"] = SanhuaMethod.sanhuaLoginInfo.jigEdtion;
  78. }
  79. }
  80. }
  81. using (StreamWriter writer = new StreamWriter(LocalPath.localpath + "\\Config.json"))
  82. {
  83. writer.Write(jObject.ToString());
  84. }
  85. }
  86. }
  87. }