示例#1
0
        private void menuPasteItem_Click(object sender, RoutedEventArgs e)
        {
            int pos = dgvCalc.SelectedIndex;

            if (copiedItems.Count > 0 && pos > -1)
            {
                foreach (HeadLossCalc hlc in copiedItems)
                {
                    HeadLossCalc newItem = (HeadLossCalc)hlc.Clone();
                    newItem.Node1 = new Node();
                    newItem.Node2 = new Node();
                    lstHeadLossCalcs.Insert(++pos, newItem);
                }
            }
        }
示例#2
0
        private void DgvCalc_SelectionChanged(object sender, Xceed.Wpf.DataGrid.DataGridSelectionChangedEventArgs e)
        {
            HeadLossCalc selectedItem = (HeadLossCalc)e.SelectionInfos[0].DataGridContext.CurrentItem;

            if (selectedItem != null)
            {
                double totalHl   = 0;
                double totalV    = 0;
                double totalL    = 0;
                var    selection = dgvCalc.SelectedItems;
                foreach (HeadLossCalc hlc in selection)
                {
                    totalL  = totalL + hlc.L;
                    totalV  = totalV + hlc.Vm;
                    totalHl = totalHl + hlc.hLm;
                }
                tbL.Text    = totalL.ToString("N3");
                tbV.Text    = totalV.ToString("N3");
                tbHlmm.Text = totalHl.ToString("N2");
            }
        }
