- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- namespace WindowsFormsApplication1
- {
- public partial class Form2 : Form
- {
- public Form2()
- {
- InitializeComponent();
- }
- private void button1_Click(object sender, EventArgs e)
- {
- textBox5.Visible = false;
- label1.Visible = false;
- //排号
- int line;
- //货架数,层数
- int ShelfNumber, LayerNumber;
- try
- {
- line = Convert.ToInt32(textBox1.Text.ToString());
- ShelfNumber = Convert.ToInt32(textBox2.Text.ToString());
- LayerNumber = Convert.ToInt32(textBox3.Text.ToString());
- //每个货架列数
- int[] Number = new int[ShelfNumber];
- string s = textBox4.Text.ToString();
- string[] sArray = s.Split(' ');
- int n = 0;
- foreach (string str in sArray)
- {
- Number[n++] = Convert.ToInt32(str);
- }
- //发现异常后面的不执行
- string title = "**卷烟厂第" + line + "排库位规划图";
- textBox5.Text = title;
- textBox5.Text += "/r/n/r/n/r/n ";
- //输出货架号
- for (int j = 0; j < ShelfNumber; j++)
- {
- for (int k = 0; k < Number[j]; k++)
- {
- if (Number[j] % 2 != 0)
- {
- if (k == (Number[j] / 2))
- {
- title = "货架" + (j + 1) + " ";
- textBox5.Text += title;
- }
- else
- {
- if (Number[j] == 1)
- {
- title = "货架" + (j + 1) + " ";
- textBox5.Text += title;
- }
- else
- {
- textBox5.Text += " ";
- }
- }
- }
- else
- {
- if (k == (Number[j] / 2) - 1)
- {
- title = " 货架" + (j + 1) + "";
- textBox5.Text += title;
- }
- else
- {
- textBox5.Text += " ";
- }
- }
- }
- if (Number[j] == 0)
- {
- title = "货架" + (j + 1) + " ";
- textBox5.Text += title;
- }
- textBox5.Text += " ";
- }
- //画一行横杠
- textBox5.Text += "/r/n ";
- for (int j = 0; j < ShelfNumber; j++)
- {
- textBox5.Text += "__________";
- for (int k = 0; k < Number[j] - 2; k++)
- {
- textBox5.Text += "_________";
- }
- if (Number[j] >= 2)
- {
- textBox5.Text += "__________ ";
- }
- else
- {
- textBox5.Text += "_ ";
- }
- }
- //画5行竖线
- for (int row = 1; row < 6; row++)
- {
- textBox5.Text += "/r/n ";
- for (int j = 0; j < ShelfNumber; j++)
- {
- textBox5.Text += "| ";
- for (int k = 0; k < Number[j] - 2; k++)
- {
- textBox5.Text += " ";
- }
- if (Number[j] <= 1)
- {
- textBox5.Text += "| ";
- }
- else
- {
- textBox5.Text += " | ";
- }
- }
- }
- //画一行横杠
- textBox5.Text += "/r/n ";
- for (int j = 0; j < ShelfNumber; j++)
- {
- textBox5.Text += "|_________";
- for (int k = 0; k < Number[j] - 2; k++)
- {
- textBox5.Text += "_________";
- }
- if (Number[j] <= 1)
- {
- textBox5.Text += "| ";
- }
- else
- {
- textBox5.Text += "_________| ";
- }
- }
- textBox5.Text += "/r/n";
- for (int i = LayerNumber; i > 0; i--)
- {
- n = 1;
- title = "第" + i + "层:";
- textBox5.Text += title;
- for (int j = 0; j < ShelfNumber; j++)
- {
- textBox5.Text += "|";
- for (int k = 0; k < Number[j]; k++)
- {
- //显示货位号 例如"|05-4-01|"
- string ss = "|" + line.ToString().PadLeft(2, '0') + "-" + i.ToString() + "-" + n.ToString().PadLeft(2, '0') + "|";
- textBox5.Text += ss;
- n++;
- }
- if (Number[j] == 0)
- {
- textBox5.Text += " ";
- }
- textBox5.Text += "|";
- textBox5.Text += " ";
- }
- if (i > 1)
- {
- textBox5.Text += "/r/n ";
- for (int j = 0; j < ShelfNumber; j++)
- {
- textBox5.Text += "|¯¯¯¯¯¯¯¯¯";
- for (int k = 0; k < Number[j] - 2; k++)
- {
- textBox5.Text += "¯¯¯¯¯¯¯¯¯";
- }
- if (Number[j] <= 1)
- {
- textBox5.Text += "| ";
- }
- else
- {
- textBox5.Text += "¯¯¯¯¯¯¯¯¯| ";
- }
- }
- for (int row = 1; row < 6; row++)
- {
- textBox5.Text += "/r/n ";
- for (int j = 0; j < ShelfNumber; j++)
- {
- textBox5.Text += "| ";
- for (int k = 0; k < Number[j] - 2; k++)
- {
- textBox5.Text += " ";
- }
- if (Number[j] <= 1)
- {
- textBox5.Text += "| ";
- }
- else
- {
- textBox5.Text += " | ";
- }
- }
- }
- //画一行下横线
- textBox5.Text += "/r/n ";
- for (int j = 0; j < ShelfNumber; j++)
- {
- textBox5.Text += "|_________";
- for (int k = 0; k < Number[j] - 2; k++)
- {
- textBox5.Text += "_________";
- }
- if (Number[j] <= 1)
- {
- textBox5.Text += "| ";
- }
- else
- {
- textBox5.Text += "_________| ";
- }
- }
- textBox5.Text += "/r/n";
- }
- else
- {
- textBox5.Text += "/r/n ";
- for (int j = 0; j < ShelfNumber; j++)
- {
- textBox5.Text += "¯¯¯¯¯¯¯¯¯¯";
- for (int k = 0; k < Number[j] - 2; k++)
- {
- textBox5.Text += "¯¯¯¯¯¯¯¯¯";
- }
- if (Number[j] <= 1)
- {
- textBox5.Text += "¯ ";
- }
- else
- {
- textBox5.Text += "¯¯¯¯¯¯¯¯¯¯ ";
- }
- }
- textBox5.Text += "/r/n";
- }
- }
- textBox5.Visible = true;
- this.AutoScroll = true;
- }
- catch (IndexOutOfRangeException)
- {
- textBox4.Text = "";
- textBox4.Focus();
- label1.Visible = true;
- label1.Text = "请输入正确的每个货位列数";
- }
- catch (FormatException)
- {
- textBox1.Text = "";
- textBox2.Text = "";
- textBox3.Text = "";
- textBox4.Text = "";
- textBox1.Focus();
- label1.Visible = true;
- label1.Text = "请输入正确的格式";
- }
- }
- }
- }
C#表单刚做的一个小东西(货架规划图)代码即输出结果
最新推荐文章于 2023-05-04 22:50:04 发布