コード例 #1
0
ファイル: FemSelect.cs プロジェクト: callme119/civil
 private void FemSelect_Load(object sender, EventArgs e)
 {
     if (this.PailieMode == 3)
     {
         this.buttonX1.Visible = true; this.textBoxX29.Visible = true; this.textBoxX30.Visible = true; this.textBoxX31.Visible = true; this.textBoxX32.Visible = true; this.textBoxX33.Visible = true;
     }
     else
     {
         this.buttonX1.Visible = false; this.textBoxX29.Visible = false; this.textBoxX30.Visible = false; this.textBoxX31.Visible = false; this.textBoxX32.Visible = false; this.textBoxX33.Visible = false;
     }
     if (this.isOneOrTwo == 0)
     {
         this.textBoxX1.Text  = "情况一组合方式";
         this.textBoxX8.Text  = A1.ToString();
         this.textBoxX9.Text  = A2.ToString();
         this.textBoxX10.Text = A3.ToString();
         this.textBoxX20.Text = B1.ToString();
         this.textBoxX21.Text = B2.ToString();
         this.textBoxX22.Text = B3.ToString();
         this.textBoxX23.Text = C1.ToString();
         this.textBoxX24.Text = C2.ToString();
         this.textBoxX25.Text = C3.ToString();
         this.textBoxX26.Text = D1.ToString();
         this.textBoxX27.Text = D2.ToString();
         this.textBoxX28.Text = D3.ToString();
     }
     else if (this.isOneOrTwo == 1)
     {
         this.textBoxX1.Text  = "情况二组合方式";
         this.textBoxX8.Text  = A1.ToString();
         this.textBoxX9.Text  = A2.ToString();
         this.textBoxX10.Text = A3.ToString();
         this.textBoxX20.Text = B1.ToString();
         this.textBoxX21.Text = B2.ToString();
         this.textBoxX22.Text = B3.ToString();
         this.textBoxX23.Text = C1.ToString();
         this.textBoxX24.Text = C2.ToString();
         this.textBoxX25.Text = C3.ToString();
         this.textBoxX26.Text = D1.ToString();
         this.textBoxX27.Text = D2.ToString();
         this.textBoxX28.Text = D3.ToString();
     }
 }
コード例 #2
0
        private void btnzn_Click(object sender, EventArgs e)
        {
            string x, y, z, ku, wu, P, I, D;
            double p, h, a, ku1, wu1, P1, I1, D1;

            x  = txtt.Text;
            y  = txth.Text;
            z  = txta.Text;
            ku = txtku.Text;
            wu = txtwu.Text;
            P  = txtP.Text;
            I  = txtI.Text;
            D  = txtD.Text;


            p = Convert.ToDouble(x);
            h = Convert.ToDouble(y);
            a = Convert.ToDouble(z);
            // ku1 = Convert.ToDouble(ku);
            // wu1 = Convert.ToDouble(wu);
            // P1 = Convert.ToDouble(P);
            // I1 = Convert.ToDouble(I);
            // D1 = Convert.ToDouble(D);

            ku1 = 4 * h / (3.1415 * a);
            wu1 = 2 * 3.1415 / p;
            P1  = ku1 / 1.7;
            I1  = 1 / (2 * wu1);
            D1  = 1 / (8 * wu1);

            txtP.Text  = P1.ToString("0.000");
            txtI.Text  = I1.ToString("0.000");
            txtD.Text  = D1.ToString("0.000");
            txtku.Text = ku1.ToString("0.000");
            txtwu.Text = wu1.ToString("0.000");
        }
