void client_addTestCompleted(object sender, WCF.addTestCompletedEventArgs e) { if (e.Error == null) { WCF.TestClass test = e.Result; if (test.ID > 0) { txtMsg.Text = "上传成功 ID = " + test.ID.ToString(); } } else { MessageBox.Show(e.Error.Message); } }
private void btUpdateTest_Click(object sender, RoutedEventArgs e) { JudgmentClass judgment = new JudgmentClass(); if (judgment.Judgment("确定提交更新吗?") != true) { return; } if (uGrid.SelectedIndex >= 0) { int index = uGrid.SelectedIndex; WCF.TestClass test = new WCF.TestClass { ID = (int)dv[index]["ID"], tTitle = dv[index]["tTitle"].ToString(), tAnswer = dv[index]["tAnswer"].ToString(), tText = dv[index]["tText"].ToString() }; String uName = Get_Info.User; String uPass = Get_Info.Pass; if (uName != "" && uPass != "") { try { uPass = encryptString(uPass); using (OperationContextScope scope = new OperationContextScope(client.InnerChannel)) { MessageHeader user = MessageHeader.CreateHeader("uName", "MySpace", uName); MessageHeader pass = MessageHeader.CreateHeader("uPass", "MySpace", uPass); OperationContext.Current.OutgoingMessageHeaders.Add(user); OperationContext.Current.OutgoingMessageHeaders.Add(pass); client.updateTestAsync(test, test.ID); } } catch (Exception exp) { showMsg(exp.Message); } } } }
private void btUpLoad_Click(object sender, RoutedEventArgs e) { JudgmentClass judgment = new JudgmentClass(); if (judgment.Judgment("确定上传新试题吗") != true) { return; } String uName = Get_Info.User; String uPass = Get_Info.Pass; String tTitle = txtTitle.Text.Trim(); String text = txtText.Text.Trim(); if (uName != "" && uPass != "" && tTitle != "" && text != "") { try { uPass = encryptString(uPass); using (OperationContextScope scope = new OperationContextScope(client.InnerChannel)) { MessageHeader user = MessageHeader.CreateHeader("uName", "MySpace", uName); MessageHeader pass = MessageHeader.CreateHeader("uPass", "MySpace", uPass); OperationContext.Current.OutgoingMessageHeaders.Add(user); OperationContext.Current.OutgoingMessageHeaders.Add(pass); WCF.TestClass test = new WCF.TestClass { ID = 0, tAnswer = cbAnswer.SelectedItem.ToString(), tTitle = tTitle, tText = text }; client.addTestAsync(test); } } catch (Exception exp) { showMsg(exp.Message); } } }