public DataTable GetDataBaseTable()
        {
            string           sql           = "select * from MaterialBalance order by CreatedDate desc";
            ConnectionString conn          = new ConnectionString();
            string           connectionSql = conn.GetConnectionString().ToString();
            DataTable        dt            = SqlHelper.ExecuteQuery(connectionSql, sql).Tables[0];

            return(dt);
        }
예제 #2
0
        public DataTable GetDataBaseTable()
        {
            string           sql           = "select mainclass,subclass1,subclass2,cluster,area,station,Mech_Eqpt_no,tag_no,Instrument_Type_Description,pitag from InstFuncHierarchy where pitag is not null";// vct.Validity_Status,vct.start_date,vct.end_date,vct.formation_gas,vct.gross,vct.oil,vct.water from v_conduit_test vct inner join v_conduit vc on VCT.CONDUIT_NAME=VC.CONDUIT_NAME where VCT.SEPARATOR_ID IS NOT NULL and vct.separator_id like '%' and vct.conduit_name = 'F018' and vct.validity_status='valid test' ";
            ConnectionString conn          = new ConnectionString();
            string           connectionSql = conn.GetConnectionString().ToString();
            DataTable        dt            = SqlHelper.ExecuteQuery(connectionSql, sql).Tables[0];

            return(dt);
        }
예제 #3
0
        DataTable bindGrid()
        {
            string           sql           = "select * from InstrumentTag_PiTag where Tag_Number ='" + hdnTag.Value + "'";
            ConnectionString conn          = new ConnectionString();
            string           connectionSql = conn.GetConnectionString().ToString();

            return(SqlHelper.ExecuteQuery(connectionSql, sql).Tables[0]);
            // gvTags.DataSource = dt;
            //gvTags.DataBind();
        }
예제 #4
0
        string getPITag(string key)
        {
            string           piTag         = "";
            string           sql           = "select * from WGMPITags where Well_No ='" + deviceName + "'";
            ConnectionString conn          = new ConnectionString();
            string           connectionSql = conn.GetConnectionString().ToString();
            DataTable        dt            = SqlHelper.ExecuteQuery(connectionSql, sql).Tables[0];
            DataRow          dr            = dt.NewRow();

            if (dt.Rows.Count > 0)
            {
                switch (key)
                {
                case "gasProd":
                    dr = dt.Select("Key='DGIFLOW'").FirstOrDefault();
                    break;

                case "condProd":
                    dr = dt.Select("Key='CONDIFLOW'").FirstOrDefault();
                    break;

                case "waterProd":
                    dr = dt.Select("Key='WTRIFLOW'").FirstOrDefault();
                    break;

                case "wetGasProd":
                    dr = dt.Select("Key='WGIFLOW'").FirstOrDefault();
                    break;

                case "gasTotal":
                    dr = dt.Select("Key='DGQFLOW'").FirstOrDefault();
                    break;

                case "condTotal":
                    dr = dt.Select("Key='CONDQFLOW'").FirstOrDefault();
                    break;

                case "waterTotal":
                    dr = dt.Select("Key='WTRQFLOW'").FirstOrDefault();
                    break;

                case "wetGasTotal":
                    dr = dt.Select("Key='WGQFLOW'").FirstOrDefault();
                    break;
                }
                if (dr != null)
                {
                    piTag = dr["PI_Tag"].ToString();
                }
            }
            return(piTag);
        }
예제 #5
0
        protected void gvMaterialBalance_DeleteCommand(object sender, GridCommandEventArgs e)
        {
            GridDataItem item = e.Item as GridDataItem;
            // using columnuniquename
            //string str1 = item["Name"].Text;
            // using DataKey
            int ID = int.Parse(item.GetDataKeyValue("MaterialBalanceID").ToString());
            ConnectionString conn          = new ConnectionString();
            string           connectionSql = conn.GetConnectionString().ToString();

            SqlHelper.ExecuteNonQuery(connectionSql, "DeleteMaterialBalance", ID);
            gvMaterialBalance.Rebind();
        }
예제 #6
0
        private void bindInstruments(string DeviceName)
        {
            string           sql           = "select Tag_No from InstFuncHierarchy where Mech_Eqpt_no='" + DeviceName + "'";
            ConnectionString conn          = new ConnectionString();
            string           connectionSql = conn.GetConnectionString().ToString();
            DataTable        dt            = SqlHelper.ExecuteQuery(connectionSql, sql).Tables[0];

            ddlInstrumnet.Items.Clear();
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                ListItem item = new ListItem(dt.Rows[i]["Tag_No"].ToString(), dt.Rows[i]["Tag_No"].ToString());
                ddlInstrumnet.Items.Add(item);
            }
        }
        void fillMaterialBalance()
        {
            ConnectionString conn          = new ConnectionString();
            string           connectionSql = conn.GetConnectionString().ToString();
            DataTable        dt            = SqlHelper.ExecuteDataset(connectionSql, "GetMaterialBalance", int.Parse(Request.QueryString["MaterialBalanceID"])).Tables[0];

            if (dt.Rows.Count > 0)
            {
                hdnInput.Value  = dt.Rows[0]["InputEquation"].ToString().Replace("''", "'");  // +" + ";
                hdnOutput.Value = dt.Rows[0]["OutputEquation"].ToString().Replace("''", "'"); // +" + ";
                //txtMaterialBalanceName.Text = dt.Rows[0]["MaterialBalanceName"].ToString();
                // if (dt.Rows[0]["CreatedBy"].ToString() != Context.User.Identity.Name)
                //    btnInsertTags.Visible = false;
                CreateChartSeries(hdnInput.Value, 0);
                CreateChartSeries(hdnOutput.Value, 1);
            }
        }