示例#3
0
        private void menuImport_Click(object sender, RoutedEventArgs e)
        {
            //Local Variables
            List <string> lstLines      = new List <string>();
            List <string> selectedLines = new List <string>();

            string[] Headers = new string[] { "WELD", "PIPE", "FLANGE", "GASKET", "END-CONNECTION-PIPELINE", "VALVE", "INDUCTION-START", "BEND", "INDUCTION-END", "MESSAGE-ROUND", "REDUCER-CONCENTRIC" };

            Double.TryParse(txtTemp.Text, out double t);
            Double.TryParse(txte.Text, out double ep);
            Double.TryParse(txtQ.Text, out double q);
            double temperature = t;
            double epsilon     = ep;
            double qh          = q;

            //Open File
            OpenFileDialog _openFileDialog = new OpenFileDialog();

            if (_openFileDialog.ShowDialog() == true)
            {
                using (Stream _fileStream = new FileStream(_openFileDialog.FileName, FileMode.Open, FileAccess.Read, FileShare.None))
                {
                    string txt = "";
                    using (var streamReader = new StreamReader(_fileStream, Encoding.UTF8, true, 128))
                    {
                        String line;
                        int    n = 0;
                        while ((line = streamReader.ReadLine()) != null)
                        {
                            lstLines.Add(line);
                            n   = ++n;
                            txt = txt + (n + "... " + line + "\n");
                        }
                        txtPCF.Text = txt;
                    }
                }
            }

            //Search for Items
            for (int i = 0; i < lstLines.Count - 1; i++)
            {
                if (lstLines[i] == "PIPE")
                {
                    selectedLines.Add(lstLines[i]);

                    HeadLossCalc pd = new HeadLossCalc(i + 1);
                    pd.ElementType = ItemType.Pipe;
                    pd.t           = temperature;
                    pd.epsilon     = epsilon;
                    pd.qh          = qh;

                    int  c = 1;
                    bool endConditionFound = false;

                    string        str = "";
                    List <string> p1  = new List <string>();
                    List <string> p2  = new List <string>();
                    List <string> w0  = new List <string>();

                    do
                    {
                        if ((i + c) > lstLines.Count - 1)
                        {
                            break;
                        }
                        str = lstLines[i + c].Split(' ').ToList <string>().Where(s => !string.IsNullOrWhiteSpace(s)).Distinct().ToList().First();

                        if (str == "END-POINT")
                        {
                            selectedLines.Add(lstLines[i + c]);
                            p1 = lstLines[i + c].Split(' ').ToList <string>().Where(s => !string.IsNullOrWhiteSpace(s)).Distinct().ToList();
                            selectedLines.Add(lstLines[i + c + 1]);
                            p2         = lstLines[i + c + 1].Split(' ').ToList <string>().Where(s => !string.IsNullOrWhiteSpace(s)).Distinct().ToList();
                            i          = i + 2;
                            pd.Node1.X = Double.Parse(p1[1]);
                            pd.Node1.Y = Double.Parse(p1[2]);
                            pd.Node1.Z = Double.Parse(p1[3]);
                            pd.Node2.X = Double.Parse(p2[1]);
                            pd.Node2.Y = Double.Parse(p2[2]);
                            pd.Node2.Z = Double.Parse(p2[3]);
                            pd.d       = Double.Parse(p1[4]);
                            pd.L       = pd.Distance(pd.Node1.X, pd.Node2.X, pd.Node1.Y, pd.Node2.Y, pd.Node1.Z, pd.Node2.Z) / 1000;
                        }

                        if (str == "WEIGHT")
                        {
                            w0   = lstLines[i + c].Split(' ').ToList <string>().Where(s => !string.IsNullOrWhiteSpace(s)).Distinct().ToList();
                            pd.W = Double.Parse(w0[1]) * pd.L;
                        }

                        if (Headers.Contains(str))
                        {
                            endConditionFound = true;
                        }

                        c++;
                    } while (!endConditionFound);

                    lstHeadLossCalcs.Add(pd);
                }

                if (lstLines[i] == "REDUCER-CONCENTRIC")
                {
                    selectedLines.Add(lstLines[i]);

                    HeadLossCalc pd = new HeadLossCalc(i + 1);
                    pd.t       = temperature;
                    pd.epsilon = epsilon;
                    pd.qh      = qh;

                    int  c = 1;
                    bool endConditionFound = false;

                    string        str = "";
                    double        d1  = 0;
                    double        d2  = 0;
                    List <string> p1  = new List <string>();
                    List <string> p2  = new List <string>();
                    List <string> w0  = new List <string>();

                    do
                    {
                        if ((i + c) > lstLines.Count - 1)
                        {
                            break;
                        }
                        str = lstLines[i + c].Split(' ').ToList <string>().Where(s => !string.IsNullOrWhiteSpace(s)).Distinct().ToList().First();

                        if (str == "END-POINT")
                        {
                            selectedLines.Add(lstLines[i + c]);
                            p1 = lstLines[i + c].Split(' ').ToList <string>().Where(s => !string.IsNullOrWhiteSpace(s)).Distinct().ToList();
                            selectedLines.Add(lstLines[i + c + 1]);
                            p2         = lstLines[i + c + 1].Split(' ').ToList <string>().Where(s => !string.IsNullOrWhiteSpace(s)).Distinct().ToList();
                            i          = i + 2;
                            pd.Node1.X = Double.Parse(p1[1]);
                            pd.Node1.Y = Double.Parse(p1[2]);
                            pd.Node1.Z = Double.Parse(p1[3]);
                            pd.Node2.X = Double.Parse(p2[1]);
                            pd.Node2.Y = Double.Parse(p2[2]);
                            pd.Node2.Z = Double.Parse(p2[3]);
                            pd.d       = Double.Parse(p1[4]);
                            d1         = Double.Parse(p1[4]);
                            d2         = Double.Parse(p2[4]);
                            pd.L       = pd.Distance(pd.Node1.X, pd.Node2.X, pd.Node1.Y, pd.Node2.Y, pd.Node1.Z, pd.Node2.Z) / 1000;

                            if (d1 < d2)
                            {
                                pd.ElementType = ItemType.Expander;
                                pd.d           = Double.Parse(p1[4]);
                                pd.d1          = d1;
                                pd.d2          = d2;
                            }
                            else
                            {
                                pd.ElementType = ItemType.Reducer;
                                pd.d           = Double.Parse(p1[4]);
                                pd.d1          = d2;
                                pd.d2          = d1;
                            }
                        }

                        if (str == "WEIGHT")
                        {
                            w0   = lstLines[i + c].Split(' ').ToList <string>().Where(s => !string.IsNullOrWhiteSpace(s)).Distinct().ToList();
                            pd.W = Double.Parse(w0[1]) * pd.L;
                        }


                        if (Headers.Contains(str))
                        {
                            endConditionFound = true;
                        }

                        c++;
                    } while (!endConditionFound);

                    lstHeadLossCalcs.Add(pd);
                }

                if (lstLines[i] == "BEND")
                {
                    selectedLines.Add(lstLines[i]);

                    HeadLossCalc pd = new HeadLossCalc(i + 1);
                    pd.ElementType = ItemType.Bend;
                    pd.t           = temperature;
                    pd.epsilon     = epsilon;
                    pd.qh          = qh;

                    int  c = 1;
                    bool endConditionFound = false;

                    string        str = "";
                    List <string> p1  = new List <string>();
                    List <string> p2  = new List <string>();
                    List <string> c1  = new List <string>();
                    List <string> a0  = new List <string>();
                    List <string> r0  = new List <string>();
                    List <string> w0  = new List <string>();
                    double        a   = 0;
                    double        r   = 0;

                    do
                    {
                        if ((i + c) > lstLines.Count - 1)
                        {
                            break;
                        }
                        str = lstLines[i + c].Split(' ').ToList <string>().Where(s => !string.IsNullOrWhiteSpace(s)).Distinct().ToList().First();

                        if (str == "END-POINT")
                        {
                            selectedLines.Add(lstLines[i + c]);
                            p1 = lstLines[i + c].Split(' ').ToList <string>().Where(s => !string.IsNullOrWhiteSpace(s)).Distinct().ToList();
                            selectedLines.Add(lstLines[i + c + 1]);
                            p2         = lstLines[i + c + 1].Split(' ').ToList <string>().Where(s => !string.IsNullOrWhiteSpace(s)).Distinct().ToList();
                            i          = i + 2;
                            pd.Node1.X = Double.Parse(p1[1]);
                            pd.Node1.Y = Double.Parse(p1[2]);
                            pd.Node1.Z = Double.Parse(p1[3]);
                            pd.Node2.X = Double.Parse(p2[1]);
                            pd.Node2.Y = Double.Parse(p2[2]);
                            pd.Node2.Z = Double.Parse(p2[3]);
                            pd.d       = Double.Parse(p1[4]);
                        }

                        if (str == "ANGLE")
                        {
                            selectedLines.Add(lstLines[i + c]);
                            a0   = lstLines[i + c].Split(' ').ToList <string>().Where(s => !string.IsNullOrWhiteSpace(s)).Distinct().ToList();
                            a    = Double.Parse(a0[1]);
                            pd.n = (a / 100) / 90;
                        }

                        if (str == "BEND-RADIUS")
                        {
                            selectedLines.Add(lstLines[i + c]);
                            r0   = lstLines[i + c].Split(' ').ToList <string>().Where(s => !string.IsNullOrWhiteSpace(s)).Distinct().ToList();
                            r    = Double.Parse(r0[1]);
                            pd.r = r;
                            pd.L = (r / 1000) * (Math.PI * (a / 100) / 180);
                        }

                        if (str == "WEIGHT")
                        {
                            w0   = lstLines[i + c].Split(' ').ToList <string>().Where(s => !string.IsNullOrWhiteSpace(s)).Distinct().ToList();
                            pd.W = Double.Parse(w0[1]) * pd.L;
                        }

                        if (Headers.Contains(str))
                        {
                            endConditionFound = true;
                        }

                        c++;
                    } while (!endConditionFound);

                    lstHeadLossCalcs.Add(pd);
                }

                if (lstLines[i] == "VALVE")
                {
                    selectedLines.Add(lstLines[i]);

                    HeadLossCalc pd = new HeadLossCalc(i + 1);
                    pd.ElementType = ItemType.Butterfly;
                    pd.t           = temperature;
                    pd.epsilon     = epsilon;
                    pd.qh          = qh;

                    int  c = 1;
                    bool endConditionFound = false;

                    string        str = "";
                    List <string> p1  = new List <string>();
                    List <string> p2  = new List <string>();
                    List <string> w0  = new List <string>();

                    do
                    {
                        if ((i + c) > lstLines.Count - 1)
                        {
                            break;
                        }
                        str = lstLines[i + c].Split(' ').ToList <string>().Where(s => !string.IsNullOrWhiteSpace(s)).Distinct().ToList().First();

                        if (str == "END-POINT")
                        {
                            selectedLines.Add(lstLines[i + c]);
                            p1 = lstLines[i + c].Split(' ').ToList <string>().Where(s => !string.IsNullOrWhiteSpace(s)).Distinct().ToList();
                            selectedLines.Add(lstLines[i + c + 1]);
                            p2         = lstLines[i + c + 1].Split(' ').ToList <string>().Where(s => !string.IsNullOrWhiteSpace(s)).Distinct().ToList();
                            i          = i + 2;
                            pd.Node1.X = Double.Parse(p1[1]);
                            pd.Node1.Y = Double.Parse(p1[2]);
                            pd.Node1.Z = Double.Parse(p1[3]);
                            pd.Node2.X = Double.Parse(p2[1]);
                            pd.Node2.Y = Double.Parse(p2[2]);
                            pd.Node2.Z = Double.Parse(p2[3]);
                            pd.d       = Double.Parse(p1[4]);
                            pd.L       = pd.Distance(pd.Node1.X, pd.Node2.X, pd.Node1.Y, pd.Node2.Y, pd.Node1.Z, pd.Node2.Z) / 1000;
                        }

                        if (str == "WEIGHT")
                        {
                            w0   = lstLines[i + c].Split(' ').ToList <string>().Where(s => !string.IsNullOrWhiteSpace(s)).Distinct().ToList();
                            pd.W = Double.Parse(w0[1]);
                        }

                        if (Headers.Contains(str))
                        {
                            endConditionFound = true;
                        }

                        c++;
                    } while (!endConditionFound);

                    lstHeadLossCalcs.Add(pd);
                }
            }

            //Draw Model
            Draw();
        }