///// <summary> ///// 设置单元格最后两行,在第A库X轴填充值 ///// </summary> ///// <param name="keys"></param> //public static void addDataToDataGridViewDataBaseB(ref OilInfoBEntity oilInfoB, ref DataGridView dataGridView, CurveTypeCode typeCode, CurveParmTypeEntity CurveXParmType, CurveParmTypeEntity CurveYParmType) //{ // if (dataGridView.Rows.Count < 5) // return; // if (typeCode == CurveTypeCode.YIELD || typeCode == CurveTypeCode.DISTILLATE) // { // #region "!RESIDUE" // CurveEntity XCurve = oilInfoB.curves.Where(o => o.propertyX == "ECP" && o.propertyY == CurveXParmType.ItemCode).FirstOrDefault(); // CurveEntity YCurve = oilInfoB.curves.Where(o => o.propertyX == "ECP" && o.propertyY == CurveYParmType.ItemCode).FirstOrDefault(); // if (XCurve == null || YCurve == null) // return; // if (XCurve.curveDatas.Count <= 0 || YCurve.curveDatas.Count <= 0) // return; // Dictionary<float, List<float>> ECP_X_Y = new Dictionary<float, List<float>>(); // for (int index = 0; index < XCurve.curveDatas.Count; index++) // { // float ecp = XCurve.curveDatas[index].xValue; // CurveDataEntity tempCurveData = YCurve.curveDatas.Where(o => o.xValue == ecp).FirstOrDefault(); // if (tempCurveData != null) // { // List<float> X_Y = new List<float>(); // X_Y.Add(XCurve.curveDatas[index].yValue); // X_Y.Add(tempCurveData.yValue); // ECP_X_Y.Add(ecp, X_Y); // } // } // if (ECP_X_Y.Count <= 0) // return; // foreach (float ECP_Key in ECP_X_Y.Keys) // { // int colIndex = FindItemCodeValueColIndexfromSpecRow(dataGridView, ECP_Key, 2); // if (colIndex != -1) // { // dataGridView.Rows[FrmCurveAGlobal._curveRowXIndex].Cells[colIndex].Value = ECP_X_Y[ECP_Key][0]; // dataGridView.Rows[FrmCurveAGlobal._curveRowYIndex].Cells[colIndex].Value = ECP_X_Y[ECP_Key][1]; // } // } // #endregion // } // else if (typeCode == CurveTypeCode.RESIDUE) // { // #region "RESIDUE" // CurveEntity XCurve = oilInfoB.curves.Where(o => o.propertyX == "ECP" && o.propertyY == CurveXParmType.ItemCode).FirstOrDefault(); // CurveEntity YCurve = oilInfoB.curves.Where(o => o.propertyX == "WY" && o.propertyY == CurveYParmType.ItemCode).FirstOrDefault(); // if (XCurve == null || YCurve == null) // return; // if (XCurve.curveDatas.Count <= 0 || YCurve.curveDatas.Count <= 0) // return; // Dictionary<float, List<float>> ECP_X_Y = new Dictionary<float, List<float>>(); // for (int index = 0; index < XCurve.curveDatas.Count; index++) // { // //float ecp = XCurve.curveDatas[index].xValue; // //if (ECP_WYDic.Keys.Contains(ecp)) // //{ // // float wy = ECP_WYDic[ecp]; // // CurveDataEntity tempCurveData = YCurve.curveDatas.Where(o => o.xValue == wy).FirstOrDefault(); // // if (tempCurveData != null) // // { // // List<float> X_Y = new List<float>(); // // X_Y.Add(XCurve.curveDatas[index].yValue); // // X_Y.Add(tempCurveData.yValue); // // ECP_X_Y.Add(ecp, X_Y); // // } // //} // } // if (ECP_X_Y.Count <= 0) // return; // foreach (float ECP_Key in ECP_X_Y.Keys) // { // int colIndex = FindItemCodeValueColIndexfromSpecRow(dataGridView, ECP_Key, 2); // if (colIndex != -1) // { // dataGridView.Rows[FrmCurveAGlobal._curveRowXIndex].Cells[colIndex].Value = ECP_X_Y[ECP_Key][0]; // dataGridView.Rows[FrmCurveAGlobal._curveRowYIndex].Cells[colIndex].Value = ECP_X_Y[ECP_Key][1]; // } // } // #endregion // } //} #endregion /// <summary> /// 渣油曲线内插和外延后设置渣油曲线的单元格最后一行的值 /// </summary> /// <param name="dataGridView"></param> /// <param name="typeCode"></param> /// <param name="CurveXParmType"></param> /// <param name="CurveYParmType"></param> /// <param name="ECP_WYDataBDic"></param> /// <param name="DataBaseBDic"></param> public static void addValueToDataGridViewDataBaseBYWhenRESIDUE(ref DataGridView dataGridView, CurveTypeCode typeCode, CurveParmTypeEntity CurveXParmType, CurveParmTypeEntity CurveYParmType, Dictionary <int, float> ECP_WYDataBDic, Dictionary <float, float> DataBaseBDic) { #region "输入条件判断" if (dataGridView.RowCount != 5) { return; } if (DataBaseBDic.Count <= 0) { return; } if (typeCode != CurveTypeCode.RESIDUE) { return; } if (ECP_WYDataBDic == null) { return; } if (ECP_WYDataBDic.Count != DataBaseBDic.Count) { return; } #endregion OilTools oilTool = new OilTools(); OilTableRowEntity tempRowX = OilTableRowBll._OilTableRow.Where(o => o.itemCode == CurveXParmType.ItemCode && o.oilTableTypeID == CurveXParmType.OilTableTypeID).FirstOrDefault(); OilTableRowEntity tempRowY = OilTableRowBll._OilTableRow.Where(o => o.itemCode == CurveYParmType.ItemCode && o.oilTableTypeID == CurveYParmType.OilTableTypeID).FirstOrDefault(); dataGridView[FrmCurveAGlobal._dataColStart, FrmCurveAGlobal._curveRowXIndex].Value = dataGridView[FrmCurveAGlobal._dataColStart, 0].Value; //原油性质赋值 dataGridView[FrmCurveAGlobal._dataColStart, FrmCurveAGlobal._curveRowYIndex].Value = dataGridView[FrmCurveAGlobal._dataColStart, 1].Value; //原油性质赋值 foreach (int cutPoint in ECP_WYDataBDic.Keys) { int colNum = FindItemCodeValueColIndexfromSpecRow(dataGridView, cutPoint, FrmCurveAGlobal._ECPRowIndex); if (colNum == -1) { continue; } if (ECP_WYDataBDic[cutPoint].Equals(float.NaN)) { continue; } if (DataBaseBDic[ECP_WYDataBDic[cutPoint]].Equals(float.NaN)) { continue; } //string strItemCodeValue = oilTool.calDataDecLimit(DataBaseBDic[ECP_WYDataBDic[cutPoint]].ToString(), tempRowY.decNumber,tempRowY.valDigital); //dataGridView[colNum, FrmCurveAGlobal._curveRowYIndex].Value = strItemCodeValue; dataGridView[colNum, FrmCurveAGlobal._curveRowYIndex].Tag = DataBaseBDic[ECP_WYDataBDic[cutPoint]].ToString(); dataGridView[colNum, FrmCurveAGlobal._curveRowYIndex].Value = DataBaseBDic[ECP_WYDataBDic[cutPoint]]; } }
/// <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); }
/// <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); }
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="dataGridView">需要填充的单元格</param> /// <param name="typeCode">曲线的类型</param> /// <param name="DataBaseBDic">需要填充的数据</param> /// <param name="CurveYParmType">最后一行物性</param> public static void addValueToDataGridViewDataBaseBYWhenNORESIDUE(ref DataGridView dataGridView, CurveTypeCode typeCode, Dictionary <float, float> DataBaseBDic, CurveParmTypeEntity CurveYParmType) { #region "输入条件判断" if (dataGridView.RowCount != 5) { return; } if (DataBaseBDic.Count <= 0) { return; } if (typeCode == CurveTypeCode.RESIDUE) { return; } #endregion OilTableRowEntity tempRowY = OilTableRowBll._OilTableRow.Where(o => o.itemCode == CurveYParmType.ItemCode && o.oilTableTypeID == CurveYParmType.OilTableTypeID).FirstOrDefault(); OilTools oilTool = new OilTools(); for (int colIndex = FrmCurveAGlobal._dataColStart; colIndex < dataGridView.ColumnCount; colIndex++) { object xValue = dataGridView.Rows[FrmCurveAGlobal._curveRowXIndex].Cells[colIndex].Value;//取出第四行的数据 #region "数据判断" if (xValue == null) { continue; } if (xValue.ToString() == "非数字" || xValue.ToString() == "") { continue; } float temp; if (!float.TryParse(xValue.ToString(), out temp)) { continue; } if (!DataBaseBDic.Keys.Contains(temp)) { continue; } float fTempY = DataBaseBDic[temp]; if (fTempY.Equals(float.NaN)) { continue; } #endregion object obj = null; if (tempRowY.errDownLimit.HasValue && fTempY < tempRowY.errDownLimit || tempRowY.errUpLimit.HasValue && fTempY > tempRowY.errUpLimit) { obj = null; } else { obj = fTempY; } //if (obj != null) //{ // if (tempRowY.errUpLimit.HasValue && fTempY > tempRowY.errUpLimit) // { // obj = null; // } // else // { // obj = fTempY; // } //} //string strTemp = oilTool.calDataDecLimit(fTempY.ToString(), tempRowY.decNumber, tempRowY.valDigital); //dataGridView.Rows[FrmCurveAGlobal._curveRowYIndex].Cells[colIndex].Value = strTemp; //dataGridView.Rows[FrmCurveAGlobal._curveRowYIndex].Cells[colIndex].Tag = fTempY; //dataGridView.Rows[FrmCurveAGlobal._curveRowYIndex].Cells[colIndex].Value = fTempY; dataGridView.Rows[FrmCurveAGlobal._curveRowYIndex].Cells[colIndex].Tag = obj; dataGridView.Rows[FrmCurveAGlobal._curveRowYIndex].Cells[colIndex].Value = obj; } }