예제 #8
0
        void fillMaterialBalance()
        {
            ConnectionString conn          = new ConnectionString();
            string           connectionSql = conn.GetConnectionString().ToString();
            DataTable        dt            = SqlHelper.ExecuteDataset(connectionSql, "GetMaterialBalance", int.Parse(Request.QueryString["MaterialBalanceID"])).Tables[0];

            if (dt.Rows.Count > 0)
            {
                txtInput.InnerText          = dt.Rows[0]["InputEquation"].ToString().Replace("''", "'") + " + ";
                txtOuput.InnerText          = dt.Rows[0]["OutputEquation"].ToString().Replace("''", "'") + " + ";
                txtMaterialBalanceName.Text = dt.Rows[0]["MaterialBalanceName"].ToString();
                if (dt.Rows[0]["CreatedBy"].ToString().ToLower() != Context.User.Identity.Name.ToLower())
                {
                    btnInsertTags.Visible   = false;
                    btnAddViewChart.Visible = false;
                }
            }
        }
예제 #9
0
        void XHQCall()
        {
            Solution s = null;
            List <XHQMembersForANS> list = new List <XHQMembersForANS>();
            DataTable dt = new DataTable();

            dt.Columns.Add("dEndDate", typeof(DateTime));
            dt.Columns.Add("dStartDate", typeof(DateTime));
            dt.Columns.Add("sArea", typeof(string));
            dt.Columns.Add("sCluster", typeof(string));
            dt.Columns.Add("sDirectorate", typeof(string));
            dt.Columns.Add("sInstrumentType", typeof(string));
            dt.Columns.Add("sMainClass", typeof(string));
            dt.Columns.Add("sPiTag", typeof(string));
            dt.Columns.Add("sProcessFunctionType", typeof(string));
            dt.Columns.Add("sService", typeof(string));
            dt.Columns.Add("sStation", typeof(string));
            dt.Columns.Add("sSubClass1", typeof(string));
            dt.Columns.Add("sSubClass2", typeof(string));
            dt.Columns.Add("sTagNumber", typeof(string));
            try
            {
                ConnectionString conn          = new ConnectionString();
                string           connectionSql = conn.GetConnectionString().ToString();
                DateTime         dtMaxEndDate  = new DateTime();
                dtMaxEndDate = Convert.ToDateTime(SqlHelper.ExecuteScalar(connectionSql, "GetLastExcursionDate").ToString());
                //SolQueryCriteria sqc = new SolQueryCriteria(
                s = Solution.getConnection("148.151.135.7");
                SolRoot             r          = s.getRootObject();
                ICollectionQuery    icq        = s.getGlobalCollection("::colAggregateExcursion2");
                SolQueryCriterion[] criterions = new SolQueryCriterion[] {
                    new SolQueryCriterion("dEndDate", SolQueryCriterion.GT, new
                                          VariantValue(dtMaxEndDate.ToString()))
                };
                SolQueryCriteria qc  = new SolQueryCriteria(criterions);
                SolCollectionSet set = icq.query(new string[14] {
                    "dEndDate", "dStartDate", "sInstrumentType", "sMainClass", "sSubClass1", "sSubClass2", "sProcessFunctionType", "sService", "sDirectorate", "sCluster", "sArea", "sStation", "sTagNumber", "sPiTag"
                }, null);
                set.setMaxFetchRows(20000);
                //StringBuffer buf = new StringBuffer();
                while (set.next())
                {
                    DataRow dr = dt.NewRow();
                    //XHQMembersForANS xhqmembersForANS = new XHQMembersForANS();
                    try
                    {
                        DateTime dtStart = Convert.ToDateTime(set.getTimestampValue(2).toString());
                        DateTime dtEnd   = Convert.ToDateTime(set.getTimestampValue(1).toString());
                        //string startDate = set.getStringValue(2);
                        //dr["dStartDate"] = Convert.ToDateTime(startDate);
                        //string endDate = set.getStringValue(1);
                        //dr["dEndDate"] = Convert.ToDateTime(endDate);
                        dr["dStartDate"] = dtStart;
                        dr["dEndDate"]   = dtEnd;
                    }
                    catch (System.Exception ex)
                    { }
                    dr["sInstrumentType"]      = set.getStringValue(3);
                    dr["sMainClass"]           = set.getStringValue(4);
                    dr["sSubClass1"]           = set.getStringValue(5);
                    dr["sSubClass2"]           = set.getStringValue(6);
                    dr["sProcessFunctionType"] = set.getStringValue(7);
                    dr["sService"]             = set.getStringValue(8);
                    dr["sDirectorate"]         = set.getStringValue(9);
                    dr["sCluster"]             = set.getStringValue(10);
                    dr["sArea"]      = set.getStringValue(11);
                    dr["sStation"]   = set.getStringValue(12);
                    dr["sTagNumber"] = set.getStringValue(13);
                    dr["sPiTag"]     = set.getStringValue(14);
                    dt.Rows.Add(dr);

                    /*dr["sInstrumentTag = set.getStringValue(3);
                     * float outParameter = 0;
                     * if (float.TryParse(set.getStringValue(4), out outParameter))
                     *  dr["rMeasMaxFR = set.getFloatValue(4);
                     * if (float.TryParse(set.getStringValue(5), out outParameter))
                     *  dr["rMeasMinFR = set.getFloatValue(5);
                     */
                    //dr["dStartDate = DateTime.Parse(set.getStringValue(3));
                    //dr["dEndDate = DateTime.Parse(set.getStringValue(4));
                    //list.Add(xhqmembersForANS);
                }
                string connectionString = ConfigurationSettings.AppSettings["PDOConnection"];
                using (SqlConnection destinationConnection = new SqlConnection(connectionString))
                {
                    destinationConnection.Open();
                    using (SqlBulkCopy bulkCopy = new SqlBulkCopy(destinationConnection))
                    {
                        bulkCopy.DestinationTableName = "InstrumentExcursionLog1";
                        bulkCopy.BatchSize            = 1000;
                        bulkCopy.WriteToServer(dt);
                    }
                }
                //           var queryLastNames =
                //from student in list
                //group student by student.sPiTag into newGroup
                //orderby newGroup.Key
                //select newGroup;
            }
            catch (SolException e)
            {
            }
            finally
            {
                if (s != null)
                {
                    s.disconnect();
                }
            }
            //return list.GroupBy(x => x.sPiTag).Select(y => y.First()).ToList();
        }
