/// <summary> /// 设置右上角提示 /// </summary> /// <param name="rowItemCode"></param> /// <param name="columnIndex"></param> /// <param name="tips"></param> /// <param name="updateTypes"></param> public void SetTips(string rowItemCode, int columnIndex, string tips, GridOilColumnType updateTypes = GridOilColumnType.Calc) { if (updateTypes == GridOilColumnType.None) { return; } var cellGroup = GetGridOilCellGroup(rowItemCode, columnIndex); if (cellGroup == null) { return; } if (updateTypes.HasFlag(GridOilColumnType.Calc)) { var cell = cellGroup.CalcCell; //string tempTips = oilTool.calDataDecLimit(tips, cell.RowEntity.decNumber); string tempTips = oilTool.calDataDecLimit(tips, cell.RowEntity.decNumber, cell.RowEntity.valDigital); cell.Tips = tempTips; this.InvalidateCell(cell); } if (updateTypes.HasFlag(GridOilColumnType.Lab)) { var cell = cellGroup.LabCell; cell.Tips = tips; this.InvalidateCell(cell); } }
/// <summary> /// 获取当前的DataGridView的B库的值 /// </summary> /// <param name="dataGridView">当前的DataGridView</param> /// <returns></returns> public static Dictionary <float, float> getDataBaseBfromDataGridView(DataGridView dataGridView) { Dictionary <float, float> returnDic = new Dictionary <float, float>(); OilTools oilTool = new OilTools();//lh:为后面调用小数位处理函数calDataDecLimit()定义实体对象 if (dataGridView.Rows.Count != 5) { return(returnDic); } for (int i = FrmCurveAGlobal._dataColStart; i < dataGridView.ColumnCount; i++) { object objx = dataGridView.Rows[FrmCurveAGlobal._curveRowXIndex].Cells[i].Value; object objy = dataGridView.Rows[FrmCurveAGlobal._curveRowYIndex].Cells[i].Value; //object objx = dataGridView.Rows[FrmCurveAGlobal._curveRowXIndex].Cells[i].Tag; //object objy = dataGridView.Rows[FrmCurveAGlobal._curveRowYIndex].Cells[i].Tag; #region "数据转换" if (objx == null || objy == null) { continue; } if (objx.ToString() == string.Empty || objy.ToString() == string.Empty) { continue; } if (objx.ToString() == "非数字" || objy.ToString() == "非数字") { continue; } //oilTool = (OilTools)objx;//lh:实体对象不能为空 float F_x = 0, F_y = 0; if (!float.TryParse(oilTool.calDataDecLimit(objx.ToString(), 2, 5), out F_x) || !float.TryParse(objy.ToString(), out F_y))//lh:修改前面判断条件 { continue; } if (returnDic.Keys.Contains(F_x)) { continue; } returnDic.Add(F_x, F_y); #endregion } return(returnDic); }
/// <summary> /// 获取渣油表的DataGridViewd的B库的ECP和X轴值 /// </summary> /// <returns></returns> public static Dictionary <int, float> getDataBaseECP_BXFromDataGridViewWhenRESIDUE(DataGridView dataGridView) { Dictionary <int, float> returnDic = new Dictionary <int, float>(); if (dataGridView.Rows.Count != 5) { return(returnDic); } for (int i = FrmCurveAGlobal._dataColStart; i < dataGridView.ColumnCount; i++) { object objECP = dataGridView.Rows[FrmCurveAGlobal._ECPRowIndex].Cells[i].Value; object objx = dataGridView.Rows[FrmCurveAGlobal._curveRowXIndex].Cells[i].Value; #region "数据转换" if (objx == null || objECP == null) { continue; } if (objx.ToString() == "非数字" || objECP.ToString() == "非数字") { continue; } if (objx.ToString() == string.Empty || objECP.ToString() == string.Empty) { continue; } int ecp = 0; float F_x = 0; OilTools oilTool = new OilTools();//lh:为后面调用小数位处理函数calDataDecLimit()定义实体对象 if (float.TryParse(oilTool.calDataDecLimit(objx.ToString(), 2, 5), out F_x) && int.TryParse(objECP.ToString(), out ecp)) {//lh:增加WY的小数位数处理函数 if (!returnDic.Keys.Contains(ecp)) { returnDic.Add(ecp, F_x); } } #endregion } return(returnDic); }
private void CurveDataDgv_CellLeave(object sender, DataGridViewCellEventArgs e) { DataGridViewCell cell = this.CurveDataDgv.Rows[e.RowIndex].Cells[e.ColumnIndex]; string tempCell = cell.Value as string; if (string.IsNullOrWhiteSpace(tempCell)) { return; } var tempOutputAxis = (OutputAxisEntity)this.CurveDataDgv.Columns[e.ColumnIndex].Tag; if (tempOutputAxis == null) { return; } this.CurveDataDgv.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = tempOutputAxis.iDecNumber == null ? tempCell : oiltool.calDataDecLimit(tempCell, tempOutputAxis.iDecNumber.Value); }
private void button2_Click(object sender, EventArgs e) { OilTools oiltools = new OilTools(); string temp = oiltools.calDataDecLimit("5.88047332E+21", null, 4); }
/// <summary> /// 将宽馏分的列数据写入原油 /// </summary> /// <param name="oilA"></param> /// <param name="Data"></param> /// <param name="tableType"></param> private static void WriteToOilA(ref OilInfoEntity oilA, List <WCol> Data, EnumTableType tableType) { try { int colNum = 0; foreach (var col in Data) { #region "获取列ID" colNum++; int oilTableColID = 0; try { oilTableColID = _colCache["Cut" + colNum.ToString(), tableType].ID; } catch { MessageBox.Show("获取不到colID" + colNum.ToString()); } #endregion #region "添加ICP ECP" if (tableType == EnumTableType.Narrow || tableType == EnumTableType.Wide || tableType == EnumTableType.Residue) { if (tableType == EnumTableType.Narrow || tableType == EnumTableType.Wide)//添加icp ecp { #region var oilTableICPRowID = _rowCache["ICP", tableType].ID; OilDataEntity oilDataICP = new OilDataEntity(); oilDataICP.oilInfoID = oilA.ID; oilDataICP.oilTableColID = oilTableColID; oilDataICP.oilTableRowID = oilTableICPRowID; string data = col.ICP == 0 ? "" : col.ICP.ToString(); oilDataICP.labData = data; oilDataICP.calData = data; oilA.OilDatas.Add(oilDataICP); var oilTableECPRowID = _rowCache["ECP", tableType].ID; OilDataEntity oilDataECP = new OilDataEntity(); oilDataECP.oilInfoID = oilA.ID; oilDataECP.oilTableColID = oilTableColID; oilDataECP.oilTableRowID = oilTableECPRowID; data = col.ECP == 0 ? "" : col.ECP.ToString(); oilDataECP.labData = data; oilDataECP.calData = data; oilA.OilDatas.Add(oilDataECP); #endregion } if (tableType == EnumTableType.Residue)//添加icp ecp { #region var ICProw = _rowCache["ICP", tableType]; OilDataEntity oilDataICP = new OilDataEntity(); oilDataICP.oilInfoID = oilA.ID; oilDataICP.oilTableColID = oilTableColID; oilDataICP.oilTableRowID = ICProw.ID; string data = col.ICP.ToString(); oilDataICP.labData = data; oilDataICP.calData = data; oilA.OilDatas.Add(oilDataICP); #endregion } } #endregion #region "添加ICP ECP" if (tableType == EnumTableType.Wide || tableType == EnumTableType.Residue) //如果是“宽馏分”和“渣油” 温度判断是什么油 ,宽 和 渣 才有 WCT { string oilType = GetOilType(col.ICP, col.ECP); //得到wct的种类 S_ParmBll s_ParmBll = new S_ParmBll(); List <S_ParmEntity> wCutTypes; //todo 如果是“渣油”变为rct if (tableType == EnumTableType.Residue) { wCutTypes = s_ParmBll.GetParms("RCT"); } else { wCutTypes = s_ParmBll.GetParms("WCT"); } string WCT = ""; try { WCT = wCutTypes.Where(c => c.parmName == oilType).FirstOrDefault().parmValue; } catch { MessageBox.Show("ICP:" + col.ICP + "ECP:" + col.ECP + "未找到对应原油类型"); } //宽馏分的wct行 var rowWCT = _rowCache["WCT", tableType]; OilDataEntity oilDataWCT = new OilDataEntity(); oilDataWCT.oilInfoID = oilA.ID; oilDataWCT.oilTableColID = oilTableColID; oilDataWCT.oilTableRowID = rowWCT.ID; string data = WCT; if (data.Length > 12) { data = data.Substring(0, 12); } oilDataWCT.labData = data; oilDataWCT.calData = data; oilA.OilDatas.Add(oilDataWCT); } #endregion #region "其他数据赋值" foreach (var item in col.Cells) { OilTableRowEntity rowEntity = null;//根据itemcode得到行id try { if (item.ItemCode == "TYP") { //rowEntity = _rowCache["TYP", EnumTableType.Info]; oilA.type = item.LabData; //更新原油信息 OilBll.saveInfo(oilA); continue; } else { rowEntity = _rowCache[item.ItemCode, tableType]; } if (rowEntity == null) { continue; } } catch { MessageBox.Show("rowEntity获取失败"); } OilDataEntity oilData = new OilDataEntity(); oilData.oilInfoID = oilA.ID; oilData.oilTableColID = oilTableColID; oilData.oilTableRowID = rowEntity.ID; string labData; try { OilTools tools = new OilTools(); if (rowEntity.decNumber != null) { labData = tools.calDataDecLimit(item.LabData, rowEntity.decNumber + 2, rowEntity.valDigital);//输入Execl表的过程中转换数据精度 } else { labData = tools.calDataDecLimit(item.LabData, rowEntity.decNumber, rowEntity.valDigital);//输入Execl表的过程中转换数据精度 } } catch { MessageBox.Show("lab:" + item.LabData); } oilData.labData = item.LabData; oilData.calData = item.LabData; oilA.OilDatas.Add(oilData); } #endregion } } catch (Exception ex) { Log.Error("erro:" + ex); } }
/// <summary> /// 获取曲线下标所对应的真实单元格下标的位置 /// </summary> /// <param name="Value">查找的值</param> /// <param name="rowNum">查找的值对应的行数</param> /// <returns>查找不_到返回-1</returns> public static int FindItemCodeValueColIndexfromSpecRow(DataGridView dataGridView, float Value, int rowNum) { int index = -1; OilTools oilTool = new OilTools(); //lh:为后面调用小数位处理函数calDataDecLimit()定义实体对象 if (rowNum > dataGridView.RowCount || rowNum < 0) { return(index); } for (int i = FrmCurveAGlobal._dataColStart; i < dataGridView.ColumnCount; i++) { object xValue = dataGridView.Rows[rowNum].Cells[i].Value; if (xValue != null && xValue.ToString() != string.Empty && xValue.ToString() != "非数字" && oilTool.calDataDecLimit(xValue.ToString(), 2) == oilTool.calDataDecLimit(Value.ToString(), 2)) // if (xValue != null && xValue.ToString() != string.Empty && xValue.ToString() != "非数字" && xValue.ToString() == Value.ToString()) { index = i; //获取真实的对应列 break; } } return(index); }