C#表单刚做的一个小东西(货架规划图)代码即输出结果

Code:
  1. using System;   
  2. using System.Collections.Generic;   
  3. using System.ComponentModel;   
  4. using System.Data;   
  5. using System.Drawing;   
  6. using System.Linq;   
  7. using System.Text;   
  8. using System.Windows.Forms;   
  9.   
  10. namespace WindowsFormsApplication1   
  11. {   
  12.     public partial class Form2 : Form   
  13.     {   
  14.         public Form2()   
  15.         {   
  16.             InitializeComponent();   
  17.         }   
  18.   
  19.         private void button1_Click(object sender, EventArgs e)   
  20.         {   
  21.             textBox5.Visible = false;   
  22.             label1.Visible = false;   
  23.             //排号   
  24.             int line;   
  25.             //货架数,层数   
  26.             int ShelfNumber, LayerNumber;   
  27.             try  
  28.             {   
  29.                 line = Convert.ToInt32(textBox1.Text.ToString());   
  30.                 ShelfNumber = Convert.ToInt32(textBox2.Text.ToString());   
  31.                 LayerNumber = Convert.ToInt32(textBox3.Text.ToString());   
  32.                 //每个货架列数   
  33.                 int[] Number = new int[ShelfNumber];   
  34.                 string s = textBox4.Text.ToString();   
  35.                 string[] sArray = s.Split(' ');   
  36.                 int n = 0;   
  37.                 foreach (string str in sArray)   
  38.                 {   
  39.                     Number[n++] = Convert.ToInt32(str);   
  40.                 }   
  41.                 //发现异常后面的不执行   
  42.                 string title = "**卷烟厂第" + line + "排库位规划图";   
  43.   
  44.                 textBox5.Text = title;   
  45.                 textBox5.Text += "/r/n/r/n/r/n        ";   
  46.                 //输出货架号   
  47.                 for (int j = 0; j < ShelfNumber; j++)   
  48.                 {   
  49.                     for (int k = 0; k < Number[j]; k++)   
  50.                     {   
  51.                         if (Number[j] % 2 != 0)   
  52.                         {   
  53.                             if (k == (Number[j] / 2))   
  54.                             {   
  55.                                 title = "货架" + (j + 1) + "    ";   
  56.                                 textBox5.Text += title;   
  57.                             }   
  58.                             else  
  59.                             {   
  60.                                 if (Number[j] == 1)   
  61.                                 {   
  62.                                     title = "货架" + (j + 1) + "    ";   
  63.                                     textBox5.Text += title;   
  64.                                 }   
  65.                                 else  
  66.                                 {   
  67.                                     textBox5.Text += "         ";   
  68.                                 }   
  69.                             }   
  70.                         }   
  71.                         else  
  72.                         {   
  73.                             if (k == (Number[j] / 2) - 1)   
  74.                             {   
  75.                                 title = "    货架" + (j + 1) + "";   
  76.                                 textBox5.Text += title;   
  77.                             }   
  78.                             else  
  79.                             {   
  80.   
  81.                                 textBox5.Text += "         ";   
  82.                             }   
  83.                         }   
  84.   
  85.                     }   
  86.                     if (Number[j] == 0)   
  87.                     {   
  88.                         title = "货架" + (j + 1) + "    ";   
  89.                         textBox5.Text += title;   
  90.                     }   
  91.                     textBox5.Text += "        ";   
  92.                 }   
  93.                 //画一行横杠   
  94.                 textBox5.Text += "/r/n      ";   
  95.                 for (int j = 0; j < ShelfNumber; j++)   
  96.                 {   
  97.                     textBox5.Text += "__________";   
  98.                     for (int k = 0; k < Number[j] - 2; k++)   
  99.                     {   
  100.                         textBox5.Text += "_________";   
  101.                     }   
  102.                     if (Number[j] >= 2)   
  103.                     {   
  104.                         textBox5.Text += "__________      ";   
  105.                     }   
  106.                     else  
  107.                     {   
  108.                         textBox5.Text += "_      ";   
  109.                     }   
  110.                 }   
  111.                 //画5行竖线   
  112.                 for (int row = 1; row < 6; row++)   
  113.                 {   
  114.                     textBox5.Text += "/r/n      ";   
  115.                     for (int j = 0; j < ShelfNumber; j++)   
  116.                     {   
  117.                         textBox5.Text += "|         ";   
  118.                         for (int k = 0; k < Number[j] - 2; k++)   
  119.                         {   
  120.                             textBox5.Text += "         ";   
  121.                         }   
  122.                         if (Number[j] <= 1)   
  123.                         {   
  124.                             textBox5.Text += "|      ";   
  125.                         }   
  126.                         else  
  127.                         {   
  128.   
  129.                             textBox5.Text += "         |      ";   
  130.                         }   
  131.                     }   
  132.                 }   
  133.                 //画一行横杠   
  134.                 textBox5.Text += "/r/n      ";   
  135.                 for (int j = 0; j < ShelfNumber; j++)   
  136.                 {   
  137.                     textBox5.Text += "|_________";   
  138.                     for (int k = 0; k < Number[j] - 2; k++)   
  139.                     {   
  140.                         textBox5.Text += "_________";   
  141.                     }   
  142.                     if (Number[j] <= 1)   
  143.                     {   
  144.                         textBox5.Text += "|      ";   
  145.                     }   
  146.                     else  
  147.                     {   
  148.                         textBox5.Text += "_________|      ";   
  149.                     }   
  150.                 }   
  151.                 textBox5.Text += "/r/n";   
  152.                 for (int i = LayerNumber; i > 0; i--)   
  153.                 {   
  154.                     n = 1;   
  155.                     title = "第" + i + "层:";   
  156.                     textBox5.Text += title;   
  157.                     for (int j = 0; j < ShelfNumber; j++)   
  158.                     {   
  159.                         textBox5.Text += "|";   
  160.                         for (int k = 0; k < Number[j]; k++)   
  161.                         {   
  162.                             //显示货位号 例如"|05-4-01|"   
  163.                             string ss = "|" + line.ToString().PadLeft(2, '0') + "-" + i.ToString() + "-" + n.ToString().PadLeft(2, '0') + "|";   
  164.                             textBox5.Text += ss;   
  165.                             n++;   
  166.                         }   
  167.                         if (Number[j] == 0)   
  168.                         {   
  169.                             textBox5.Text += "         ";   
  170.                         }   
  171.   
  172.                         textBox5.Text += "|";   
  173.                         textBox5.Text += "      ";   
  174.                     }   
  175.                     if (i > 1)   
  176.                     {   
  177.                         textBox5.Text += "/r/n      ";   
  178.                         for (int j = 0; j < ShelfNumber; j++)   
  179.                         {   
  180.                             textBox5.Text += "|¯¯¯¯¯¯¯¯¯";   
  181.                             for (int k = 0; k < Number[j] - 2; k++)   
  182.                             {   
  183.                                 textBox5.Text += "¯¯¯¯¯¯¯¯¯";   
  184.                             }   
  185.                             if (Number[j] <= 1)   
  186.                             {   
  187.                                 textBox5.Text += "|      ";   
  188.                             }   
  189.                             else  
  190.                             {   
  191.                                 textBox5.Text += "¯¯¯¯¯¯¯¯¯|      ";   
  192.                             }   
  193.                         }   
  194.                         for (int row = 1; row < 6; row++)   
  195.                         {   
  196.                             textBox5.Text += "/r/n      ";   
  197.                             for (int j = 0; j < ShelfNumber; j++)   
  198.                             {   
  199.                                 textBox5.Text += "|         ";   
  200.                                 for (int k = 0; k < Number[j] - 2; k++)   
  201.                                 {   
  202.                                     textBox5.Text += "         ";   
  203.                                 }   
  204.                                 if (Number[j] <= 1)   
  205.                                 {   
  206.                                     textBox5.Text += "|      ";   
  207.                                 }   
  208.                                 else  
  209.                                 {   
  210.                                     textBox5.Text += "         |      ";   
  211.                                 }   
  212.                             }   
  213.                         }   
  214.                         //画一行下横线   
  215.                         textBox5.Text += "/r/n      ";   
  216.                         for (int j = 0; j < ShelfNumber; j++)   
  217.                         {   
  218.                             textBox5.Text += "|_________";   
  219.                             for (int k = 0; k < Number[j] - 2; k++)   
  220.                             {   
  221.                                 textBox5.Text += "_________";   
  222.                             }   
  223.                             if (Number[j] <= 1)   
  224.                             {   
  225.                                 textBox5.Text += "|      ";   
  226.                             }   
  227.                             else  
  228.                             {   
  229.                                 textBox5.Text += "_________|      ";   
  230.                             }   
  231.                         }   
  232.                         textBox5.Text += "/r/n";   
  233.                     }   
  234.                     else  
  235.                     {   
  236.                             textBox5.Text += "/r/n      ";   
  237.                             for (int j = 0; j < ShelfNumber; j++)   
  238.                             {   
  239.                                 textBox5.Text += "¯¯¯¯¯¯¯¯¯¯";   
  240.                                 for (int k = 0; k < Number[j] - 2; k++)   
  241.                                 {   
  242.                                     textBox5.Text += "¯¯¯¯¯¯¯¯¯";   
  243.                                 }   
  244.                                 if (Number[j] <= 1)   
  245.                                 {   
  246.                                     textBox5.Text += "¯      ";   
  247.                                 }   
  248.                                 else  
  249.                                 {   
  250.   
  251.                                     textBox5.Text += "¯¯¯¯¯¯¯¯¯¯      ";   
  252.                                 }   
  253.                             }   
  254.                         textBox5.Text += "/r/n";   
  255.                     }   
  256.   
  257.                 }   
  258.                 textBox5.Visible = true;   
  259.                 this.AutoScroll = true;   
  260.             }   
  261.             catch (IndexOutOfRangeException)   
  262.             {   
  263.                 textBox4.Text = "";   
  264.                 textBox4.Focus();   
  265.                 label1.Visible = true;   
  266.                 label1.Text = "请输入正确的每个货位列数";   
  267.             }   
  268.             catch (FormatException)   
  269.             {   
  270.                 textBox1.Text = "";   
  271.                 textBox2.Text = "";   
  272.                 textBox3.Text = "";   
  273.                 textBox4.Text = "";   
  274.                 textBox1.Focus();   
  275.                 label1.Visible = true;   
  276.                 label1.Text = "请输入正确的格式";   
  277.             }   
  278.         }   
  279.     }   
  280. }   

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值