Esempio n. 1
0
        /// <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);
        }
Esempio n. 2
0
        /// <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);
        }
Esempio n. 3
0
 /// <summary>
 /// 保存原油信息表,并返回ID
 /// </summary>
 /// <param name="info">一条原油</param>
 /// <returns>原油ID,-1表示有重复代码,或代码为空</returns>
 public override int Save()
 {
     ReadDataFromUI();
     this._isChanged = false;
     return(OilBll.saveInfo(this._oilInfo));
 }
Esempio n. 4
0
        /// <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;
                        }
                    }
                }
            }
        }
Esempio n. 5
0
        /// <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);
            }
        }
Esempio n. 6
0
        /// <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
                    }
                }
            }
        }