C# 综合示例 库存管理系统21 关于(FormAbout)、 输入对话框(InputBox)、 总结

发布于:2025-05-07 ⋅ 阅读:(14) ⋅ 点赞:(0)

版权声明:本文为博主原创文章,转载请在显著位置标明本文出处以及作者网名,未经作者允许不得用于商业目的

99.2.3.19 关于(FormAbout)

图99A-36 关于窗口设计

关于窗口内可以加入对开发者、程序版本等的介绍。

全部代码如下:

        public static void ShowForm()

        {

            FormAbout frm = new FormAbout();

            frm.ShowDialog();

        }

        private void FormAbout_Load(object sender, EventArgs e)

        {

            btnOk.Focus();

        }

 

        private void btnOk_Click(object sender, EventArgs e)

        {

            Close();

        }

99.2.3.20 输入对话框(InputBox)

输入对话框窗体主要是模拟类似Vb的InputBox方法,提供获取用户输入字符串的弹出窗口。

全部代码如下:

        private TextBox textBox;

        private Button okButton;

        private Button cancelButton;

 

        public InputBox(string title, string promptText)

        {

            Text = title;

            ClientSize = new System.Drawing.Size(300, 150);

 

            Label label = new Label();

            label.Text = promptText;

            label.SetBounds(10, 10, 280, 20);

            label.AutoSize = true;

            Controls.Add(label);

 

            textBox = new TextBox();

            textBox.SetBounds(10, 40, 280, 20);

            Controls.Add(textBox);

 

            okButton = new Button();

            okButton.Text = "确定";

            okButton.DialogResult = DialogResult.OK;

            okButton.SetBounds(80, 70, 75, 23);

            Controls.Add(okButton);

 

            cancelButton = new Button();

            cancelButton.Text = "取消";

            cancelButton.DialogResult = DialogResult.Cancel;

            cancelButton.SetBounds(160, 70, 75, 23);

            Controls.Add(cancelButton);

 

            AcceptButton = okButton;

            CancelButton = cancelButton;

        }

 

        public static string ShowDialog(string title, string promptText)

        {

            using (InputBox inputBox = new InputBox(title, promptText))

            {

                if (inputBox.ShowDialog() == DialogResult.OK)

                {

                    return inputBox.textBox.Text;

                }

                return null;

            }

        }

 

        private void InitializeComponent()

        {

            this.SuspendLayout();

            this.ClientSize = new System.Drawing.Size(284, 261);

            this.Name = "InputBox";

            this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;

            this.Load += new System.EventHandler(this.InputBox_Load);

            this.ResumeLayout(false);

        }

使用此窗体的代码示例如下:

 

//通过窗体的ShowDialog方法返回用户输入的字符串

string newUser = InputBox.ShowDialog("对话框文本内容", "对话框标题");

//通过字符串的Trim方法,确定用户是否有输入

if (newUser.Trim() == "")

{

MessageBox.Show("取消操作");

return;

}

99.2.4 总结

如前言所述,《库存管理系统》主要是为了弥补教程中缺少综合示例。由于设计时间较短,可能会有些遗漏或者Bug。

可以在此基础上增加:

1、操作日志:记录管理员、操作员对数据库操作时间和操作动作。

2、对数据库增加密码。access2010中,请以独占方式打开数据库,在【文件】|【信息】,按下【用密码进行加密】对数据库增加密码。在程序代码中,64位程序使用以下连接语句:

Provider=Microsoft.ACE.OLEDB.12.0;Data Source=数据库路径;jet oledb:database password=密码;

其它情况的连接语句,请参看教程第19.3.1节《连接字符串》。

3、管理员权限增加对操作员删除数据的查看和恢复功能。

 

 

学习更多vb.net知识,请参看vb.net 教程 目录

学习更多C#知识,请参看C#教程 目录

 


网站公告

今日签到

点亮在社区的每一天
去签到