private void Btn_result_Click(object sender, EventArgs e) { if (rowDataPath == "" || rowDataPath == null) { Log("请先载入rowData再点分析!", Color.Red, true); return; } string new_path = Path.GetDirectoryName(rowDataPath) + "\\生成的数据.xls"; //ExcelOperation.Analysize(new_path, chips); bool result = ExcelOperation.Analysize(new_path, chips); if (result) { //Log("分析完成,数据保存在"+new_path, Color.Green, true); ExDictionary dic = new ExDictionary(); dic["msg"] = "分析完成,数据保存在" + new_path; dic["color"] = Color.Green; dic["nextline"] = true; Notification.GetInstance().PostNotification("log", dic); MessageBox.Show("分析完成!"); } else { MessageBox.Show("分析失败", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); //Log("分析失败",Color.Red,true); ExDictionary dic = new ExDictionary(); dic["msg"] = "分析失败!"; dic["color"] = Color.Red; dic["nextline"] = true; Notification.GetInstance().PostNotification("log", dic); } }
private void button_scan_Click(object sender, EventArgs e) { OpenFileDialog op = new OpenFileDialog(); op.Title = "请选择rowData的excel文件"; op.Multiselect = false; if (op.ShowDialog() != DialogResult.OK) { return; } rowDataPath = op.FileName; chips = ReadRowData(rowDataPath); ExDictionary dic = new ExDictionary(); if (chips != null) { dic["msg"] = "载入并读取数据成功!Row Data:" + rowDataPath; dic["color"] = Color.Green; dic["nextline"] = true; } else { dic["msg"] = "载入数据失败,请检查Row Data:" + rowDataPath; dic["color"] = Color.Red; dic["nextline"] = true; } Notification.GetInstance().PostNotification("log", dic); }
public static void StockUpPasteSettings(this Pawn pawn) { Dictionary <Pawn, ExDictionary <ThingDef, int> > settings = SmartMedicineGameComp.Settings(); if (settings.ContainsKey(SmartMedicineGameComp.Get().copiedPawn)) { settings[pawn] = new ExDictionary <ThingDef, int>(settings[SmartMedicineGameComp.Get().copiedPawn]); } }
/// <summary> /// 为适应借口而写的 /// </summary> /// <param name="dic"></param> /// <returns></returns> public int Log(ExDictionary dic) { string msg = dic["msg"] as string; Color color = (Color)dic["color"]; bool nextline = (bool)dic["nextline"]; Log(msg, color, nextline); return(0); }
public static Dictionary <ThingDef, int> StockUpSettings(this Pawn pawn) { var settings = SmartMedicineGameComp.Settings(); if (!settings.TryGetValue(pawn, out ExDictionary <ThingDef, int> pawnSettings)) { settings[pawn] = pawnSettings = new ExDictionary <ThingDef, int>(); } return(pawnSettings); }
/// <summary> /// 调用方法 /// </summary> /// <param name="name">与方法相关联的字符串</param> /// <param name="dic">方法的参数</param> public void PostNotification(string name, ExDictionary dic) { foreach (NotificationEntry i in _notificationEntrys) { if (i.name == name) { if (i.nf != null) { i.nf(dic); } } } }
/// <summary> /// データ群を<see cref="DataElement"/>型の情報群に変換する /// </summary> /// <remarks><paramref name="encode"/>がnullの時は<see cref="Encoding.UTF8"/>を使う</remarks> /// <param name="encode">シリアライズ時のエンコード</param> /// <returns>情報群</returns> public static Elements ExDicToDataElements(ExDictionary dic, Encoding encode = null, bool forceSerialize = false) { var list = new Elements(); encode = encode ?? Encoding.UTF8; foreach (var pair in dic) { foreach (var e in pair.Value) { list.Add(Object2DataElement(e.Value, e.Key, pair.Key, encode, forceSerialize)); } } return(list); }
public static Chip[] ReadRowData(string path) { Chip[] _chips; try { IWorkbook workbook = Factory.GetWorkbook(path); IWorksheet worksheet = workbook.Worksheets["Overview"]; if (worksheet == null) { ExDictionary dic = new ExDictionary(); dic["msg"] = "所载入的RowData格式不正确:没有Overview工作表!"; dic["color"] = Color.Red; dic["nextline"] = true; Notification.GetInstance().PostNotification("log", dic); return(null); } int height = worksheet.UsedRange.RowCount; int chips = height - 11; _chips = new Chip[chips]; for (int i = 0; i < chips; i++) { _chips[i] = new Chip(); //赋值 //int endCount = (int)RowName.B * 26 + (int)RowName.A; int endCount = 59; for (int j = 1; j <= endCount; j++) { string address = GetRowNameByIndex(j) + (i + 12).ToString(); _chips[i][j - 1] = worksheet.UsedRange.Cells[address].Value.ToString(); } } } catch (Exception e) { ExDictionary dic = new ExDictionary(); dic["msg"] = "信息:" + e.Message + "\r\n源:" + e.StackTrace; dic["color"] = Color.Red; dic["nextline"] = true; Notification.GetInstance().PostNotification("log", dic); _chips = null; } return(_chips); }
/// <summary> /// /// </summary> /// <param name="path">生成的文件路径</param> /// <param name="chips">源数据</param> public static bool Analysize(string path, Chip[] chips) { bool result = false; FileStream fs_create = new FileStream(path, FileMode.Create, FileAccess.ReadWrite); try { //1.获取有多少个chip var count = from i in chips select i[1]; //选取所有的chipID var count_distinct = count.Distinct().ToArray(); //对chipID去重,结果是数组。 //2.通过文件流来创建workbook,注意最后要关闭。 IWorkbook workbook = Factory.GetWorkbook(); IWorksheet worksheet = (IWorksheet)workbook.Sheets[0]; for (int i = 0; i < count_distinct.Length; i++) { if (i == 0) { worksheet.Name = count_distinct[0]; } else { IWorksheet next_worksheet = (IWorksheet)worksheet.CopyAfter(worksheet); next_worksheet.Name = count_distinct[i]; } IWorksheet currentworksheet = workbook.Worksheets[count_distinct[i]]; //分析数据 //1.搜索chipID为count_distinct[i]的所有chip对象。 var chip_group = from j in chips where j[1] == count_distinct[i] select j; //2.对同一个chipID的所有chip对象进行分析。 var TemperatureMeasureds = (from j in chip_group select j[8]).ToArray(); //3.取最大温度量测值和最小温度量测值做比较 double[] temperatures = new double[TemperatureMeasureds.Length]; for (int k = 0; k < TemperatureMeasureds.Length; k++) { temperatures[k] = Convert.ToDouble(TemperatureMeasureds[k]); } double maxvalue = Enumerable.Max(temperatures); double minvalue = Enumerable.Min(temperatures); //4.搜索最大温度值的芯片与最小温度值的芯片: var Max_chip = (from j in chip_group where Convert.ToDouble(j[8]) == maxvalue select j).ToArray()[0]; var Min_chip = (from j in chip_group where Convert.ToDouble(j[8]) == minvalue select j).ToArray()[0]; //得出需要的数据: //Gain Resistance 14 L //Imod_90mA 38 L //Ith_Imod 17 L //Pout_90mA 42 两个,一个高一个低 H L //Reflection3rd Distance 23 L //SMSR_90mA 57 L //Vgain_90mA 34 L //WVL_90mA 50 H L IWorksheet current_worksheet = workbook.Worksheets[i]; current_worksheet.Cells["A1"].Value = "GAINR_L"; current_worksheet.Cells["B1"].Value = "Gain Resistance (Ohm)"; current_worksheet.Cells["C1"].Value = Min_chip[14]; current_worksheet.Cells["A2"].Value = "IMOD_90MA_L"; current_worksheet.Cells["B2"].Value = "Imod_90mA (mA)"; current_worksheet.Cells["C2"].Value = Min_chip[38]; current_worksheet.Cells["A3"].Value = "ITH_L"; current_worksheet.Cells["B3"].Value = "Ith_Imod (mA)"; current_worksheet.Cells["C3"].Value = Min_chip[17]; current_worksheet.Cells["A4"].Value = "POUT_90MA_H"; current_worksheet.Cells["B4"].Value = "Pout_90mA (mW)"; current_worksheet.Cells["C4"].Value = Max_chip[42]; current_worksheet.Cells["A5"].Value = "POUT_90MA_L"; current_worksheet.Cells["B5"].Value = "Pout_90mA (mW)"; current_worksheet.Cells["C5"].Value = Min_chip[42]; current_worksheet.Cells["A6"].Value = "REFCECTLON_D3_L"; current_worksheet.Cells["B6"].Value = "Reflection3rd Distance (K/A^3)"; current_worksheet.Cells["C6"].Value = Min_chip[23]; current_worksheet.Cells["A7"].Value = "SMSR_90MA_L"; current_worksheet.Cells["B7"].Value = "SMSR_90mA (dB)"; current_worksheet.Cells["C7"].Value = Min_chip[57]; current_worksheet.Cells["A8"].Value = "VGAIN_90MA_L"; current_worksheet.Cells["B8"].Value = Chip.properties[34]; current_worksheet.Cells["C8"].Value = Min_chip[34]; current_worksheet.Cells["A9"].Value = "WL_90MA_H"; current_worksheet.Cells["B9"].Value = Chip.properties[50]; current_worksheet.Cells["C9"].Value = Max_chip[50]; current_worksheet.Cells["A10"].Value = "WL_90MA_L"; current_worksheet.Cells["B10"].Value = Chip.properties[50]; current_worksheet.Cells["C10"].Value = Min_chip[50]; } workbook.SaveToStream(fs_create, FileFormat.Excel8); result = true; } catch (Exception e) { ExDictionary dic = new ExDictionary(); dic["msg"] = "异常:" + e.Message + "\r\n异常出现的地方:" + e.StackTrace; dic["color"] = Color.Red; dic["nextline"] = true; Notification.GetInstance().PostNotification("log", dic); result = false; } finally { fs_create.Close(); } return(result); }