예제 #10
0
 void SaveData(bool viewChart)
 {
     try
     {
         ConnectionString conn          = new ConnectionString();
         string           connectionSql = conn.GetConnectionString().ToString();
         string           user          = Context.User.Identity.Name.ToString();
         string           input         = string.Empty;
         string           output        = string.Empty;
         if (!string.IsNullOrEmpty(txtInput.InnerText) && txtInput.InnerText.Length > 3 && txtInput.InnerText.Substring(txtInput.InnerText.Length - 3) == " + ")
         {
             input = txtInput.InnerText.Substring(0, txtInput.InnerText.Length - 3);
         }
         else
         {
             input = txtInput.InnerText;
         }
         if (!string.IsNullOrEmpty(txtOuput.InnerText) && txtOuput.InnerText.Length > 3 && txtOuput.InnerText.Substring(txtOuput.InnerText.Length - 3) == " + ")
         {
             output = txtOuput.InnerText.Substring(0, txtOuput.InnerText.Length - 3);
         }
         else
         {
             output = txtOuput.InnerText;
         }
         if (isExpressionValid(input) && isExpressionValid(output))
         {
             int MaterialBalanceID = 0;
             if (!string.IsNullOrEmpty(Request.QueryString["MaterialBalanceID"]))
             {
                 MaterialBalanceID = int.Parse(Request.QueryString["MaterialBalanceID"]);
             }
             else
             {
                 DataTable dt = SqlHelper.ExecuteDataset(connectionSql, "GetMaterialBalanceByName1", txtMaterialBalanceName.Text).Tables[0];
                 if (dt.Rows.Count > 0)
                 {
                     lblStatus.ForeColor = Color.Red;
                     lblStatus.Text      = "Material Balance already exists with this name.";
                     string script = string.Format("alert('{0}');", "Material Balance already exists with this name.");
                     if (this.Page != null && !this.Page.ClientScript.IsClientScriptBlockRegistered("alert"))
                     {
                         this.Page.ClientScript.RegisterClientScriptBlock(this.Page.GetType(), "alert", script, true /* addScriptTags */);
                     }
                     return;
                 }
             }
             int ID = Convert.ToInt32(SqlHelper.ExecuteScalar(connectionSql, "InsertMaterialBalance", input.Replace("'", "''"), output.Replace("'", "''"), user, txtMaterialBalanceName.Text, MaterialBalanceID));
             if (viewChart)
             {
                 Response.Redirect("MaterialBalanceChart.aspx?MaterialBalanceID=" + ID.ToString());
             }
             else
             {
                 Response.Redirect("MaterialBalance.aspx");
             }
             //lblStatus.ForeColor = Color.Black;
             //lblStatus.Text = "Data saved successfully";
         }
         else
         {
             lblStatus.ForeColor = Color.Red;
             lblStatus.Text      = "Invalid expression.";
             string script = string.Format("alert('{0}');", "Invalid Expression.");
             if (this.Page != null && !this.Page.ClientScript.IsClientScriptBlockRegistered("alert1"))
             {
                 this.Page.ClientScript.RegisterClientScriptBlock(this.Page.GetType(), "alert1", script, true /* addScriptTags */);
             }
         }
     }
     catch (Exception ex)
     {
         lblStatus.ForeColor = Color.Red;
         lblTitle.Text       = "Error in saving data. Please try again later.";
     }
 }