コード例 #3
0
        public static bool IsAsmensKodasGood(string asmensKodas)
        {
            if (String.IsNullOrEmpty(asmensKodas))
            {
                return(false);
            }
            else
            {
                asmensKodas = WhiteSpaceRemove(asmensKodas);

                if (CheckIfForeigner(asmensKodas))
                {
                    return(true);
                }

                if (!CheckIfNumerable(asmensKodas))
                {
                    return(false);
                }

                else
                {
                    int L, Y1, Y2, M1, M2, D1, D2, X1, X2, X3, K = 0;
                    L  = int.Parse(asmensKodas[0].ToString(CultureInfo.InvariantCulture), CultureInfo.InvariantCulture);
                    Y1 = int.Parse(asmensKodas[1].ToString(CultureInfo.InvariantCulture), CultureInfo.InvariantCulture);
                    Y2 = int.Parse(asmensKodas[2].ToString(CultureInfo.InvariantCulture), CultureInfo.InvariantCulture);
                    M1 = int.Parse(asmensKodas[3].ToString(CultureInfo.InvariantCulture), CultureInfo.InvariantCulture);
                    M2 = int.Parse(asmensKodas[4].ToString(CultureInfo.InvariantCulture), CultureInfo.InvariantCulture);
                    D1 = int.Parse(asmensKodas[5].ToString(CultureInfo.InvariantCulture), CultureInfo.InvariantCulture);
                    D2 = int.Parse(asmensKodas[6].ToString(CultureInfo.InvariantCulture), CultureInfo.InvariantCulture);
                    X1 = int.Parse(asmensKodas[7].ToString(CultureInfo.InvariantCulture), CultureInfo.InvariantCulture);
                    X2 = int.Parse(asmensKodas[8].ToString(CultureInfo.InvariantCulture), CultureInfo.InvariantCulture);
                    X3 = int.Parse(asmensKodas[9].ToString(CultureInfo.InvariantCulture), CultureInfo.InvariantCulture);
                    K  = int.Parse(asmensKodas[10].ToString(CultureInfo.InvariantCulture), CultureInfo.InvariantCulture);

                    // Tikrinamas pirmas skaitmuo ar yra nuo 1 iki 6
                    if (L == 0)
                    {
                        return(false);
                    }
                    else if (L == 7)
                    {
                        return(false);
                    }
                    else if (L == 8)
                    {
                        return(false);
                    }
                    else if (L == 9)
                    {
                        return(false);
                    }

                    // Tikrina datas
                    else if (int.Parse(Y1.ToString(CultureInfo.InvariantCulture) + Y2.ToString(CultureInfo.InvariantCulture), CultureInfo.InvariantCulture) < 00 || int.Parse(Y1.ToString(CultureInfo.InvariantCulture) + Y2.ToString(CultureInfo.InvariantCulture), CultureInfo.InvariantCulture) > 99)
                    {
                        return(false);
                    }
                    else if (int.Parse(M1.ToString(CultureInfo.InvariantCulture) + M2.ToString(CultureInfo.InvariantCulture), CultureInfo.InvariantCulture) < 01 || int.Parse(M1.ToString(CultureInfo.InvariantCulture) + M2.ToString(CultureInfo.InvariantCulture), CultureInfo.InvariantCulture) > 12)
                    {
                        return(false);
                    }
                    else if (int.Parse(D1.ToString(CultureInfo.InvariantCulture) + D2.ToString(CultureInfo.InvariantCulture), CultureInfo.InvariantCulture) < 01 || int.Parse(D1.ToString(CultureInfo.InvariantCulture) + D2.ToString(CultureInfo.InvariantCulture), CultureInfo.InvariantCulture) > 31)
                    {
                        return(false);
                    }

                    // Tikrina kontroline suma
                    else
                    {
                        int S = 0, Liekana = 0;
                        S       = L * 1 + Y1 * 2 + Y2 * 3 + M1 * 4 + M2 * 5 + D1 * 6 + D2 * 7 + X1 * 8 + X2 * 9 + X3 * 1;
                        Liekana = S % 11;
                        if (Liekana != 10 && Liekana == K)
                        {
                            return(true);
                        }
                        else if (Liekana == 10)
                        {
                            S       = 0;
                            S       = L * 3 + Y1 * 4 + Y2 * 5 + M1 * 6 + M2 * 7 + D1 * 8 + D2 * 9 + X1 * 1 + X2 * 2 + X3 * 3;
                            Liekana = S % 11;
                            if (Liekana != 10 && Liekana == K)
                            {
                                return(true);
                            }
                            else if (Liekana == 10 && K == 0)
                            {
                                return(true);
                            }
                            else
                            {
                                return(false);
                            }
                        }
                        else
                        {
                            return(false);
                        }
                    }
                }
            }
        }
