private void btnAddCode_Click(object sender, EventArgs e) { if (txtQunarCode.Text.Length <= 0) { MessageBox.Show("要添加的三字码不能为空!"); return; } if (!Regex.IsMatch(txtQunarCode.Text, @"^[a-zA-Z]{3}$")) { MessageBox.Show("输入的三字码必须是三个字母"); return; } this.lbQunarCodes.Items.Add(txtQunarCode.Text.ToUpper()); lstQunarCodes.Add(txtQunarCode.Text.ToUpper()); QunarCodeList codeList = new QunarCodeList() { Code = lstQunarCodes }; Task.Factory.StartNew(() => { CoreHelper.DoPost(System.Configuration.ConfigurationManager.AppSettings["AddQunarCodeUrl"].ToString(), new QunarCodeRequest() { Code = txtQunarCode.Text.ToUpper() }); }); //string content = XmlHelper.Serializer(typeof(QunarCodeList), codeList); //string path = System.IO.Directory.GetCurrentDirectory(); //File.WriteAllText(path + "\\QunarCode.xml", content); MessageBox.Show("添加成功!"); }
private void lbQunarCodes_MouseDoubleClick(object sender, MouseEventArgs e) { lstQunarCodes.Remove(this.lbQunarCodes.SelectedItem.ToString()); QunarCodeList codeList = new QunarCodeList() { Code = lstQunarCodes }; Task.Factory.StartNew(() => { CoreHelper.DoPost(System.Configuration.ConfigurationManager.AppSettings["DeleteQunarCodeUrl"].ToString(), new QunarCodeRequest() { Code = this.lbQunarCodes.SelectedItem.ToString().ToUpper() }); }); //string content= XmlHelper.Serializer(typeof(QunarCodeList), codeList); // string path = System.IO.Directory.GetCurrentDirectory(); // File.WriteAllText(path + "\\QunarCode.xml", content); this.lbQunarCodes.Items.Remove(this.lbQunarCodes.SelectedItem); }