/// <summary> /// DGV 列表格式变化事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void dgv_BundledList_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e) { switch (e.ColumnIndex) { case 1: e.Value = e.Value.Equals(0) ? Properties.Resources.check : Properties.Resources.block; break; case 4: if (e.Value == null) { return; } if (!Regex.IsMatch(e.Value.ToString(), @"^\d+$")) { return; } StringBuilder sb = new StringBuilder(); int partition = HexadecimalConversion.ObjToInt(e.Value); for (int i = 0; i < 16; i++) { if (BinaryHelper.GetIntegerSomeBit(partition, i) == 1) { sb.AppendFormat(" {0} 分区", i + 1); } } e.Value = sb.ToString(); break; } }
private void dgv_BundledList_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e) { if (e.ColumnIndex != 4) { return; } if (e.Value.Equals(0)) { e.Value = "关闭"; } else { if (Regex.IsMatch(e.Value.ToString(), @"^\d+$")) { StringBuilder sb = new StringBuilder(); int partition = HexadecimalConversion.ObjToInt(e.Value); for (int i = 0; i < 16; i++) { if (BinaryHelper.GetIntegerSomeBit(partition, i) == 1) { sb.AppendFormat(" {0} 分区", i + 1); } } e.Value = sb.ToString(); } } }
private void GetDeviceInfo(string filename) { try { DeviceInfo dinfo = new DeviceInfo(); using (TextFieldParser tfp = new TextFieldParser(filename)) { tfp.Delimiters = new[] { ",", "<", ">" }; tfp.TextFieldType = FieldType.Delimited; while (!tfp.EndOfData) { string[] content = tfp.ReadFields(); if (content != null) { int number = Convert.ToInt32(content[0], 16); string value = content[2]; switch (number) { case 0: dinfo.HostNumber = HexadecimalConversion.StrToInt(value.Substring(0, 2)); dinfo.FrequencyOffset = HexadecimalConversion.StrToInt(value.Substring(2, 2)); dinfo.WirelessNumber = HexadecimalConversion.StrToInt(value.Substring(4, 8)); dinfo.CameraDetection = HexadecimalConversion.StrToInt(value.Substring(12, 2)); break; case 1: dinfo.CardReadDistance = HexadecimalConversion.StrToInt(value); break; case 2: dinfo.ReadCardDelay = HexadecimalConversion.StrToInt(value); break; case 8: dinfo.Partition = Convert.ToInt32(value, 16); break; case 9: if (!string.IsNullOrEmpty(value)) { dinfo.IOMouth = HexadecimalConversion.StrToInt(value); } break; case 10: dinfo.SAPBF = HexadecimalConversion.StrToInt(value); break; case 12: switch (value.Substring(value.Length - 2, 2)) { case "F0": //继电器开闸 dinfo.OpenModel = 3; dinfo.BrakeNumber = 1; break; case "AA": //学习遥控器开闸 dinfo.OpenModel = 2; dinfo.BrakeNumber = 1; break; case "FF": //串口开闸 dinfo.OpenModel = 0; dinfo.BrakeNumber = Convert.ToInt32(value.Substring(0, 6), 16); break; case "55": //无线电开闸 dinfo.OpenModel = 1; dinfo.BrakeNumber = Convert.ToInt32(value.Substring(0, 6), 16); break; } break; case 13: dinfo.Language = HexadecimalConversion.StrToInt(value); break; case 15: dinfo.Detection = HexadecimalConversion.StrToInt(value); break; case 17: dinfo.Detection = HexadecimalConversion.StrToInt(value); break; } } } } DbHelper.Db.Insert(dinfo); } catch (Exception ex) { MessageBox.Show(ex.Message, @"提示", MessageBoxButtons.OK, MessageBoxIcon.Error); } }