【C#】计算输入的任意英寸整数,得到指定区间内所有公制尺寸和对应英制尺寸

通过程序计算输入的任意英寸整数,打印出对应的区间内所有的公制(mm)尺寸与其对应的的英制尺寸

通过程序计算输入的任意英寸整数,打印出对应的区间内所有的公制(mm)尺寸与其对应的的英制尺寸,代码为方法片段

    class Program
    {
        static void Main(string[] args)
        {
            MillmeterToInch.ModeSelection();
        }
    }
       public static void ModeSelection()
        {
            Console.WriteLine("输入 \"X8\" \"X16\" \"X32\" \"X64\" 生成 1/8英寸 1/16英寸 1/32英寸 1/64英寸数据");
            string a = Console.ReadLine();
            if (a == "X8" || a == "x8")
            {
                MillmeterToInch.GetInchX8();
            }
            if (a == "X16" || a == "x16")
            {
                MillmeterToInch.GetInchX16();
            }
            if (a == "X32" || a == "x32")
            {
                MillmeterToInch.GetInchX32();
            }

            if (a == "X64" || a == "x64")
            {
                MillmeterToInch.GetInchX64();
            }
            else
            {
                Console.WriteLine("模式选择错误,请重新输入");
                ModeSelection();
            }
        }
        public static int GetValue()
        {
            Console.WriteLine("输入整数尺寸");
            string a = Console.ReadLine();
            if (a == "")
            {
                a = "0";
            }

            int b = Convert.ToInt32(a);
            if (b == 0 || b < 0)
            {
                Console.WriteLine("输入值错误,请输入尺寸");
                GetInchX64();
            }

            return b;
        }
        public static void GetInchX8()
        {
            double inch = 25.4;
            double inch1_8 = 3.175;
            string f = "f3"; //小数位数
            List<string> lists = new List<string>();
            int b = MillmeterToInch.GetValue();

            for (int i = 0; i < b; i++)
            {
                double inchs = inch * i;
                string inchsStr = inchs.ToString() + "\r\n";
                lists.Add(inchsStr);

                for (int j = 1; j < 8; j++)
                {
                    double inchs12 = inchs + inch1_8 * j;
                    if (j == 1)
                    {
                        string inch_1_8 = "1/8\"";
                        string inchsStr2 = inchs12.ToString(f) + "\r\n";
                        lists.Add(inchsStr2);
                    }

                    if (j == 2)
                    {
                        string inch_1_4 = "1/4\"";
                        string inchsStr2 = inchs12.ToString(f) + "\r\n";
                        lists.Add(inchsStr2);
                    }

                    if (j == 3)
                    {
                        string inch_3_8 = "3/8\"";
                        string inchsStr2 = inchs12.ToString(f) + "\r\n";
                        lists.Add(inchsStr2);
                    }

                    if (j == 4)
                    {
                        string inch_1_2 = "1/2\"";
                        string inchsStr2 = inchs12.ToString(f) + "\r\n";
                        lists.Add(inchsStr2);
                    }

                    if (j == 5)
                    {
                        string inch_5_8 = "5/8\"";
                        string inchsStr2 = inchs12.ToString(f) + "\r\n";
                        lists.Add(inchsStr2);
                    }

                    if (j == 6)
                    {
                        string inch_3_4 = "3/4\"";
                        string inchsStr2 = inchs12.ToString(f) + "\r\n";
                        lists.Add(inchsStr2);
                    }

                    if (j == 7)
                    {
                        string inch_7_8 = "7/8\"";
                        string inchsStr2 = inchs12.ToString(f) + "\r\n";
                        lists.Add(inchsStr2);
                    }

                    if (i > b - 2 && j > 6)
                    {
                        double s = inch * b;
                        string inchsStr2 = s.ToString(f) + "\r\n";
                        lists.Add(inchsStr2);
                    }
                }
            }

            for (int i = 0; i < b; i++)
            {
                double inchs = inch * i;
                string inchsStr = i.ToString() + "\"" + "\r\n";
                lists.Add(inchsStr);

                for (int j = 1; j < 8; j++)
                {
                    double inchs12 = inchs + inch1_8 * j;
                    if (j == 1)
                    {
                        string inch_1_8 = "1/8\"";
                        string inchsStr2 = i.ToString() + "-" + inch_1_8 + "\r\n";
                        lists.Add(inchsStr2);
                    }

                    if (j == 2)
                    {
                        string inch_1_4 = "1/4\"";
                        string inchsStr2 = i.ToString() + "-" + inch_1_4 + "\r\n";
                        lists.Add(inchsStr2);
                    }

                    if (j == 3)
                    {
                        string inch_3_8 = "3/8\"";
                        string inchsStr2 = i.ToString() + "-" + inch_3_8 + "\r\n";
                        lists.Add(inchsStr2);
                    }

                    if (j == 4)
                    {
                        string inch_1_2 = "1/2\"";
                        string inchsStr2 = i.ToString() + "-" + inch_1_2 + "\r\n";
                        lists.Add(inchsStr2);
                    }

                    if (j == 5)
                    {
                        string inch_5_8 = "5/8\"";
                        string inchsStr2 = i.ToString() + "-" + inch_5_8 + "\r\n";
                        lists.Add(inchsStr2);
                    }

                    if (j == 6)
                    {
                        string inch_3_4 = "3/4\"";
                        string inchsStr2 = i.ToString() + "-" + inch_3_4 + "\r\n";
                        lists.Add(inchsStr2);
                    }

                    if (j == 7)
                    {
                        string inch_7_8 = "7/8\"";
                        string inchsStr2 = i.ToString() + "-" + inch_7_8 + "\r\n";
                        lists.Add(inchsStr2);
                    }

                    if (i > b - 2 && j > 6)
                    {
                        double s = inch * b;
                        string inchsStr2 = b.ToString() + "\"" + "\r\n";
                        lists.Add(inchsStr2);
                    }
                }
            }


            foreach (var list in lists) //使用遍历的方式打印输出Lists数组的内容
            {
                MillmeterToInch.CreateTXTFile(list);
                Console.WriteLine(list);
            }

            Console.ReadKey();

        }
        public static void CreateTXTFile(string list)
        {
            string excelFilePath = "C:\\Users\\Nico\\Desktop\\";
            string fileName =excelFilePath + DateTime.Now.ToLongDateString() +DateTime.Now.ToLongTimeString().Replace(":", "-") + "数据输出" + ".TXT";
            FileStream dataFile = new FileStream(fileName, FileMode.Append, FileAccess.Write);
            StreamWriter writerInchInfo = new StreamWriter(dataFile);
            writerInchInfo.Write(list);
            writerInchInfo.Flush();
            writerInchInfo.Close();
        }
  • 发表于 2020-04-20 10:16
  • 阅读 ( 120 )
  • 分类:NX Open C#

你可能感兴趣的文章

相关问题

0 条评论

请先 登录 后评论
Nico
Nico

F3Dexpress工程师

44 篇文章

作家榜 »

  1. Nico 44 文章
  2. 大管家 12 文章
  3. 落雨 7 文章
  4. F3Dexpress 6 文章
  5. Eric 5 文章
  6. 里海 2 文章
  7. 851422649 0 文章
  8. 黄先生 0 文章