/// <summary> /// 保存到数据库 /// </summary> public void Save() { var data = GetAllData(); var ass = new OilDataAccess(); OilBll.updateTables2(data); }
/// <summary> /// 删除选中的原油 /// </summary> public override void delete() { if (this.gridList.CurrentRow != null) { if (MessageBox.Show("是否要删除!", "信息提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information) == DialogResult.OK) { try { int oilInfoId = int.Parse(this.gridList.CurrentRow.Cells["ID"].Value.ToString()); string frmName = this.gridList.CurrentRow.Cells["原油编号"].Value.ToString() + "A"; OilBll.delete(oilInfoId, LibraryType.LibraryA); //删除数据 this._sqlWhere = "1=1"; dgvHeader.SetMangerDataBaseAColHeader(this.gridList, false); InitGridListBind(false); FrmMain frmMain = (FrmMain)this.MdiParent; if (frmMain == null) { return; } Form from = frmMain.GetChildFrm(frmName); //关闭被删除数据的窗口 if (from != null) { from.Close(); } } catch (Exception ex) { Log.Error("数据管理" + ex); } } } }
/// <summary> /// 保存 /// </summary> private void save() { List <TargetedValueEntity> list = new List <TargetedValueEntity>(); for (int col = 5; col < this.dgvSetTargetedValue.ColumnCount; col++) { for (int row = 0; row < this.dgvSetTargetedValue.RowCount; row++) { if (dgvSetTargetedValue[col, row].Value == null) { continue; } var cellEntity = cellToEntity(dgvSetTargetedValue[col, row]); if (cellEntity == null) { continue; } list.Add(cellEntity); } } TargetedValueEntityAccess valueAccess = new TargetedValueEntityAccess(); valueAccess.Delete("OilTableTypeComparisonTableID =" + this._currentOilTableTypeComparisonTableEntity.ID); OilBll.saveTargetedValue(list); }
/// <summary> /// 鼠标双击-打开一条原油 /// </summary> public override void openOil() { int oilInfoID = this.gridList.CurrentRow != null?int.Parse(this.gridList.CurrentRow.Cells["ID"].Value.ToString()) : -1; OilInfoBEntity oil = OilBll.GetOilBByID(oilInfoID); if (oil == null) { return; } if (isOilOpening) { return; } isOilOpening = true; try { FrmMain frmMain = this.MdiParent as FrmMain; DatabaseB.FrmOilDataB child = (DatabaseB.FrmOilDataB)frmMain.GetChildFrm(oil.crudeIndex + "B"); if (child == null) { FrmOilDataB form = new FrmOilDataB(oil); form.MdiParent = frmMain; form.Show(); } else { child.Activate(); } } finally { isOilOpening = false; } }
/// <summary> /// 首先要找到原油信息表,没有原油信息表 则没必要继续下去 /// </summary> /// <param name="oilA"></param> /// <param name="ds"></param> /// <param name="oilInfoItemCode"></param> /// <returns></returns> private static OilInfoEntity findOilInfoTalbe(DataSet ds, List <string> oilInfoItemCode) { OilInfoEntity oilA = new OilInfoEntity(); #region 找到原油信息表 string itemCode = string.Empty; foreach (DataTable table in ds.Tables) { int[] firstCode = new int[2] { -1, -1 }; for (int r_num = 0; r_num < table.Rows.Count; r_num++) { for (int c_num = 0; c_num < table.Columns.Count; c_num++) { string cellContent = table.Rows[r_num][c_num].ToString(); cellContent = Units.ToDBC(cellContent);//单元格内容 if (!cellContent.Equals("CLA") && oilInfoItemCode.Contains(cellContent)) { //原油信息表 第一个代码 firstCode[0] = r_num; firstCode[1] = c_num; for (int i = firstCode[0]; i < table.Rows.Count; i++) { itemCode = table.Rows[i][firstCode[1]].ToString().Trim(); itemCode = Units.ToDBC(itemCode); string value = table.Rows[i][firstCode[1] + 1].ToString().Trim(); value = Units.ToDBC(value); OilBll.oilInfoAddItem(ref oilA, itemCode, value); } oilA.ID = OilBll.saveInfo(oilA); if (oilA.ID == -1) { return(oilA); } } if (firstCode[0] != -1) { break; } } if (firstCode[0] != -1) { break; } } if (firstCode[0] != -1) { break; } } #endregion return(oilA); }
private void button2_Click(object sender, EventArgs e) { int num = Convert.ToInt32(txbNum2.Text); int rep = Convert.ToInt32(txbRep2.Text); this.button2.Text = "Working"; this.button2.Enabled = false; ThreadStart start2 = () => { OilInfoAccess oc = new OilInfoAccess(); var oil = new OilInfoEntity() { crudeIndex = DateTime.Now.ToString("yyyyMMddHHmmssfff"), crudeName = DateTime.Now.ToString("yyyyMMddHHmmssfff") }; oil.ID = oc.Insert(oil); for (int i = 0; i < num; i++) { var item = new OilDataEntity() { calData = RIPP.Lib.Security.SecurityTool.MyEncrypt(i.ToString()), labData = i.ToString(), oilInfoID = oil.ID, oilTableColID = i, oilTableRowID = i }; oil.OilDatas.Add(item); } OilBll.saveTables(oil); this.richTextBox2.AppendText(string.Format("已经插入一条原油数据到数据库 {0}\n", DateTime.Now.ToString())); double[] r = new double[rep]; for (int k = 0; k < rep; k++) { DateTime dt = DateTime.Now; var ooo = OilBll.GetOilById(oil.ID); foreach (var d in ooo.OilDatas) { var ssss = RIPP.Lib.Security.SecurityTool.MyDecrypt(d.calData); } r[k] = (DateTime.Now - dt).TotalMilliseconds; } for (int k = 0; k < rep; k++) { this.richTextBox2.AppendText(string.Format("读取并解密 {0} 条, 第 {2} 次花费 {1} ms \n", num, r[k], k + 1)); } this.button2.Text = "Run"; this.button2.Enabled = true; this.richTextBox2.AppendText("\n"); }; this.Invoke(start2); }
/// <summary> /// 保存到快速查询库 /// </summary> private void SaveC() { DialogResult r = MessageBox.Show("是否保存数据到快速查询库!", "提示信息", MessageBoxButtons.YesNo, MessageBoxIcon.Information); if (r == DialogResult.Yes) { OilBll.SaveC(this._oilB); } }
/// <summary> /// 删除一条记录 /// </summary> public override void delete() { if (this.gridList.CurrentRow != null) { if (MessageBox.Show("是否要删除!", "信息提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information) == DialogResult.OK) { try { int oilInfoID = this.gridList.CurrentRow != null?int.Parse(this.gridList.CurrentRow.Cells["ID"].Value.ToString()) : -1; string crudeIndex = this.gridList.CurrentRow.Cells["原油编号"].Value.ToString(); string frmName = this.gridList.CurrentRow.Cells["原油编号"].Value.ToString() + "B"; OilBll.delete(oilInfoID, LibraryType.LibraryB); //删除数据 this._sqlWhere = "1=1"; dgvHeader.SetMangerDataBaseBColHeader(this.gridList, Visible); InitGridListBind(false); FrmMain frmMain = (FrmMain)this.MdiParent; if (frmMain == null) { return; } Form from = frmMain.GetChildFrm(frmName); //关闭被删除数据的窗口 if (from != null) { from.Close(); } DatabaseC.FrmOpenC openC = (DatabaseC.FrmOpenC)frmMain.GetChildFrm("FrmOpenC"); if (openC != null) { openC.refreshGridList(); } DatabaseC.FrmOilDataC child = (DatabaseC.FrmOilDataC)frmMain.GetChildFrm(crudeIndex + "C"); if (child != null) { child.Close(); } } catch (Exception ex) { Log.Error("数据管理" + ex); } } } }
/// <summary> /// 保存到数据库 /// </summary> public void Save() { try { var data = GetAllData(); OilBll.updateTables2(data); needSave = false; needSaveInfo = true; } catch (Exception ex) { Log.Error(ex.ToString()); } }
private void button2_Click(object sender, EventArgs e) { int num = Convert.ToInt32(txtNum2.Text); int rep = Convert.ToInt32(txtRep2.Text); //先搞一条原油数据 OilInfoAccess oc = new OilInfoAccess(); this.button2.Text = "Working"; this.button2.Enabled = false; ThreadStart start2 = () => { double[] r = new double[rep]; for (int k = 0; k < rep; k++) { var oil = new OilInfoEntity() { crudeIndex = DateTime.Now.ToString("yyyyMMddHHmmssfff"), crudeName = DateTime.Now.ToString("yyyyMMddHHmmssfff") }; oil.ID = oc.Insert(oil); DateTime dt = DateTime.Now; for (int i = 0; i < num; i++) { var item = new OilDataEntity() { calData = i.ToString(), labData = i.ToString(), oilInfoID = oil.ID, oilTableColID = i, oilTableRowID = i }; oil.OilDatas.Add(item); } OilBll.saveTables(oil); r[k] = (DateTime.Now - dt).TotalMilliseconds; } for (int k = 0; k < rep; k++) { this.richTextBox2.AppendText(string.Format("插入 {0} 条, 第 {2} 次花费 {1} ms \n", num, r[k], k + 1)); } this.button2.Text = "Run"; this.button2.Enabled = true; this.richTextBox2.AppendText("\n"); }; this.Invoke(start2); }
/// <summary> /// 向B库中保存A库的原油信息 /// </summary> /// <returns></returns> public int SaveInfoB(ref OilInfoBEntity oilInfoB) { ReadDataFromUI(); OilBll.InfoToInfoB(this._oilInfo, oilInfoB); oilInfoB.ID = OilBll.saveInfo(oilInfoB); if (oilInfoB.ID == -1) { OilInfoBAccess access = new OilInfoBAccess(); string sqlWhere = "crudeIndex='" + oilInfoB.crudeIndex + "'"; List <OilInfoBEntity> oilInfoBList = access.Get(sqlWhere).ToList(); oilInfoB.ID = oilInfoBList[0].ID; access.Update(oilInfoB, oilInfoB.ID.ToString()); OilDataBAccess oilDataAccess = new OilDataBAccess(); oilDataAccess.Delete("labData='' and calData='' and oilInfoID=" + oilInfoB.ID); //删除空的数据 return(oilInfoB.ID); } return(oilInfoB.ID); }
/// <summary> /// 打开选中的原油A /// </summary> public override void openOil() { int oilInfoId = this.gridList.CurrentRow != null?int.Parse(this.gridList.CurrentRow.Cells["ID"].Value.ToString()) : 0; OilInfoEntity oil = OilBll.GetOilById(oilInfoId); if (oil == null) { return; } if (isOilOpening) { return; } isOilOpening = true; try { FrmMain frmMain = this.MdiParent as FrmMain; DatabaseA.FrmOilDataA child = (DatabaseA.FrmOilDataA)frmMain.GetChildFrm(oil.crudeIndex + "A"); if (child == null) { DatabaseA.FrmOilDataA form = new DatabaseA.FrmOilDataA(oil); form.MdiParent = frmMain; form.Show(); Application.DoEvents(); } else { child.Activate(); } } finally { isOilOpening = false; } }
/// <summary> /// 关闭窗体的保存提示 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void FrmOilDataC_FormClosing(object sender, FormClosingEventArgs e) { if (IsChange()) { DialogResult r = MessageBox.Show("是否保存数据!", "提示信息", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Information); if (r == DialogResult.Yes) { this.SaveC(); if (this._isValueChange) { var oilInfoB = new OilInfoBAccess().Get(this._oilInfoID); oilInfoB.updataDate = DateTime.Now.ToString(LongDateFormat); OilBll.updateOilInfoB(oilInfoB); FrmMain frmMain = (FrmMain)this.MdiParent; FrmOpenC frmOpenC = (FrmOpenC)frmMain.GetChildFrm("frmOpenC"); if (frmOpenC != null) //如果打开原油库A的窗口存在,则更新 { frmOpenC.refreshGridList(); } this._isValueChange = false; } this._isChange = false; } else if (r == DialogResult.No) { this._isChange = false; } else if (r == DialogResult.Cancel) { e.Cancel = true; } } }
/// <summary> /// 初始化表,给表头、行头和单元格赋值 /// </summary> public void InitTable(string oilId, GridOilViewA gdvWide) { var oil = OilBll.GetOilById(oilId); InitTable(oil, gdvWide); }
void Test_Load(object sender, EventArgs e) { OilInfoEntity oil = OilBll.GetOilById("test原油1"); var dd = oil.OilDatas; }
/// <summary> /// 相似查找的确定按钮 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> public override void btnSimilarSubmit_Click(object sender, EventArgs e) { if (this.similarListView.Items.Count <= 0) { return; } try { this.StartWaiting(); this._similarSearchList = new List <OilSimilarSearchEntity>(); #region "相似查找实体集合" OilDataSearchAccess oilDataSearchAccess = new OilDataSearchAccess(); foreach (ListViewItem item in this.similarListView.Items) { OilSimilarSearchEntity similarSearch = new OilSimilarSearchEntity(); similarSearch.ItemCode = item.Tag.ToString(); similarSearch.LeftParenthesis = item.SubItems[0].Tag.ToString(); similarSearch.OilTableColID = Convert.ToInt32(item.SubItems[1].Tag.ToString()); similarSearch.OilTableRowID = Convert.ToInt32(item.SubItems[3].Tag.ToString()); similarSearch.Fvalue = Convert.ToSingle(item.SubItems[5].Tag.ToString()); similarSearch.Weight = Convert.ToSingle(item.SubItems[7].Tag.ToString()); similarSearch.RightParenthesis = item.SubItems[8].Tag.ToString(); similarSearch.FracitonName = item.SubItems[1].Text; similarSearch.ItemName = item.SubItems[3].Text; string sqlWhere = "oilTableRowID='" + similarSearch.OilTableRowID.ToString() + "'" + " and oilTableColId='" + similarSearch.OilTableColID + "'" + " and calData!=''"; List <OilDataSearchEntity> oilDataSearchEntityList = oilDataSearchAccess.Get(sqlWhere);//获取对应物性的校正值 float?MaxValue = float.MinValue, MinValue = float.MaxValue; if (oilDataSearchEntityList.Count > 0) { MaxValue = oilDataSearchEntityList.Max(o => o.fCal); MinValue = oilDataSearchEntityList.Min(o => o.fCal); MaxValue = MaxValue > similarSearch.Fvalue ? MaxValue : similarSearch.Fvalue; //如果最大值比基础值要小,则最大值取基础值 MinValue = MinValue < similarSearch.Fvalue ? MinValue : similarSearch.Fvalue; //如果最小值比基础值要大,则最小值取基础值 } if (!MaxValue.Equals(float.MinValue) && !MinValue.Equals(float.MaxValue) && MaxValue != null && MinValue != null) { similarSearch.Diff = MaxValue.Value - MinValue.Value; } else { similarSearch.Diff = 0; } if (this.similarListView.Items.Count == 1) { similarSearch.IsAnd = true; } else { similarSearch.IsAnd = item.SubItems[9].Tag.ToString() == "And" ? true : false; } this._similarSearchList.Add(similarSearch); } #endregion #region "当前显示原油的集合" List <CrudeIndexIDAEntity> currentCrudeIndexIDList = new List <CrudeIndexIDAEntity>(); foreach (DataGridViewRow row in this.gridList.Rows) { CrudeIndexIDAEntity tempCrudeIndexIDAEntity = new CrudeIndexIDAEntity(); tempCrudeIndexIDAEntity.ID = Convert.ToInt32(row.Cells["ID"].Value.ToString()); tempCrudeIndexIDAEntity.crudeIndex = row.Cells["原油编号"].Value.ToString(); tempCrudeIndexIDAEntity.crudeName = row.Cells["原油名称"].Value.ToString(); currentCrudeIndexIDList.Add(tempCrudeIndexIDAEntity); } #endregion OilBll oilBll = new OilBll(); IDictionary <string, double> CrudeIndexSumDic = oilBll.GetOilSimInfoCrudeIndex(this._similarSearchList); //从C库获取满足条件的原油编号 GetSimSearchResult(CrudeIndexSumDic, currentCrudeIndexIDList); //绑定控件 } catch (Exception ex) { Log.Error("原油B库相似查找错误:" + ex.ToString()); return; } finally { this.StopWaiting(); } }
/// <summary> /// 相似查找,返回对应的原油ID /// </summary> /// <param name="oilProperty">相似查找条件的实体集合OilSimilarSearchEntityList</param> /// <returns></returns> public IDictionary <string, double> GetOilSimInfoCrudeIndex(IList <OilSimilarSearchEntity> similarSearchEntityList) { IDictionary <string, double> crudeIndexSimDic = new Dictionary <string, double>(); #region "输入条件判断" IList <string> resultCrudeIndexList = new List <string>(); //存放满足条件的原油编号 if (similarSearchEntityList == null) //查找条件为空 { return(crudeIndexSimDic); } if (similarSearchEntityList.Count == 0)//查找条件为空 { return(crudeIndexSimDic); } #endregion #region "初始化判断条件" string sqlWhere = "select distinct(oilInfoID) from OilDataSearch"; OilDataSearchAccess oilDataSearchAccess = new OilDataSearchAccess(); List <int> oilDataSearchOilInfoIDList = oilDataSearchAccess.getId(sqlWhere); //获取OilDataSearch表中的所有oilInfoID foreach (int oilInfoBID in oilDataSearchOilInfoIDList) //从C库中查找到的原油编号 { OilInfoBEntity bEntity = OilBll.GetOilBByID(oilInfoBID); List <TempsimliarEntity> tempList = new List <TempsimliarEntity>(); if (bEntity != null) { tempSimliarDic[bEntity.crudeIndex] = tempList; } } #endregion #region "范围查找中And和or两种类型的判断的归类" IList <OilSimilarSearchEntity> searchAnd = new List <OilSimilarSearchEntity>(); //范围查找用(and条件) IList <OilSimilarSearchEntity> searchOr = new List <OilSimilarSearchEntity>(); //范围查找用(or条件) foreach (OilSimilarSearchEntity currentOilSimilarSearchEntity in similarSearchEntityList) { if (currentOilSimilarSearchEntity.IsAnd && currentOilSimilarSearchEntity.RightParenthesis.Trim() == "")//如果该条件是And,添加到searchAnd中去 { searchAnd.Add(currentOilSimilarSearchEntity); continue; } else if (!currentOilSimilarSearchEntity.IsAnd && currentOilSimilarSearchEntity.LeftParenthesis.Trim() == "(" && currentOilSimilarSearchEntity.RightParenthesis.Trim() == "")//如果该条件是Or,但不是最后一个Or,则添加到searchOr中去,暂时不进行计算 { searchOr.Add(currentOilSimilarSearchEntity); continue; } else if (!currentOilSimilarSearchEntity.IsAnd && currentOilSimilarSearchEntity.LeftParenthesis.Trim() == "" && currentOilSimilarSearchEntity.RightParenthesis.Trim() == "")//如果该条件是Or,但不是最后一个Or,则添加到searchOr中去,暂时不进行计算 { searchOr.Add(currentOilSimilarSearchEntity); continue; } else if (currentOilSimilarSearchEntity.RightParenthesis.Trim() == ")")////如果该条件是Or,且是括号中的最后一个Or,则添加到searchOr中去,并进行或的计算 { #region "Or的计算" searchOr.Add(currentOilSimilarSearchEntity); foreach (int ID in oilDataSearchOilInfoIDList)//根据ID循环每一条原油 { OilInfoBEntity infoB = OilBll.GetOilBByID(ID); if (!tempSimliarDic.Keys.Contains(infoB.crudeIndex)) { continue; } if (searchOr.Count <= 0) { continue; } TempsimliarEntity tempsimliarEntity = getDataFromOrSimilarSearchList(searchOr, ID); if (tempSimliarDic.Keys.Contains(infoB.crudeIndex)) { tempSimliarDic[infoB.crudeIndex].Add(tempsimliarEntity); } } searchOr.Clear();//该Or括号计算完后,情况OrList,用于后面的Or括号计算 continue; #endregion } } #endregion #region "处理And条件或计算的结果和And条件取交集" foreach (int oilInfoID in oilDataSearchOilInfoIDList)//根据ID循环每一条原油 { OilInfoBEntity infoB = OilBll.GetOilBByID(oilInfoID); if (!tempSimliarDic.Keys.Contains(infoB.crudeIndex)) { continue; } if (searchAnd.Count <= 0) { continue; } TempsimliarEntity tempsimliarEntity = getDataFromAndSimilarSearchList(searchAnd, oilInfoID); if (tempSimliarDic.Keys.Contains(infoB.crudeIndex)) { tempSimliarDic[infoB.crudeIndex].Add(tempsimliarEntity); } } #endregion foreach (string key in tempSimliarDic.Keys) { double sum = 0, sumWeight = 0; foreach (TempsimliarEntity tempsimliarEntity in tempSimliarDic[key]) { if (tempsimliarEntity.Match == 0 || tempsimliarEntity.Match.Equals(double.NaN)) { sum = double.NaN; sumWeight = tempsimliarEntity.Weight; } else { sum += tempsimliarEntity.Match; sumWeight += tempsimliarEntity.Weight; } } if (sumWeight != 0 && !sum.Equals(double.NaN)) { crudeIndexSimDic.Add(key, sum / sumWeight); } } return(crudeIndexSimDic); }
/// <summary> /// 范围查询-从C库查找满足条件的原油编号 /// </summary> /// <returns></returns> public static IDictionary <string, double> GetRangOilInfoCrudeIndex(IList <OilRangeSearchEntity> rangeSearchEntityList) { int count = 0; //输入条件的个数 IDictionary <string, double> crudeIndexRanDic = new Dictionary <string, double>(); //IList<string> resultCrudeIndexList = new List<string>();//存放满足条件的原油编号 #region "输入条件判断" if (rangeSearchEntityList == null)//查找条件为空 { return(crudeIndexRanDic); } if (rangeSearchEntityList.Count == 0)//查找条件为空 { return(crudeIndexRanDic); } #endregion #region "标志条件" Dictionary <string, int> oilInfoCrudeIndex_And_Result = new Dictionary <string, int>();//满足条件的原油对应值为1,不满足为0 string sqlWhere = "select distinct(oilInfoID) from OilDataSearch"; OilDataSearchAccess oilDataSearchAccess = new OilDataSearchAccess(); List <int> oilDataSearchOilInfoBIDList = oilDataSearchAccess.getId(sqlWhere); //获取OilDataSearch表中的所有oilInfoID foreach (int oilInfoBID in oilDataSearchOilInfoBIDList) //从C库中查找到的原油编号 { OilInfoBEntity bEntity = OilBll.GetOilBByID(oilInfoBID); if (bEntity != null) { oilInfoCrudeIndex_And_Result[bEntity.crudeIndex] = 0; } } #endregion #region "范围查找中And和or两种类型的判断的归类" IList <OilRangeSearchEntity> searchAnd = new List <OilRangeSearchEntity>(); //范围查找用(and条件) IList <OilRangeSearchEntity> searchOr = new List <OilRangeSearchEntity>(); //范围查找用(or条件) foreach (OilRangeSearchEntity currentOilRangeSearchEntity in rangeSearchEntityList) { if (currentOilRangeSearchEntity.IsAnd && currentOilRangeSearchEntity.RightParenthesis.Trim() == "")//如果该条件是And,添加到searchAnd中去 { searchAnd.Add(currentOilRangeSearchEntity); count++; continue; } else if (!currentOilRangeSearchEntity.IsAnd && currentOilRangeSearchEntity.RightParenthesis.Trim() != ")")//如果该条件是Or,但不是最后一个Or,则添加到searchOr中去,暂时不进行计算 { searchOr.Add(currentOilRangeSearchEntity); continue; } else if (currentOilRangeSearchEntity.RightParenthesis.Trim() == ")")////如果该条件是Or,且是括号中的最后一个Or,则添加到searchOr中去,并进行或的计算 { #region "Or的计算" searchOr.Add(currentOilRangeSearchEntity); foreach (int oilInfoBID in oilDataSearchOilInfoBIDList)//从C库中查找到的原油编号 { OilInfoBEntity infoB = OilBll.GetOilBByID(oilInfoBID); int temp = getDataFromOrRangeSearchList(searchOr, oilInfoBID); oilInfoCrudeIndex_And_Result[infoB.crudeIndex] += temp; } count++; searchOr.Clear();//该Or括号计算完后,情况OrList,用于后面的Or括号计算 continue; #endregion } } #endregion #region "处理And条件(或计算的结果和And条件取交集" foreach (int oilInfoBID in oilDataSearchOilInfoBIDList)//从C库中查找到的原油编号 { OilInfoBEntity infoB = OilBll.GetOilBByID(oilInfoBID); oilInfoCrudeIndex_And_Result[infoB.crudeIndex] += getDataFromAndRangeSearchList(searchAnd, oilInfoBID); } #endregion foreach (string key in oilInfoCrudeIndex_And_Result.Keys) { if (oilInfoCrudeIndex_And_Result[key] == count) { crudeIndexRanDic.Add(key, 0); } } searchAnd.Clear(); searchOr.Clear(); return(crudeIndexRanDic); }
/// <summary> /// 初始化表,给表头、行头和单元格赋值 /// </summary> public virtual void InitTable(string oilId, EnumTableType tableType, string dropDownTypeCode = null) { var oil = OilBll.GetOilById(oilId); InitTable(oil, tableType, dropDownTypeCode); }
/// <summary> /// 保存原油信息表,并返回ID /// </summary> /// <param name="info">一条原油</param> /// <returns>原油ID,-1表示有重复代码,或代码为空</returns> public override int Save() { ReadDataFromUI(); this._isChanged = false; return(OilBll.saveInfo(this._oilInfo)); }
/// <summary> /// 初始化表,给表头、行头和单元格赋值 /// </summary> public void InitTable(string oilId) { var oil = OilBll.GetOilById(oilId); InitTable(oil); }
/// <summary> /// B库数据导入功能 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void toolStripBtnIn_Click(object sender, EventArgs e) { this.dgvLibBIn.EndEdit(); OilInfoBAccess oilInfoBccess = new OilInfoBAccess(); //从B库进行原油查找 LibManageBll libManageBll = new LibManageBll(); //导入B库管理 string alert = "未导入的原油:"; foreach (DataGridViewRow row in this.dgvLibBIn.Rows) { if (bool.Parse(row.Cells["select"].Value.ToString()) == true) { int oilInfoId = int.Parse(row.Cells["ID"].Value.ToString()); OilInfoOut oilInfoOut = this._outLib.oilInfoOuts.Where(c => c.ID == oilInfoId).FirstOrDefault();//从库文件中获取数据 OilInfoBEntity oilInfoBEntity = new OilInfoBEntity(); libManageBll.toOilInfoEntity(ref oilInfoBEntity, oilInfoOut); //转换为OilInfoBEntity oilInfoBEntity.ID = OilBll.saveInfo(oilInfoBEntity); //将数据保存到原油应用模块 if (oilInfoBEntity.ID == -1) //原油已存在,提示是否更新数据 { DialogResult r = MessageBox.Show(oilInfoBEntity.crudeIndex + "原油已存在!是否要更新", "提示信息", MessageBoxButtons.YesNo, MessageBoxIcon.Information); if (r == DialogResult.Yes) { oilInfoBccess.Delete("crudeIndex='" + oilInfoBEntity.crudeIndex + "'"); //删除原油信息数据 oilInfoBEntity.ID = OilBll.save(oilInfoBEntity); //重新插入原油信息 libManageBll.toOilDatas(ref oilInfoBEntity, oilInfoOut, this._outLib.oilTableRows, this._outLib.oilTableCols); OilBll.saveTables(oilInfoBEntity); libManageBll.toOilDataSearchs(ref oilInfoBEntity, oilInfoOut); OilBll.saveSearchTable(oilInfoBEntity); libManageBll.toCurve(ref oilInfoBEntity, oilInfoOut.curves, _outLib.curveTypes); OilBll.saveCurves(oilInfoBEntity); if (this.ActiveMdiChild != null) { if (this.ActiveMdiChild.GetType().Name == "FrmMain")//如果打开窗体存在. { FrmMain frmMain = (FrmMain)this.ActiveMdiChild; if (frmMain != null) //如果打开原油库A的窗口存在,则更新 { frmMain.refreshGridList(); } } } MessageBox.Show(oilInfoBEntity.crudeName + "原油导入成功!"); } else { alert += oilInfoBEntity.crudeIndex + " "; MessageBox.Show(oilInfoBEntity.crudeName + "原油导入不成功!"); } } else//原油不存在 { try { libManageBll.toOilDatas(ref oilInfoBEntity, oilInfoOut, this._outLib.oilTableRows, this._outLib.oilTableCols); OilBll.saveTables(oilInfoBEntity); libManageBll.toOilDataSearchs(ref oilInfoBEntity, oilInfoOut); OilBll.saveSearchTable(oilInfoBEntity); libManageBll.toCurve(ref oilInfoBEntity, oilInfoOut.curves, _outLib.curveTypes); OilBll.saveCurves(oilInfoBEntity); if (this.ActiveMdiChild != null) { if (this.ActiveMdiChild.GetType().Name == "FrmMain")//如果打开窗体存在. { FrmMain frmMain = (FrmMain)this.ActiveMdiChild; if (frmMain != null) //如果打开原油库A的窗口存在,则更新 { frmMain.refreshGridList(); } } } MessageBox.Show(oilInfoBEntity.crudeName + "原油导入成功!"); } catch (Exception ex) { Log.Error("原油导入错误!" + ex.ToString()); MessageBox.Show(oilInfoBEntity.crudeName + "原油导入不成功!"); return; } } } } }
/// <summary> /// 即时从表格中读取数据 /// </summary> /// <param name="infoNo"></param> public void getOilInfo(ref OilInfoEntity infoNo) { ReadDataFromUI(); OilBll.InfoToInfo(this._oilInfo, infoNo); }
/// <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> /// 生成C库 /// </summary> public override void newC() { string strID = this.gridList.CurrentRow.Cells["ID"].Value.ToString(); string crudeIndex = this.gridList.CurrentRow.Cells["原油编号"].Value.ToString(); int ID = 0; if (int.TryParse(strID, out ID)) { OilDataSearchAccess dataSearchAccess = new OilDataSearchAccess(); List <OilDataSearchEntity> dataList = dataSearchAccess.Get("oilInfoID =" + ID).ToList(); if (dataList.Count > 0) { DialogResult r = MessageBox.Show("原油" + crudeIndex + "的查询库数据已经存在是否替换?", "提示信息", MessageBoxButtons.YesNo, MessageBoxIcon.Information); if (r == DialogResult.Yes) { dataSearchAccess.deleteData("Delete from OilDataSearch where oilInfoID =" + ID); OilInfoBEntity oilB = OilBll.GetOilByCrudeIndex(crudeIndex); OilInfoEntity oilA = OilBll.GetOilById(crudeIndex); if (oilA == null) { OilBll.SaveC(oilB); } else { OilBll.SaveC(oilA, oilB); } MessageBox.Show("原油" + crudeIndex + "生成查询库成功!", "提示信息", MessageBoxButtons.YesNo, MessageBoxIcon.Information); FrmMain frmMain = this.MdiParent as FrmMain; DatabaseC.FrmOilDataC child = (DatabaseC.FrmOilDataC)frmMain.GetChildFrm(crudeIndex + "C"); if (child != null) { MessageBox.Show("原油" + crudeIndex + "的数据窗体需关闭重新打开才有效!", "提示信息", MessageBoxButtons.YesNo, MessageBoxIcon.Information); } } } else { DialogResult r = MessageBox.Show("是否保存数据到快速查询库!", "提示信息", MessageBoxButtons.YesNo, MessageBoxIcon.Information); if (r == DialogResult.Yes) { dataSearchAccess.deleteData("Delete from OilDataSearch where oilInfoID =" + ID); OilInfoBEntity oilB = OilBll.GetOilByCrudeIndex(crudeIndex); OilInfoEntity oilA = OilBll.GetOilById(crudeIndex); if (oilA == null) { OilBll.SaveC(oilB); } else { OilBll.SaveC(oilA, oilB); } MessageBox.Show("原油" + crudeIndex + "生成查询库成功!", "提示信息", MessageBoxButtons.YesNo, MessageBoxIcon.Information); FrmMain frmMain = this.MdiParent as FrmMain; DatabaseC.FrmOilDataC child = (DatabaseC.FrmOilDataC)frmMain.GetChildFrm(crudeIndex + "C"); if (child != null) { MessageBox.Show("原油" + crudeIndex + "的数据窗体需关闭重新打开才有效!", "提示信息", MessageBoxButtons.YesNo, MessageBoxIcon.Information); } } } } else { MessageBox.Show("应用库无此条原油!", "警告信息", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }
public override void InitTable(string oilId, EnumTableType tableType, string dropDownTypeCode = null) { var oil = OilBll.GetOilByCrudeIndex(oilId); InitTable(oil, tableType, dropDownTypeCode); }
/// <summary> /// 范围查询中的确定按钮事件,目的进行数据范围查询 /// </summary> public override void btnRangeSubmit_Click(object sender, EventArgs e) { if (this.rangeListView.Items.Count <= 0) { return; } this._rangeSearchList = new List <OilRangeSearchEntity>(); try { this.StartWaiting(); #region "显示条件集合" foreach (ListViewItem item in this.rangeListView.Items) { OilRangeSearchEntity rangeSearch = new OilRangeSearchEntity(); rangeSearch.itemCode = item.Tag.ToString(); rangeSearch.LeftParenthesis = item.SubItems[0].Tag.ToString(); rangeSearch.OilTableColID = Convert.ToInt32(item.SubItems[1].Tag.ToString()); rangeSearch.OilTableRowID = item.SubItems[3].Tag.ToString(); rangeSearch.downLimit = item.SubItems[5].Tag.ToString(); rangeSearch.upLimit = item.SubItems[7].Tag.ToString(); rangeSearch.RightParenthesis = item.SubItems[8].Tag.ToString(); rangeSearch.FracitonName = item.SubItems[1].Text; rangeSearch.ItemName = item.SubItems[3].Text; if (this.rangeListView.Items.Count == 1) { rangeSearch.IsAnd = true; } else { rangeSearch.IsAnd = item.SubItems[9].Tag.ToString() == "And" ? true : false; } this._rangeSearchList.Add(rangeSearch); } #endregion #region "当前显示原油的集合" List <CrudeIndexIDAEntity> currentCrudeIndexIDList = new List <CrudeIndexIDAEntity>(); foreach (DataGridViewRow row in this.gridList.Rows) { CrudeIndexIDAEntity tempCrudeIndexIDAEntity = new CrudeIndexIDAEntity(); tempCrudeIndexIDAEntity.ID = Convert.ToInt32(row.Cells["ID"].Value.ToString()); tempCrudeIndexIDAEntity.crudeIndex = row.Cells["原油编号"].Value.ToString(); tempCrudeIndexIDAEntity.crudeName = row.Cells["原油名称"].Value.ToString(); currentCrudeIndexIDList.Add(tempCrudeIndexIDAEntity); } #endregion OilBll oilBll = new OilBll(); this.tempRanSumDic = oilBll.GetRangOilInfoCrudeIndex(this._rangeSearchList); //从C库获取满足条件的原油编号 GetRangeSearchResult(this.tempRanSumDic, currentCrudeIndexIDList); //绑定控件 } catch (Exception ex) { Log.Error("原油B库范围查找错误:" + ex.ToString()); return; } finally { this.StopWaiting(); } }
/// <summary> /// 导入到B库 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void toolStripBtnIn_Click(object sender, EventArgs e) { this.gridList.EndEdit(); OilInfoBAccess oilInfoAccess = new OilInfoBAccess(); LibManageBll libManageBll = new LibManageBll(); string alert = "未导入的原油:"; foreach (DataGridViewRow row in this.gridList.Rows) { if (bool.Parse(row.Cells["select"].Value.ToString()) == true) { int oilInfoId = int.Parse(row.Cells["ID"].Value.ToString()); OilInfoOut oilInfoOut = this._outLib.oilInfoOuts.Where(c => c.ID == oilInfoId).FirstOrDefault(); OilInfoBEntity oilInfoBEntity = new OilInfoBEntity(); libManageBll.toOilInfoEntity(ref oilInfoBEntity, oilInfoOut); //转换为OilInfoEntity oilInfoBEntity.ID = OilBll.saveInfo(oilInfoBEntity); if (oilInfoBEntity.ID == -1) { try { #region "原油冲突" DialogResult r = MessageBox.Show(oilInfoBEntity.crudeIndex + "原油已存在!是否要更新", "提示信息", MessageBoxButtons.YesNo, MessageBoxIcon.Information); if (r == DialogResult.Yes) { oilInfoAccess.Delete("crudeIndex='" + oilInfoBEntity.crudeIndex + "'"); //删除原油信息数据 oilInfoBEntity.ID = OilBll.save(oilInfoBEntity); //重新插入原油信息 libManageBll.toOilDatas(ref oilInfoBEntity, oilInfoOut, this._outLib.oilTableRows, this._outLib.oilTableCols); OilBll.saveTables(oilInfoBEntity); libManageBll.toCurve(ref oilInfoBEntity, oilInfoOut.curves, _outLib.curveTypes); OilBll.saveCurves(oilInfoBEntity); libManageBll.toOilDataSearchs(ref oilInfoBEntity, oilInfoOut); OilBll.saveSearchTable(oilInfoBEntity.OilDataSearchs); DatabaseB.FrmOpenB frmOpenB = (DatabaseB.FrmOpenB)GetChildFrm("frmOpenB"); if (frmOpenB != null) //如果打开原油库B的窗口存在,则更新 { frmOpenB.refreshGridList(false); } DatabaseC.FrmOpenC frmOpenC = (DatabaseC.FrmOpenC)GetChildFrm("frmOpenC"); if (frmOpenC != null) //如果打开原油库C的窗口存在,则更新 { frmOpenC.refreshGridList(); } } else { alert += oilInfoBEntity.crudeIndex + " "; } #endregion } catch (Exception ex) { Log.Error("原油导入错误!" + ex.ToString()); return; } MessageBox.Show(oilInfoBEntity.crudeName + "原油导入成功!"); } else { #region "原油无冲突" try { libManageBll.toOilDatas(ref oilInfoBEntity, oilInfoOut, this._outLib.oilTableRows, this._outLib.oilTableCols); OilBll.saveTables(oilInfoBEntity); libManageBll.toCurve(ref oilInfoBEntity, oilInfoOut.curves, _outLib.curveTypes); OilBll.saveCurves(oilInfoBEntity); libManageBll.toOilDataSearchs(ref oilInfoBEntity, oilInfoOut); OilBll.saveSearchTable(oilInfoBEntity.OilDataSearchs); DatabaseB.FrmOpenB frmOpenB = (DatabaseB.FrmOpenB)GetChildFrm("frmOpenB"); if (frmOpenB != null) //如果打开原油库A的窗口存在,则更新 { frmOpenB.refreshGridList(false); } } catch (Exception ex) { Log.Error("原油导入错误!" + ex.ToString()); return; } MessageBox.Show(oilInfoBEntity.crudeName + "原油导入成功!"); #endregion } } } }