private bool yanzhengGroupText() { int n = (this.GroupInfo.SelectedIndex + 1) * 3; bool b = false; for (int i = 0; i < n; i++) { string str = this.GroupTextlist[i].Text; if (!Utils.IsEmptyOrNull(str) && !Regex.IsMatch(str, "^\\d{15}$")) { MessageBox.Show(str + " 数据应为15位数字"); return(false); } if (!Utils.IsEmptyOrNull(str) && Regex.IsMatch(str, "^\\d{15}$")) { b = true; } } if (!b) { MessageBox.Show("未检测到芯片信息,请扫描芯片录入信息!"); return(false); } /*监测文本框信息连续*/ // List<long> valueList = new List<long>(); string message = ""; long target = 1; List <TextBox> list = this.GroupTextlist.Where(p => !string.IsNullOrEmpty(p.Text)).ToList(); var GROUP = this.GroupTextlist.Where(p => !string.IsNullOrEmpty(p.Text)).GroupBy(P => P.Tag); foreach (var item in GROUP) { string str = item.Key.ToString(); List <TextBox> tempList = item.OrderBy(p => p.Text).ToList(); bool b1 = false; for (int j = 1; j < tempList.Count; j++) { long d1 = long.Parse(tempList[j - 1].Text); long d2 = long.Parse(tempList[j].Text); if (d2 - d1 != target) { int n1 = this.GroupTextlist.IndexOf(tempList[j]); string labelText = this.GroupTextLabellist[n1].Text; b1 = true; } } //valueList.Add(long.Parse(item.Min(p => p.Text))); //valueList.Add(long.Parse(item.Max(p => p.Text))); if (b1) { message += "第" + str + "组有数据不连续\r\n\r\n"; } } List <string> LabelTextList = new List <string>() { "A", "B", "C", "D", "E", "F", "G", "H", "I" }; List <long> list1 = this.GroupTextlist.Where(p => !string.IsNullOrWhiteSpace(p.Text)).Select(p => long.Parse(p.Text)).OrderBy(p => p).ToList(); for (int i = 0; i < list1.Count - 1; i++) { if (list1[i + 1] - list1[i] != 1) { TextBox t1 = this.GroupTextlist.Where(p => p.Text == list1[i].ToString()).FirstOrDefault(); TextBox t2 = this.GroupTextlist.Where(p => p.Text == list1[i + 1].ToString()).FirstOrDefault(); if (t1.Tag.ToString() != t2.Tag.ToString()) { message += string.Format("第{0}组数据和第{1}组数据不连续\r\n\r\n", t1.Tag.ToString(), t2.Tag.ToString()); } } } //for (int i = 1; i+1 < valueList.Count; i+=2) { // if (Math.Abs(valueList[i] - valueList[i + 1]) != 1) { // int n1 = i / 2+1; // int n2 = (i + 1) / 2 + 1; // message += string.Format("第{0}组数据和第{1}组数据不连续\r\n\r\n",n1,n2); // } //} if (!string.IsNullOrEmpty(message)) { DialogResult dr = MyDialogOption.show("提示", message + "是否继续绑定!", "是,继续完成绑定", "否,返回检查"); // DialogResult dr = MessageBox.Show( message+"是否继续绑定!", "提示",MessageBoxButtons.OKCancel); return(dr == DialogResult.OK); } return(true); }
private void button1_Click(object sender, EventArgs e) { //Task.Factory.StartNew(() => //{ if (yanzhengGroupText()) { Models.ProjectDetails details = detailsBLL.GetModel(this.comboBox4.SelectedValue.ToString()); //details.DeviceDataList = new List<Models.DeviceData>(); BLL.DeviceDataBLL DeviceDataBLL = new BLL.DeviceDataBLL(); List <string> list = new List <string>() { "A", "B", "C", "D", "E", "F", "G", "H", "I" }; int n = (this.GroupInfo.SelectedIndex + 1) * 3; bool ifSuccess = true; string CreateDataStr = DateTime.Now.ToString("yyyyMMddHHmmss"); string CreateDataStrGroup = ""; int m = this.GroupTextlist.Where(p => !string.IsNullOrWhiteSpace(p.Text)).Count(); int a = m / 3; int b = m % 3; //if (a == 0) //{ // DialogResult dr = MessageBox.Show("至少需要填写一组数据,是否继续","提示",MessageBoxButtons.OKCancel ); // if (dr != DialogResult.OK) // { // MoveToNextText(); // return; // } //} if (b != 0) { string messagestr = ""; if (this.GroupInfo.SelectedIndex == 0) { if (textBox1.Text.Length == 0 || textBox2.Text.Length == 0 || textBox3.Text.Length == 0) { messagestr += "第一组数据不完整,是否继续提交绑定\r\n\r\n"; } } else if (this.GroupInfo.SelectedIndex == 1) { if (textBox1.Text.Length == 0 || textBox2.Text.Length == 0 || textBox3.Text.Length == 0) { messagestr += "第一组数据不完整,是否继续提交绑定\r\n\r\n"; } if (textBox4.Text.Length == 0 || textBox5.Text.Length == 0 || textBox6.Text.Length == 0) { messagestr += "第二组数据不完整,是否继续提交绑定\r\n\r\n"; } } else if (this.GroupInfo.SelectedIndex == 2) { if (textBox1.Text.Length == 0 || textBox2.Text.Length == 0 || textBox3.Text.Length == 0) { messagestr += "第一组数据不完整,是否继续提交绑定\r\n\r\n"; } if (textBox4.Text.Length == 0 || textBox5.Text.Length == 0 || textBox6.Text.Length == 0) { messagestr += "第二组数据不完整,是否继续提交绑定\r\n\r\n"; } if (textBox7.Text.Length == 0 || textBox8.Text.Length == 0 || textBox9.Text.Length == 0) { messagestr += "第三组数据不完整,是否继续提交绑定\r\n\r\n"; } } DialogResult dr = MyDialogOption.show("提示", messagestr, "是,继续完成绑定", "否,返回补充完整"); // DialogResult dr = MessageBoxEx.Show("数据不完整,是否继续提交绑定", "提示", MessageBoxButtons.OKCancel, new string[] { "是,继续完成绑定", "否,返回补充完整" }); // DialogResult dr = MessageBox.Show("数据不完整,是否继续提交绑定?", "确认", MessageBoxButtons.OKCancel); if (dr != DialogResult.OK) { MoveToNextText(); return; } } for (int i = 0; i < n; i++) { if (list[i] == "A" || list[i] == "B" || list[i] == "C") { CreateDataStrGroup = CreateDataStr + "A"; } else if (list[i] == "D" || list[i] == "E" || list[i] == "F") { CreateDataStrGroup = CreateDataStr + "B"; } else { CreateDataStrGroup = CreateDataStr + "C"; } Models.DeviceData deviceData = new Models.DeviceData() { DataId = this.comboBox4.SelectedValue.ToString() + "_" + list[i] + "_" + Utils.getGUID(), DeviceValue = this.GroupTextlist[i].Text, GroupName = list[i], ProjectDetailId = this.comboBox4.SelectedValue.ToString(), Instar = this.Instar.SelectedItem.ToString(), YangSheng = this.yangsheng.SelectedItem.ToString(), SamplingDate = this.SamplingDate.Value.ToString("yyyy-MM-dd"), CreateDate = CreateDataStrGroup, IfUpload = 0, NotUploadReason = "网络" }; if (!Regex.IsMatch(deviceData.DeviceValue, "^\\d{15}$")) { continue; } //判断重复 if (DeviceDataBLL.GetModelByWhere(" DeviceValue='" + deviceData.DeviceValue + "'") != null) { MessageBox.Show("绑定数据库中已经存在[" + deviceData.DeviceValue + "]RFID编号请核实!"); return; } BLL.FunctionResult result = DeviceDataBLL.Create(deviceData); if (!result.ExcuteState) { ifSuccess = false; break; } this.DeviceDataTotal++; setProcess(); this.DetailsForUpload.Enqueue(deviceData); } if (ifSuccess) { details.DetailState = 1; this.Invoke(new EventHandler((aa, bb) => { MessageBox.Show("绑定数据完成!"); resetTextBox(); MoveToNextText(); })); } } //}); }