猿问

如何有效的缩短此语句

using System;
using System.IO;
using System.Text;

namespace ConsoleApplication1
{
class Program
{
private static string code1 = "";
private static string code2 = "";
private static string code3 = "";
private static string code4 = "";
private static int ge2 = 65;
private static int ge3 = 65;
private static int ge4 = 65;
private static int ge5 = 65;
private static int shi2 = 65;
private static int shi3 = 65;
private static int shi4 = 65;
private static int shi5 = 65;
private static int bai2 = 65;
private static int bai3 = 65;
private static int bai4 = 65;
private static int bai5 = 65;
static void Main(string[] args)
{

const string aname = "A";
const string bname = "B";
const string cname = "C";
const string dname = "D";
exitPoint:
Console.WriteLine("\n请输入您需要的code的选项!\nA:医院code,B:药店code,C:经销商code,D:其它code");
string name;
name = Console.ReadLine();
switch (name.ToUpper())
{
case aname:
{
qk1();
goto exitPoint;
}
case bname:
{
qk2();
goto exitPoint;
}
case cname:
{
qk3();
goto exitPoint;
}
case dname:
{
qk4();
goto exitPoint;
}
default:
Console.WriteLine("输入错误,请重新输入!");
goto exitPoint;
}
}

private static void qk4()
{
TXTcls txt = new TXTcls();
StringBuilder temp = new StringBuilder();
txt.ReadConfig("D", "D", "", temp, 255, ".\\TestFile.ini");

if (temp.Length != 0)
{
ge5 = Convert.ToInt32(temp[3]);
shi5 = Convert.ToInt32(temp[2]);
bai5 = Convert.ToInt32(temp[1]);
ge5++;
}
if (ge5 == 91)
{
shi5++;
ge5 = 65;
}
if (shi5 == 91)
{
bai5++;
shi5 = 65;
}
char ge1 = Convert.ToChar(ge5);
char shi1 = Convert.ToChar(shi5);
char bai1 = Convert.ToChar(bai5);
string code = "Z" + bai1 + shi1 + ge1;
txt.Writeconfig("D", "D", code, ".\\TestFile.ini");
code4 = code;
Console.WriteLine("{0}", code4);
}

private static void qk3()
{
TXTcls txt = new TXTcls();
StringBuilder temp = new StringBuilder();
txt.ReadConfig("C", "C", "", temp, 255, ".\\TestFile.ini");

if (temp.Length != 0)
{
ge4 = Convert.ToInt32(temp[3]);
shi4 = Convert.ToInt32(temp[2]);
bai4 = Convert.ToInt32(temp[1]);
ge4++;
}
if (ge4 == 91)
{
shi4++;
ge4 = 65;
}
if (shi4 == 91)
{
bai4++;
shi4 = 65;
}
char ge1 = Convert.ToChar(ge4);
char shi1 = Convert.ToChar(shi4);
char bai1 = Convert.ToChar(bai4);
string code = "V" + bai1 + shi1 + ge1;
txt.Writeconfig("C", "C", code, ".\\TestFile.ini");
code3 = code;
Console.WriteLine("{0}", code3);
}

private static void qk2()
{
TXTcls txt = new TXTcls();
StringBuilder temp = new StringBuilder();
txt.ReadConfig("B", "B", "", temp, 255, ".\\TestFile.ini");

if (temp.Length != 0)
{
ge3 = Convert.ToInt32(temp[3]);
shi3 = Convert.ToInt32(temp[2]);
bai3 = Convert.ToInt32(temp[1]);
ge3++;
}
if (ge3 == 91)
{
shi3++;
ge3 = 65;
}
if (shi3 == 91)
{
bai3++;
shi3 = 65;
}
char ge1 = Convert.ToChar(ge3);
char shi1 = Convert.ToChar(shi3);
char bai1 = Convert.ToChar(bai3);
string code = "P" + bai1 + shi1 + ge1;
txt.Writeconfig("B", "B", code, ".\\TestFile.ini");
code2 = code;
Console.WriteLine("{0}", code2);
}

private static void qk1()
{
TXTcls txt = new TXTcls();
StringBuilder temp = new StringBuilder();
txt.ReadConfig("A", "A", "", temp, 255, ".\\TestFile.ini");

if (temp.Length != 0)
{
ge2 = Convert.ToInt32(temp[3]);
shi2 = Convert.ToInt32(temp[2]);
bai2 = Convert.ToInt32(temp[1]);
ge2++;
}

if (ge2 == 91)
{
shi2++;
ge2 = 65;
}
if (shi2 == 91)
{
bai2++;
shi2 = 65;
}
char ge1 = Convert.ToChar(ge2);
char shi1 = Convert.ToChar(shi2);
char bai1 = Convert.ToChar(bai2);
string code = "A" + bai1 + shi1 + ge1;
txt.Writeconfig("A", "A", code, ".\\TestFile.ini");
code1 = code;
Console.WriteLine("{0}", code1);
}
}
}

慕斯709654
浏览 267回答 1
1回答
随时随地看视频慕课网APP
我要回答