コード例 #4
0
        //Main function
        public void startSolve(List <String> varList, MainWindow con, bool showWarnings1)
        {
            showWarnings = showWarnings1;

            //Logging
            try
            {
                checkFileSize();
                writer = new StreamWriter(fileName, true);                  //Set true for append mode
                writeToFile("\nNew logging", DateTime.Now.ToString());
            }
            catch (Exception e1)
            {
                con.hideClipMsg();
                Debug.WriteLine(e1.ToString());
                return;
            }

            //Opening reader file
            try
            {
                reader = Properties.Resources.readerFile.ToString();
            }
            catch (Exception e2)
            {
                Debug.WriteLine(e2.ToString(), "ERROR", MessageBoxButton.OK, MessageBoxImage.Error);
                con.hideClipMsg();
                writeToFile("ERROR!", "Cannot find fileReader.txt");
                if (showWarnings)
                {
                    MessageBox.Show("Cannot find fileReader.txt", "ERROR", MessageBoxButton.OK, MessageBoxImage.Error);
                }
                return;
            }

            //Checking input and loading variables
            try
            {
                checkInput(varList, con);
            }
            catch (Exception e)
            {
                con.setResult("");
                if (showWarnings)
                {
                    MessageBox.Show("Input problem!\nProblem: " + e.Message, "ERROR", MessageBoxButton.OK, MessageBoxImage.Error);
                }
                con.hideClipMsg();
                writeToFile("ERROR!", "Input problem! MSG: " + e.ToString());

                try
                {
                    writer.Close();
                }
                catch (Exception e2)
                {
                    Debug.WriteLine(e2.ToString());
                }
                return;
            }


            //Making calculations
            try
            {
                prepare();

                makeCalculations();

                finishIt(x1, y1, z1, con);

                con.showClipMsg();
            }
            catch (Exception e)
            {
                if (showWarnings)
                {
                    MessageBox.Show("Calculation problem!", "ERROR", MessageBoxButton.OK, MessageBoxImage.Error);
                }
                con.setResult("");
                con.hideClipMsg();
                writeToFile("ERROR", "Calculation problem! " + e.ToString());
            }
            finally
            {
                try
                {
                    writer.Close();
                }
                catch (Exception e)
                {
                    Debug.WriteLine(e.ToString());
                }
            }

            void finishIt(double x, double y, double z, MainWindow con)
            {
                double s = Math.Sqrt(x * x + y * y + z * z);
                double v = Math.Sqrt(x * x + y * y);

                a = Math.Acos(z / s) * 180 / Math.PI - 90;
                b = Math.Acos(x / v) * 180 / Math.PI - 180;
                c = s - R;

                if (y < 0)
                {
                    b = -b;
                }

                a = decimal.ToDouble(decimal.Round(new decimal(a), 4, MidpointRounding.ToEven));
                b = decimal.ToDouble(decimal.Round(new decimal(b), 4, MidpointRounding.ToEven));
                c = decimal.ToDouble(decimal.Round(new decimal(c), 4, MidpointRounding.ToEven));

                writeToFile("s", s.ToString());
                writeToFile("a", a.ToString());
                writeToFile("b", b.ToString());
                writeToFile("c", c.ToString());

                String result = "::pos{" + positions[0][0] + "," + positions[0][1] + "," + a + "," + b + "," + c + "}";

                writeToFile("Final pos is", result);

                con.setResult(result);

                Clipboard.SetText(result);
            }

            void prepare()
            {
                for (int i = 0; i < FIELD_COUNT; i++)
                {
                    sValue[i] = R + positions[i][4];
                    aValue[i] = sValue[i] * Math.Sin(positions[i][2] * Math.PI / 180 + Math.PI / 2) * Math.Cos(positions[i][3] * Math.PI / 180 + Math.PI);
                    bValue[i] = sValue[i] * Math.Sin(positions[i][2] * Math.PI / 180 + Math.PI / 2) * Math.Sin(positions[i][3] * Math.PI / 180 + Math.PI);
                    cValue[i] = sValue[i] * Math.Cos(positions[i][2] * Math.PI / 180 + Math.PI / 2);
                }

                for (int i = 0; i < FIELD_COUNT; i++)
                {
                    writeToFile("A", aValue[i].ToString());
                }

                for (int i = 0; i < FIELD_COUNT; i++)
                {
                    writeToFile("B", bValue[i].ToString());
                }

                for (int i = 0; i < FIELD_COUNT; i++)
                {
                    writeToFile("C", cValue[i].ToString());
                }

                for (int i = 0; i < FIELD_COUNT; i++)
                {
                    writeToFile("S", sValue[i].ToString());
                }
            }

            void makeCalculations()
            {
                double[] deltaA = new double[3];
                double[] deltaB = new double[3];
                double[] deltaC = new double[3];
                double   p1, p2, p3;
                double   D1, D2, A1, A2, B1, B2;

                for (int i = 0; i < 3; i++)
                {
                    deltaA[i] = aValue[0] - aValue[1 + i];
                    deltaB[i] = bValue[0] - bValue[1 + i];
                    deltaC[i] = cValue[0] - cValue[1 + i];
                }

                p1 = other[0] * other[0] - aValue[0] * aValue[0] - bValue[0] * bValue[0] - cValue[0] * cValue[0] - other[1] * other[1] + aValue[1] * aValue[1] + bValue[1] * bValue[1] + cValue[1] * cValue[1];
                p2 = other[0] * other[0] - aValue[0] * aValue[0] - bValue[0] * bValue[0] - cValue[0] * cValue[0] - other[2] * other[2] + aValue[2] * aValue[2] + bValue[2] * bValue[2] + cValue[2] * cValue[2];
                p3 = other[0] * other[0] - aValue[0] * aValue[0] - bValue[0] * bValue[0] - cValue[0] * cValue[0] - other[3] * other[3] + aValue[3] * aValue[3] + bValue[3] * bValue[3] + cValue[3] * cValue[3];

                A1 = -4 * deltaA[0] * deltaC[1] + 4 * deltaA[1] * deltaC[0];
                B1 = -4 * deltaB[0] * deltaC[1] + 4 * deltaB[1] * deltaC[0];
                A2 = -4 * deltaA[0] * deltaC[2] + 4 * deltaA[2] * deltaC[0];
                B2 = -4 * deltaB[0] * deltaC[2] + 4 * deltaB[2] * deltaC[0];
                D1 = (2 * p1 * deltaC[1] - 2 * p2 * deltaC[0]);
                D2 = (2 * p1 * deltaC[2] - 2 * p3 * deltaC[0]);

                writeToFile("A1", A1.ToString());
                writeToFile("B1", B1.ToString());
                writeToFile("A2", A2.ToString());
                writeToFile("B2", B2.ToString());
                writeToFile("D1", D1.ToString());
                writeToFile("D2", D2.ToString());

                x1 = (D1 * B2 - D2 * B1) / (A1 * B2 - A2 * B1);
                y1 = (D1 - A1 * x1) / B1;
                z1 = (p1 + 2 * deltaA[0] * x1 + 2 * deltaB[0] * y1) / (-2 * deltaC[0]);

                writeToFile("x1", x1.ToString());
                writeToFile("y1", y1.ToString());
                writeToFile("z1", z1.ToString());

                //Check for bullshit
                double max = Math.Max(Math.Max(other[0], other[1]), Math.Max(other[2], other[3]));

                double min       = 1000;
                int    min_index = 0;

                for (int i = 0; i < FIELD_COUNT; i++)
                {
                    if (other[i] < min)
                    {
                        min       = other[i];
                        min_index = i;
                    }
                }

                double tmp = Math.Pow(x1 - aValue[min_index], 2) + Math.Pow(y1 - bValue[min_index], 2) + Math.Pow(z1 - cValue[min_index], 2);

                if (tmp > max * max)
                {
                    writeToFile("Bullshit check failed, sorry", "");
                    throw new Exception("BULLSHIT CHECK!");
                }
            }

            double getRValue(String value1, String value2)
            {
                List <String> list = new List <String>(reader.Split("\n"));
                String        tmp;

                /*while ((tmp = reader.ReadLine()) != null)
                 * {
                 *      list.Add(tmp);
                 * }*/

                double value = -1;

                foreach (String str in list)
                {
                    String tmpValue = str.Split("=")[1];
                    String val1     = str.Split("=")[0].Split(",")[0];
                    String val2     = str.Split("=")[0].Split(",")[1];

                    if (value1.Equals(val1) && value2.Equals(val2))
                    {
                        Double foundValue = double.Parse(tmpValue);
                        value = Math.Sqrt(foundValue / (4 * Math.PI));
                        break;
                    }
                }

                return(value);
            }

            void checkInput(List <String> varList, MainWindow con)
            {
                for (int i = 0; i < FIELD_COUNT; i++)
                {
                    positions.Add(new List <Double>());

                    String pos      = varList[i * 2];
                    String otherVar = varList[i * 2 + 1];

                    writeToFile(pos, otherVar);

                    if (string.IsNullOrEmpty(pos))
                    {
                        throw new Exception("Position " + (i + 1) + " is empty");
                    }

                    if (string.IsNullOrEmpty(otherVar))
                    {
                        throw new Exception("Ore distance " + (i + 1) + " is empty!");
                    }

                    //Get inputs from string
                    List <String> tmp = new List <String>(pos.Split("{"));

                    if (tmp.Count <= 1)
                    {
                        throw new Exception("Position " + (i + 1) + " is badly formatted!");
                    }

                    String positionsRaw = tmp[1].Split("}")[0];

                    List <String> tmpList = new List <String>(positionsRaw.Split(","));

                    //Saving values to list
                    try
                    {
                        foreach (String str in tmpList)
                        {
                            positions[i].Add(Double.Parse(str));
                        }
                    }
                    catch (Exception)
                    {
                        throw new Exception("Position " + (i + 1) + " is badly formatted!");
                    }

                    try
                    {
                        other.Add(Double.Parse(otherVar));
                    }
                    catch (Exception)
                    {
                        throw new Exception("Ore distance " + (i + 1) + " is badly formatted!");
                    }

                    //Only calculate once
                    if (i == 0)
                    {
                        //Prepping R value
                        if (reader == null)
                        {
                            throw new Exception("Reader file not found");
                        }
                        R = getRValue(tmpList[0], tmpList[1]);
                        if (R < 0)
                        {
                            R = 120000;
                            if (showWarnings)
                            {
                                MessageBox.Show("Calculations for this planet may be inaccurate!", "Warning!", MessageBoxButton.OK, MessageBoxImage.Warning);
                            }
                        }
                    }
                }

                double pos1 = positions[0][0];
                double pos2 = positions[0][1];

                for (int i = 1; i < FIELD_COUNT; i++)
                {
                    if (pos1 != positions[i][0] || pos2 != positions[i][1])
                    {
                        throw new Exception("All positions have to be on same planet!");
                    }
                }

                reorderBySmallest();
            }

            void reorderBySmallest()
            {
                for (int i = 0; i < 3; i++)
                {
                    double min      = 99999.0;
                    int    minIndex = -1;
                    for (int j = i; j < 4; j++)
                    {
                        if (other[j] < min)
                        {
                            min      = other[j];
                            minIndex = j;
                        }
                    }

                    if (minIndex < 0)
                    {
                        throw new Exception("Ore distances are too big!");
                    }

                    double tmp = other[i];
                    other[i]        = min;
                    other[minIndex] = tmp;

                    List <Double> tmpList = positions[i];
                    positions[i]        = positions[minIndex];
                    positions[minIndex] = tmpList;
                }
            }

            void checkFileSize()
            {
                FileInfo file = new FileInfo(fileName);

                if (file == null || !file.Exists)
                {
                    return;
                }

                //If log file is bigger than 20mb, we should delete it
                if (getFileSizeMegaBytes(file) > 20)
                {
                    File.Delete(fileName);
                }
            }

            double getFileSizeMegaBytes(FileInfo file)
            {
                return((double)file.Length / (1024 * 1024));
            }

            //Used for logging
            void writeToFile(String varName, String value)
            {
                try
                {
                    writer.WriteLine(varName + " " + value);
                }
                catch (Exception e)
                {
                    if (showWarnings)
                    {
                        MessageBox.Show(e.ToString());
                    }
                }
            }
        }
