private void button1_Click(object sender, EventArgs e) { if (string.IsNullOrWhiteSpace(txtLoginName.Text)) { MessageBox.Show("请输入登录账号!"); txtLoginName.Focus(); return; } if (string.IsNullOrWhiteSpace(txtPassword.Text)) { MessageBox.Show("请输入密码!"); txtPassword.Focus(); return; } string XmlFile = string.Format(@"{0}\{1}.xml", Directory.GetCurrentDirectory(), ConfigurationManager.AppSettings["WCF_xmlFile"]); if (!File.Exists(XmlFile)) { MessageBox.Show("请先设置访问的IP!"); WcfAddressSettings seetings = new WcfAddressSettings(); seetings.StartPosition = FormStartPosition.CenterScreen; seetings.Show(); this.Visible = false;; return; } string result = ""; try { ServiceReference1.InstrumentWCFServices wcf = InvokeContext.CreateWCFService <ServiceReference1.InstrumentWCFServices>(); result = wcf.AppLogin(txtLoginName.Text, txtPassword.Text, ""); } catch { MessageBox.Show("连接服务失败,请检查IP及端口设置是否正确"); return; } using (MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(result))) { DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(LoginResult)); LoginResult model = (LoginResult)serializer.ReadObject(ms); if (model.Msg != "OK") { MessageBox.Show(model.Msg); txtPassword.Text = ""; return; } LoginInfo.CurrentUser.JobNo = txtLoginName.Text; LoginInfo.CurrentUser.AccessToKen = model.Data.AccessToKen; MainForm mainform = new MainForm(); mainform.StartPosition = FormStartPosition.CenterScreen; mainform.Show(); this.Visible = false;; } }
private IList <InstrumentModel> BindData(int InstrumentForm) { string result = ""; try { ServiceReference1.InstrumentWCFServices wcf = InvokeContext.CreateWCFService <ServiceReference1.InstrumentWCFServices>(); result = wcf.GetAllInstrument(InstrumentForm, LoginInfo.CurrentUser.JobNo.ToString(), LoginInfo.CurrentUser.AccessToKen); } catch { MessageBox.Show("连接服务失败,请检查IP及端口设置是否正确!"); return(null); } using (MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(result))) { DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(RsultModel)); RsultModel model = (RsultModel)serializer.ReadObject(ms); if (model.Msg != "OK") { MessageBox.Show(model.Msg); return(null); } return(model.Data); } }