예제 #11
0
        private void CreateTrends(string deviceName)
        {
            DateTime startdate, enddate = new DateTime();

            startdate = DateTime.Now.AddMonths(-1);
            //startdate = DateTime.Now.AddDays(-7);
            enddate = DateTime.Now;
            string           sql           = "select * from WGMPITags where Well_No ='" + deviceName + "'";
            ConnectionString conn          = new ConnectionString();
            string           connectionSql = conn.GetConnectionString().ToString();
            DataTable        dt            = SqlHelper.ExecuteQuery(connectionSql, sql).Tables[0];

            if (dt.Rows.Count > 0)
            {
                #region instantaneous
                #region GasProd
                string  GasProdTag = "";
                DataRow drGasProd  = dt.Select("Key='DGIFLOW'").FirstOrDefault();
                if (drGasProd != null)
                {
                    GasProdTag = drGasProd["PI_Tag"].ToString();
                }
                if (!string.IsNullOrEmpty(GasProdTag))
                {
                    showPITrendInst(GasProdTag, startdate, enddate, "DGIFLOW");
                }
                #endregion
                #region ConProd
                string  ConProdTag = "";
                DataRow drConProd  = dt.Select("Key='CONDIFLOW'").FirstOrDefault();
                if (drConProd != null)
                {
                    ConProdTag = drConProd["PI_Tag"].ToString();
                }
                if (!string.IsNullOrEmpty(ConProdTag))
                {
                    showPITrendInst(ConProdTag, startdate, enddate, "CONDIFLOW");
                }
                #endregion
                #region WaterProd
                string  WaterProdTag = "";
                DataRow drWaterProd  = dt.Select("Key='WTRIFLOW'").FirstOrDefault();
                if (drWaterProd != null)
                {
                    WaterProdTag = drWaterProd["PI_Tag"].ToString();
                }
                if (!string.IsNullOrEmpty(WaterProdTag))
                {
                    showPITrendInst(WaterProdTag, startdate, enddate, "WTRIFLOW");
                }
                #endregion
                #region WetGasProd
                string  WetGasProdTag = "";
                DataRow drWetGasProd  = dt.Select("Key='WGIFLOW'").FirstOrDefault();
                if (drWetGasProd != null)
                {
                    WetGasProdTag = drWetGasProd["PI_Tag"].ToString();
                }
                if (!string.IsNullOrEmpty(WetGasProdTag))
                {
                    showPITrendInst(WetGasProdTag, startdate, enddate, "WGIFLOW");
                }
                #endregion

                #endregion
                #region totalizers
                #region GasTotal
                string  GasTotalTag = "";
                DataRow drGasTotal  = dt.Select("Key='DGQFLOW'").FirstOrDefault();
                if (drGasTotal != null)
                {
                    GasTotalTag = drGasTotal["PI_Tag"].ToString();
                }
                if (!string.IsNullOrEmpty(GasTotalTag))
                {
                    showPITrendTotal(GasTotalTag, startdate, enddate, "DGQFLOW");
                }
                #endregion
                #region ConTotal
                string  ConTotalTag = "";
                DataRow drConTotal  = dt.Select("Key='CONDQFLOW'").FirstOrDefault();
                if (drConTotal != null)
                {
                    ConTotalTag = drConTotal["PI_Tag"].ToString();
                }
                if (!string.IsNullOrEmpty(ConTotalTag))
                {
                    showPITrendTotal(ConTotalTag, startdate, enddate, "CONDQFLOW");
                }
                #endregion
                #region WaterTotal
                string  WaterTotalTag = "";
                DataRow drWaterTotal  = dt.Select("Key='WTRQFLOW'").FirstOrDefault();
                if (drWaterTotal != null)
                {
                    WaterTotalTag = drWaterTotal["PI_Tag"].ToString();
                }
                if (!string.IsNullOrEmpty(WaterTotalTag))
                {
                    showPITrendTotal(WaterTotalTag, startdate, enddate, "WTRQFLOW");
                }
                #endregion
                #region WetGasTotal
                string  WetGasTotalTag = "";
                DataRow drWetGasTotal  = dt.Select("Key='WGQFLOW'").FirstOrDefault();
                if (drWetGasTotal != null)
                {
                    WetGasTotalTag = drWetGasTotal["PI_Tag"].ToString();
                }
                if (!string.IsNullOrEmpty(WetGasTotalTag))
                {
                    showPITrendTotal(WetGasTotalTag, startdate, enddate, "WGQFLOW");
                }
                #endregion

                #endregion
            }
        }