コード例 #5
0
        private void Calc()
        {
            double Pk, L, Ti, Tm, Gp, Tp, Var_A, Var_B, D1, k, k_Qnpp, Tmin, Tmax;
            int    n, Qz, Qnpp;

            ClearResult();

            if (kToolStripMenuItem.Checked == true)
            {
                k_Qnpp = 0.7;
            }
            else
            {
                k_Qnpp = 1;
            }

            try
            {
                Pk   = Convert.ToDouble(txtPk.Text);
                L    = Convert.ToDouble(txtL.Text);
                n    = Convert.ToInt16(txtn.Text);
                Qz   = Convert.ToInt16(txtQz.Text);
                Ti   = Convert.ToDouble(txtT1.Text);
                Qnpp = Convert.ToInt16(txtQnpp.Text);

                Qz   = Qz * 1000;
                Qnpp = Qnpp * 1000;

                Tm = Ti / 60;

                Gp = 4 * Pk * L * n;

                Tp = 3600 * Gp / Qz;

                Var_A = Qz * Tm - 60 * Gp;

                //Var_B = 0.7 * Qnpp;
                Var_B = k_Qnpp * Qnpp;

                D1 = Var_A / (Var_B * Tm) * 100;

                k = Tp / Ti;

                Tmin = (6 * 60 * Gp) / (100 * Qz / 1000 - k_Qnpp * Qnpp / 1000);
                Tmax = (6 * 60 * Gp) / (k_Qnpp * Qnpp / 1000 + 100 * Qz / 1000);


                label1.Text = label1.Text + " " + Gp.ToString("0.###") + " кг";
                label4.Text = label4.Text + " " + Tp.ToString("0.###") + " c";

                label5.Text = label5.Text + " " + Tmax.ToString("0.###") + " c";
                label7.Text = label7.Text + " " + Tmin.ToString("0.###") + " c";

                label6.Text = label6.Text + " " + k.ToString("0.###");
                label3.Text = label3.Text + " " + D1.ToString("0.##") + " %";



                if (D1 > 1 || D1 < -1)
                {
                    lblError.Visible = true;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Проверьте введенные данные!", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            // MessageBox.Show(Pk.ToString("0.##"));
        }