Exemple #1
0
 private static bookAdd _instance = null; // 单例模式
 public static bookAdd CreateInstance()
 {
     if (_instance == null)
     {
         _instance = new bookAdd();
     }
     return(_instance);
 }
Exemple #2
0
        private void bookAdd_Load(object sender, EventArgs e)
        {
            int bkID = bookAddControler.GetLastBkID();

            if (bkID == -1)
            {
                MessageBox.Show("连接数据库失败,请检查您的网络连接!", "错误:", MessageBoxButtons.OK, MessageBoxIcon.Error);
                _instance = null;
                this.Dispose();
            }
            textBox_bkID.Text = (bkID + 1).ToString();
            comboBox_bkCatalog.SelectedIndex  = 0;
            comboBox_bkLanguage.SelectedIndex = 0;
        }
Exemple #3
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            if (textBox_bkCode.Text == "")
            {
                MessageBox.Show("图书编号不能为空!", "提示:", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                return;
            }
            if (textBox_bkName.Text == "")
            {
                MessageBox.Show("图书名称不能为空!", "提示:", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                return;
            }
            if (textBox_bkAuthor.Text == "")
            {
                MessageBox.Show("图书作者不能为空!", "提示:", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                return;
            }
            if (textBox_bkPress.Text == "")
            {
                MessageBox.Show("出版社名不能为空!", "提示:", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                return;
            }
            if (textBox_bkISBN.Text == "")
            {
                MessageBox.Show("ISBN不能为空!", "提示:", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                return;
            }
            try
            {
                if (Int32.Parse(textBox_bkPages.Text) <= 0)
                {
                    MessageBox.Show("图书页数必须大于0!", "提示:", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                    return;
                }
            }
            catch (Exception)
            {
                MessageBox.Show("请输入正确的图书页数!", "错误:", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            try
            {
                if (decimal.Parse(textBox_bkPrice.Text) <= 0)
                {
                    MessageBox.Show("图书价格必须大于0!", "提示:", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                    return;
                }
            }
            catch (Exception)
            {
                MessageBox.Show("请输入正确的价格!", "错误:", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            try
            {
                if (Int32.Parse(textBox_quantity.Text) <= 0)
                {
                    MessageBox.Show("图书本书必须大于0!", "提示:", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                    return;
                }
            }
            catch (Exception)
            {
                MessageBox.Show("请输入正确的图书本书!", "错误:", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (textBox_bkBrief.Text == "")
            {
                MessageBox.Show("内容简介不能为空!", "提示:", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                return;
            }
            setBookInfo();
            // 如果还存在未提交的添加图书操作,则bkID从未提交操作中获取!
            int index = -1;

            foreach (UserAction action in main.ActionList)
            {
                if (action.actionSource == "Book" && action.actionType == "Add")
                {
                    Book tmp = (Book)action.actionModel;
                    index = tmp.bkID;
                }
            }
            for (int i = 0; i < Int32.Parse(textBox_quantity.Text); i++)
            {
                if (index != -1)
                {
                    textBox_bkID.Text = (index + 1).ToString();
                }
                GlobalObject.bookSource.bkID = Int32.Parse(textBox_bkID.Text) + i;
                GlobalObject.actionSource.actionDescription = $"添加图书 {GlobalObject.bookSource.bkCode}(bkID:{GlobalObject.bookSource.bkID}) 。";
                main.addAction(GlobalObject.actionSource);
            }
            this.Visible = false;
            _instance    = null;
            this.Dispose();
        }
Exemple #4
0
 private void bookAdd_FormClosing(object sender, FormClosingEventArgs e)
 {
     _instance = null;
     this.Dispose();
 }
Exemple #5
0
 private void btnCancel_Click(object sender, EventArgs e)
 {
     _instance = null;
     this.Dispose();
 }