예제 #12
0
        //private string GetOracleConnectionString()
        //{
        //    return "Data Source=ARDHDV.world;Persist Security Info=True;User ID=wh_pmms;Password=PMMS;Unicode=True";
        //}
        private void ConnectAndQuery(string tagName)
        {
            try
            {
                tagName = string.IsNullOrEmpty(tagName) ? "25-QR-2006" : tagName;
                ConnectionString conn          = new ConnectionString();
                string           connectionSql = conn.GetConnectionString().ToString();
                DataSet          ds            = SqlHelper.ExecuteDataset(connectionSql, "GetMFMDetailsByTag", tagName);
                if (ds != null && ds.Tables.Count > 0)
                {
                    DataTable dtBasicDetail = ds.Tables[0];
                    if (dtBasicDetail.Rows.Count > 0)
                    {
                        DataTable dt = SqlHelper.ExecuteDataset(connectionSql, "GetMFMPEFSByTag", dtBasicDetail.Rows[0]["MFM TAG No"].ToString()).Tables[0];
                        if (dt.Rows.Count > 0)
                        {
                            if (!string.IsNullOrEmpty(dt.Rows[0]["ZIP"].ToString()) && !string.IsNullOrEmpty(dt.Rows[0]["Folder Name"].ToString()) && !string.IsNullOrEmpty(dt.Rows[0]["PEFS NAME"].ToString()))
                            {
                                //lnkPEFS.HRef = ConfigurationSettings.AppSettings["CadViewerPath"] + "?ID=" + dt.Rows[0]["ZIP"].ToString() + "/" + dt.Rows[0]["Folder Name"].ToString() + "/" + dt.Rows[0]["Actual PEF Name"].ToString() + ".dwg";
                                lnkPEFS.HRef = ConfigurationSettings.AppSettings["CadViewerPath"] + "?ID=" + dt.Rows[0]["ZIP"].ToString() + "/" + dt.Rows[0]["Actual PEF Name"].ToString() + ".dwg";
                            }
                        }
                        txtTagNumber.Text         = dtBasicDetail.Rows[0]["PMMS_TAG_NO"].ToString();
                        txtPEFSNumber.Text        = dtBasicDetail.Rows[0]["PEFS_NO"].ToString();
                        txtClusterAndArea.Text    = dtBasicDetail.Rows[0]["Cluster"].ToString() + "/" + dtBasicDetail.Rows[0]["Area"].ToString();
                        txtYearCommissioned.Text  = dtBasicDetail.Rows[0]["MFM Commissioned"].ToString();
                        txtMaterial.Text          = dtBasicDetail.Rows[0]["Material"].ToString();
                        txtSizeAndRating.Text     = dtBasicDetail.Rows[0]["Meter Size"].ToString() + "/" + dtBasicDetail.Rows[0]["Class_Rating ANSI"].ToString();
                        txtMinAndMaxFlowRate.Text = dtBasicDetail.Rows[0]["Min Liquid_Flow_Range M3D"].ToString() + "/" + dtBasicDetail.Rows[0]["Max Liquid_Flow_Range M3D"].ToString();
                        txtMaxGVFAndWC.Text       = dtBasicDetail.Rows[0]["MAX GVF_Flow_Range PCT"].ToString() + "/" + dtBasicDetail.Rows[0]["MAX WC_Flow_Range PCT"].ToString();
                        if (ds.Tables.Count > 1)
                        {
                            if (ds.Tables[1].Rows.Count > 0)
                            {
                                string    betaRatio = ""; string throatDiameter = "";
                                DataTable dtVenturiDetails = ds.Tables[1];
                                betaRatio                 = dtVenturiDetails.Rows.Count > 1 ? dtVenturiDetails.Rows[0]["Venturi_Beta ratio"].ToString() + "/" + dtVenturiDetails.Rows[1]["Venturi_Beta ratio"].ToString() : dtVenturiDetails.Rows[0]["Venturi_Beta ratio"].ToString();
                                throatDiameter            = dtVenturiDetails.Rows.Count > 1 ? dtVenturiDetails.Rows[0]["Venturi_D mm"].ToString() + "/" + dtVenturiDetails.Rows[1]["Venturi_D mm"].ToString() : dtVenturiDetails.Rows[0]["Venturi_D mm"].ToString();
                                txtNumberOfVenturies.Text = dtBasicDetail.Rows[0]["No_Venturies"].ToString();
                                txtVentruiSize.Text       = dtBasicDetail.Rows[0]["Large _Venturi_Size"].ToString() + "/" + dtBasicDetail.Rows[0]["SmalL_Venturi_Size"].ToString();
                                txtBetaRatio.Text         = betaRatio;
                                txtThroatDiameter.Text    = throatDiameter;
                            }
                        }
                        if (ds.Tables.Count > 2)
                        {
                            if (ds.Tables[2].Rows.Count > 0)
                            {
                                DataTable dtVortex = ds.Tables[2];
                                txtVortexMake.Text     = dtVortex.Rows[0]["Make"].ToString();
                                txtVortexMaterial.Text = dtVortex.Rows[0]["Model"].ToString();
                                txtVortexRangeMax.Text = dtVortex.Rows[0]["MaxMeasure_Range(am3/d)"].ToString();
                                txtVortexRangeMin.Text = dtVortex.Rows[0]["MinMeasure_Range(am3/d)"].ToString();
                            }
                        }
                        if (ds.Tables.Count > 3)
                        {
                            if (ds.Tables[3].Rows.Count > 0)
                            {
                                DataTable dtGamma = ds.Tables[3];
                                txtGammaHalfLife.Text       = dtGamma.Rows[0]["Half_Life"].ToString();
                                txtGammaLeak100.Text        = dtGamma.Rows[0]["Leakeage_does100"].ToString();
                                txtGammaLeak5.Text          = dtGamma.Rows[0]["Leakeage_does5"].ToString();
                                txtGammaOutput.Text         = dtGamma.Rows[0]["Output"].ToString();
                                txtGammaProbe.Text          = dtGamma.Rows[0]["Probe"].ToString();
                                txtGammaSingleHalfLife.Text = dtGamma.Rows[0]["SingleHalf_Life"].ToString();
                            }
                        }
                        if (ds.Tables.Count > 4)
                        {
                            if (ds.Tables[4].Rows.Count > 0)
                            {
                                DataTable dtValve = ds.Tables[4];
                                string    make = ""; string model = ""; string failPosition = ""; string processConnection = ""; string bodyMaterial = ""; string trimMaterial = "";
                                foreach (DataRow dr in dtValve.Rows)
                                {
                                    make              += !string.IsNullOrEmpty(dr["Mold"].ToString()) ? dr["Mold"].ToString() + "/" : "";
                                    model             += !string.IsNullOrEmpty(dr["Model"].ToString()) ? dr["Model"].ToString() + "/" : "";
                                    failPosition      += !string.IsNullOrEmpty(dr["Fail_Position"].ToString()) ? dr["Fail_Position"].ToString() + "/" : "";
                                    processConnection += !string.IsNullOrEmpty(dr["Process_Connection"].ToString()) ? dr["Process_Connection"].ToString() + "/" : "";
                                    bodyMaterial      += !string.IsNullOrEmpty(dr["Body_Material"].ToString()) ? dr["Body_Material"].ToString() + "/" : "";
                                    trimMaterial      += !string.IsNullOrEmpty(dr["Trim_Material"].ToString()) ? dr["Trim_Material"].ToString() + "/" : "";
                                }
                                make                      = string.IsNullOrEmpty(make) ? make : make.Substring(0, make.Length - 1);
                                model                     = string.IsNullOrEmpty(model) ? model : model.Substring(0, model.Length - 1);
                                failPosition              = string.IsNullOrEmpty(failPosition) ? failPosition : failPosition.Substring(0, failPosition.Length - 1);
                                processConnection         = string.IsNullOrEmpty(processConnection) ? processConnection : processConnection.Substring(0, processConnection.Length - 1);
                                bodyMaterial              = string.IsNullOrEmpty(bodyMaterial) ? bodyMaterial : bodyMaterial.Substring(0, bodyMaterial.Length - 1);
                                trimMaterial              = string.IsNullOrEmpty(trimMaterial) ? trimMaterial : trimMaterial.Substring(0, trimMaterial.Length - 1);
                                txtValveMake.Text         = make;
                                txtValveModel.Text        = model;
                                txtValveFailPosition.Text = failPosition;
                                txtValveProcConn.Text     = processConnection;
                                txtValveBodyMaterial.Text = bodyMaterial;
                                txtValveTrimMaterial.Text = trimMaterial;
                            }
                        }
                        if (ds.Tables.Count > 5)
                        {
                            if (ds.Tables[5].Rows.Count > 0)
                            {
                                DataTable dtTransmitter  = ds.Tables[5];
                                DataRow[] drPressure     = dtTransmitter.Select("[Type P DP T] = 'P'");
                                DataRow[] drDiffPressure = dtTransmitter.Select("[Type P DP T] = 'DP'");
                                DataRow[] drTemperature  = dtTransmitter.Select("[Type P DP T] = 'T'");
                                if (drPressure != null)
                                {
                                    if (drPressure.Length < 2)
                                    {
                                        txtMakeP1.Text         = drPressure[0]["Make"].ToString();
                                        txtModelP1.Text        = drPressure[0]["Model"].ToString();
                                        txtMeasRangeMinP1.Text = drPressure[0]["MinMesurement Range"].ToString();
                                        txtMeasRangeMaxP1.Text = drPressure[0]["Max Mesurement_Range"].ToString();
                                        txtUnitP1.Text         = drPressure[0]["Qty"].ToString();
                                        P2.Visible             = false;
                                    }
                                    else
                                    {
                                        txtMakeP1.Text         = drPressure[0]["Make"].ToString();
                                        txtModelP1.Text        = drPressure[0]["Model"].ToString();
                                        txtMeasRangeMinP1.Text = drPressure[0]["MinMesurement Range"].ToString();
                                        txtMeasRangeMaxP1.Text = drPressure[0]["Max Mesurement_Range"].ToString();
                                        txtUnitP1.Text         = drPressure[0]["Qty"].ToString();

                                        txtMakeP2.Text         = drPressure[1]["Make"].ToString();
                                        txtModelP2.Text        = drPressure[1]["Model"].ToString();
                                        txtMeasRangeMinP2.Text = drPressure[1]["MinMesurement Range"].ToString();
                                        txtMeasRangeMaxP2.Text = drPressure[1]["Max Mesurement_Range"].ToString();
                                        txtUnitP2.Text         = drPressure[1]["Qty"].ToString();
                                    }
                                }
                                else
                                {
                                    P2.Visible = false;
                                }
                                if (drDiffPressure != null)
                                {
                                    if (drDiffPressure.Length < 2)
                                    {
                                        txtMakeDP1.Text         = drDiffPressure[0]["Make"].ToString();
                                        txtModelDP1.Text        = drDiffPressure[0]["Model"].ToString();
                                        txtMeasRangeMinDP1.Text = drDiffPressure[0]["MinMesurement Range"].ToString();
                                        txtMeasRangeMaxDP1.Text = drDiffPressure[0]["Max Mesurement_Range"].ToString();
                                        txtUnitDP1.Text         = drDiffPressure[0]["Qty"].ToString();
                                        DP2.Visible             = false;
                                    }
                                    else
                                    {
                                        txtMakeDP1.Text         = drDiffPressure[0]["Make"].ToString();
                                        txtModelDP1.Text        = drDiffPressure[0]["Model"].ToString();
                                        txtMeasRangeMinDP1.Text = drDiffPressure[0]["MinMesurement Range"].ToString();
                                        txtMeasRangeMaxDP1.Text = drDiffPressure[0]["Max Mesurement_Range"].ToString();
                                        txtUnitDP1.Text         = drDiffPressure[0]["Qty"].ToString();

                                        txtMakeDP2.Text         = drDiffPressure[1]["Make"].ToString();
                                        txtModelDP2.Text        = drDiffPressure[1]["Model"].ToString();
                                        txtMeasRangeMinDP2.Text = drDiffPressure[1]["MinMesurement Range"].ToString();
                                        txtMeasRangeMaxDP2.Text = drDiffPressure[1]["Max Mesurement_Range"].ToString();
                                        txtUnitDP2.Text         = drDiffPressure[1]["Qty"].ToString();
                                    }
                                }
                                else
                                {
                                    DP2.Visible = false;
                                }
                                if (drTemperature != null)
                                {
                                    if (drTemperature.Length < 2)
                                    {
                                        txtMakeT1.Text         = drTemperature[0]["Make"].ToString();
                                        txtModelT1.Text        = drTemperature[0]["Model"].ToString();
                                        txtMeasRangeMinT1.Text = drTemperature[0]["MinMesurement Range"].ToString();
                                        txtMeasRangeMaxT1.Text = drTemperature[0]["Max Mesurement_Range"].ToString();
                                        txtUnitT1.Text         = drTemperature[0]["Qty"].ToString();
                                        T2.Visible             = false;
                                    }
                                    else
                                    {
                                        txtMakeT1.Text         = drTemperature[0]["Make"].ToString();
                                        txtModelT1.Text        = drTemperature[0]["Model"].ToString();
                                        txtMeasRangeMinT1.Text = drTemperature[0]["MinMesurement Range"].ToString();
                                        txtMeasRangeMaxT1.Text = drTemperature[0]["Max Mesurement_Range"].ToString();
                                        txtUnitT1.Text         = drTemperature[0]["Qty"].ToString();

                                        txtMakeT2.Text         = drTemperature[1]["Make"].ToString();
                                        txtModelT2.Text        = drTemperature[1]["Model"].ToString();
                                        txtMeasRangeMinT2.Text = drTemperature[1]["MinMesurement Range"].ToString();
                                        txtMeasRangeMaxT2.Text = drTemperature[1]["Max Mesurement_Range"].ToString();
                                        txtUnitT2.Text         = drTemperature[1]["Qty"].ToString();
                                    }
                                }
                                else
                                {
                                    T2.Visible = false;
                                }
                            }
                        }
                    }
                    else
                    {
                        string script = string.Format("alert('{0}');", "No Data To Display");
                        if (this.Page != null && !this.Page.ClientScript.IsClientScriptBlockRegistered("alert"))
                        {
                            this.Page.ClientScript.RegisterClientScriptBlock(this.Page.GetType(), "alert", script, true /* addScriptTags */);
                        }
                    }
                }
                else
                {
                    string script = string.Format("alert('{0}');", "No Data To Display");
                    if (this.Page != null && !this.Page.ClientScript.IsClientScriptBlockRegistered("alert1"))
                    {
                        this.Page.ClientScript.RegisterClientScriptBlock(this.Page.GetType(), "alert1", script, true /* addScriptTags */);
                    }
                }
            }
            catch (Exception ex)
            {
                string script = string.Format("alert('{0}');", "No Data To Display");
                if (this.Page != null && !this.Page.ClientScript.IsClientScriptBlockRegistered("alert2"))
                {
                    this.Page.ClientScript.RegisterClientScriptBlock(this.Page.GetType(), "alert2", script, true /* addScriptTags */);
                }
            }
        }
예제 #13
0
        public void ShowChart()
        {
            string InstrumentTag = string.Empty;

            if (!string.IsNullOrEmpty(Request.QueryString["DeviceName"]))
            {
                InstrumentTag = ddlInstrumnet.SelectedValue;
            }
            else if (!string.IsNullOrEmpty(Request.QueryString["TagNumber"]))
            {
                InstrumentTag = Request.QueryString["TagNumber"];
            }
            else
            {
                InstrumentTag = "95-FIC-0379";
            }
            string           sql           = "select * from InstFuncHierarchy where Tag_No ='" + InstrumentTag + "'";
            ConnectionString conn          = new ConnectionString();
            string           connectionSql = conn.GetConnectionString().ToString();
            DataTable        dt            = SqlHelper.ExecuteQuery(connectionSql, sql).Tables[0];
            string           PITag         = "";

            if (dt.Rows.Count > 0)
            {
                PITag            = dt.Rows[0]["PITag"].ToString();
                txtInstType.Text = dt.Rows[0]["Service"].ToString();
                if (!string.IsNullOrEmpty(PITag))
                {
                    DateTime startdate, enddate = new DateTime();
                    if (string.IsNullOrEmpty(Request.Form["txtStartDate"]))
                    {
                        startdate = CalendarExtender1.SelectedDate.Value;
                    }
                    else
                    {
                        startdate = DateTime.Parse(Request.Form["txtStartDate"]);
                        startdate = startdate.AddHours(int.Parse(ddlHoursStart.SelectedValue));
                        startdate = startdate.AddMinutes(int.Parse(ddlMinutesStart.SelectedValue));
                    }
                    if (string.IsNullOrEmpty(Request.Form["txtEndDate"]))
                    {
                        enddate = CalendarExtender2.SelectedDate.Value;
                    }
                    else
                    {
                        enddate = DateTime.Parse(Request.Form["txtEndDate"]);
                        enddate = enddate.AddHours(int.Parse(ddlHoursEnd.SelectedValue));
                        enddate = enddate.AddMinutes(int.Parse(ddlMinutesEnd.SelectedValue));
                    }
                    string    unit   = "";
                    List <Pi> PIData = getPiData(PITag, startdate, enddate, out unit);
                    showPITrend(PITag, startdate, enddate);
                    if (PIData != null && PIData.Count > 0)
                    {
                        List <decimal>            distArray      = new List <decimal>();
                        decimal[]                 ScoreArray     = PIData.Select(x => decimal.Parse(x.value)).ToArray <decimal>();
                        decimal[]                 distinctvalues = ScoreArray.Distinct().OrderBy(x => x).ToArray();
                        Dictionary <decimal, int> seriesArray    = new Dictionary <decimal, int>();
                        //Finds distinct values and orders them in ascending order.
                        decimal min = ScoreArray.Min(); decimal max = ScoreArray.Max();
                        decimal diff    = ((max - min) / 10);
                        decimal current = min;
                        for (int i = 0; i < 10; i++)
                        {
                            distArray.Add(current);
                            decimal count        = ScoreArray.Where(x => x >= distArray[i] && x <= (distArray[i] + diff)).Count();
                            decimal countPercent = (count / ScoreArray.Count()) * 100;
                            int     value        = (int)Math.Round(distArray[i]);
                            chartFrequency.Series[0].Points.AddXY(value, (int)Math.Round(countPercent));
                            current = current + diff;
                            //chartFrequency.Series[1].Points.AddXY(value, (int)Math.Round(countPercent));
                        }
                        chartFrequency.ChartAreas[0].AxisX.Minimum = Convert.ToDouble((int)Math.Round(min));
                        chartFrequency.ChartAreas[0].AxisX.Maximum = Convert.ToDouble((int)Math.Round(max));
                        chartFrequency.ChartAreas[0].AxisX.Title   = "Value(" + unit + ")";
                        if (unit.ToLower() == "m3/d" || 1 == 1)
                        {
                            string    sqlDiameter = "select * from Instrument_Spec_Data_Stage_1 where Tag_No ='" + InstrumentTag + "'";
                            DataTable dtDiameter  = SqlHelper.ExecuteQuery(connectionSql, sqlDiameter).Tables[0];
                            string    diameter    = "";
                            if (dtDiameter.Rows.Count > 0)
                            {
                                if (!string.IsNullOrEmpty(dtDiameter.Rows[0]["Pipe Id"].ToString()))
                                {
                                    diameter = dtDiameter.Rows[0]["Pipe Id"].ToString();
                                }
                                else if (!string.IsNullOrEmpty(dtDiameter.Rows[0]["Line Size"].ToString()))
                                {
                                    diameter = dtDiameter.Rows[0]["Line Size"].ToString();
                                }
                                else if (!string.IsNullOrEmpty(dtDiameter.Rows[0]["Line Size"].ToString()))
                                {
                                    diameter = dtDiameter.Rows[0]["Line Size"].ToString();
                                }
                                double dDiameter = 0;
                                if (!string.IsNullOrEmpty(diameter) && double.TryParse(diameter, out dDiameter))
                                {
                                    List <double> velocities     = new List <double>();
                                    List <double> reynoldNumbers = new List <double>();
                                    foreach (Pi pi in PIData)
                                    {
                                        double denominator = 0;
                                        dDiameter   = dDiameter / 0.0254;
                                        denominator = (dDiameter) / 2;
                                        denominator = denominator * denominator;
                                        denominator = denominator * (3.14);
                                        double velocity = (double.Parse(pi.value) / denominator) / (24 * 60 * 60);
                                        chartVelocity.Series[0].Points.AddXY(pi.time, (int)Math.Round(velocity));
                                        velocities.Add(velocity);
                                        double density = 0; double viscosity = 0;
                                        if (string.IsNullOrEmpty(dtDiameter.Rows[0]["Viscosity Min"].ToString()) || !double.TryParse(dtDiameter.Rows[0]["Viscosity Min"].ToString(), out viscosity))
                                        {
                                            switch (dtDiameter.Rows[0]["fluid"].ToString())
                                            {
                                            case "OIL":
                                                viscosity = 5;
                                                break;

                                            case "WATER":
                                                viscosity = 1;
                                                break;

                                            case "Gas":
                                                viscosity = 0.01;
                                                break;
                                            }
                                        }
                                        else
                                        {
                                            viscosity = double.Parse(dtDiameter.Rows[0]["Viscosity Min"].ToString());
                                        }
                                        if (string.IsNullOrEmpty(dtDiameter.Rows[0]["Operating Density Norm"].ToString()) || !double.TryParse(dtDiameter.Rows[0]["Operating Density Norm"].ToString(), out density))
                                        {
                                            switch (dtDiameter.Rows[0]["fluid"].ToString())
                                            {
                                            case "OIL":
                                                density = 890;
                                                break;

                                            case "WATER":
                                                density = 1000;
                                                break;

                                            case "Gas":
                                                density = 30;
                                                break;
                                            }
                                        }
                                        else
                                        {
                                            density = double.Parse(dtDiameter.Rows[0]["Operating Density Norm"].ToString());
                                        }
                                        if (viscosity != 0)
                                        {
                                            double reynoldNumber = ((density) * (velocity) * (dDiameter)) / viscosity;
                                            chartReynoldNumber.Series[0].Points.AddXY(pi.time, (int)Math.Round(reynoldNumber));
                                            reynoldNumbers.Add(reynoldNumber);
                                        }
                                    }

                                    /* if (velocities.Count > 0)
                                     * {
                                     *   chartVelocity.ChartAreas[0].AxisY.Minimum = (int)velocities.Min()-10;
                                     *   chartVelocity.ChartAreas[0].AxisY.Maximum = (int)velocities.Max()+10;
                                     * }
                                     * if (reynoldNumbers.Count > 0)
                                     * {
                                     *   chartReynoldNumber.ChartAreas[0].AxisY.Minimum = (int)reynoldNumbers.Min()-10;
                                     *   chartReynoldNumber.ChartAreas[0].AxisY.Maximum = (int)reynoldNumbers.Max()+10;
                                     * }*/
                                }
                                else
                                {
                                    showMessage("Diameter not defined for the instrument.");
                                }
                            }
                            else
                            {
                                showMessage("Diameter not defined for the instrument.");
                            }
                        }
                        else
                        {
                            showMessage("Unit must be in m3/d.");
                        }
                    }
                    //else chartFrequency.DataSource = null;
                }
            }
        }