管理系統開發三: winforml錄入界面

1.打開sql server  添加數據庫

2.打開VS  創建錄入界面

3

 3.打開VS  添加新建方法 儲存實體類

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Models
{
    /// <summary>
    /// 社區實體類
    /// </summary>
    public class SeQuDate
    {
        public string SqId { get; set; }
        public string SqName { get; set; }
        public string SqManer { get; set; }
        //將數據庫中的18位整數轉換成字符串
        public string SqPhone { get; set; }
        public DateTime SqTime { get; set; }
    }
}

4.添加新建腳本 儲存數據訪問類

   /// <summary>
        /// 添加 社區信息
        /// </summary>
        /// <param name="objsq"></param>
        /// <returns></returns>
        public int AddSeQu(SeQuDate objsq)
        {
            string sql = "insert into SeQu (sqid,sqname,sqmaner,sqphone,sqtime) ";
            sql += "values ('{0}','{1}','{2}','{3}','{4}')";
            sql = string.Format(sql,
                objsq.SqId,
                objsq.SqName,
                objsq.SqManer,
                objsq.SqPhone,
                objsq.SqTime);
            try
            {
                return SQLHelper.Update(sql);
            }
            catch (Exception ex)
            {

                throw new Exception("保存數據出錯!" + ex.Message);
            }
        }

5.打開錄入界面  雙擊錄入按鈕 進入方法  

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Models;
using DAL;

namespace StudentManager
{
    /// <summary>
    /// 社區信息添加 功能
    /// </summary>
    public partial class My_SeQuAdd : Form
    {
        private SeQuService objSequ = new SeQuService();//數據庫後臺鏈接

        public My_SeQuAdd()
        {
            InitializeComponent();
        }
        private void My_SeQuAdd_Load(object sender, EventArgs e)
        {
        }


        //確認添加社區信息
        private void BtnAddOK_Click(object sender, EventArgs e)
        {
            //社區代碼驗證
            if (this.textBoxid.Text.Trim().Length != 12)
            {
                MessageBox.Show("社區代碼應爲12位數字", "驗證提示");
                this.textBoxid.Focus();
                return;
            }
           
            //驗證完畢 上傳數據庫
            //1.封裝對象
            SeQuDate sqdate = new SeQuDate()
            {
                SqId = this.textBoxid.Text.Trim(),
                SqName = this.textBoxname.Text.Trim(),
                SqManer = this.textBoxMan.Text.Trim(),
                SqPhone = this.textBoxphone.Text.Trim(),
                SqTime = Convert.ToDateTime(this.dateTimePicker1.Text)
            };
            //2.提交對象
            try
            {
                int result = objSequ.AddSeQu(sqdate);
                if (result == 1)
                {
                    sqlLog.WriteSQLLog(this.textBoxname.Text + "社區信息添加");
                    DialogResult dresult = MessageBox.Show("添加成功!繼續添加嗎?", "添加詢問",
                        MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
                    if (dresult == DialogResult.OK)
                    {
                        //清空當前文本框
                        Cleardate();
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

        }

        //數據清空
        private void Cleardate()
        {
            this.textBoxid.Text = "";
            this.textBoxMan.Text = "";
            this.textBoxname.Text = ""; ;
            this.textBoxphone.Text = "";
            this.textBoxid.Focus();
        }

        //重新輸入
        private void button2_Click(object sender, EventArgs e)
        {
            Cleardate();
        }
    }
}

預祝成功!!!!!!!!!!!

下一章 管理系統開發四: 在主窗體中嵌入子窗體的實現

  1. 管理系統開發一: winform連接sql數據庫 https://blog.csdn.net/m0_37583098/article/details/88546146
  2. 管理系統開發二: winforml登錄界面sql數據查詢和修改 https://blog.csdn.net/m0_37583098/article/details/88547123
  3. 管理系統開發三: winforml錄入界面 https://blog.csdn.net/m0_37583098/article/details/88547805
  4. 管理系統開發四: 在主窗體中嵌入子窗體的實現 https://blog.csdn.net/m0_37583098/article/details/88549151
  5. 管理開發系統五:winform連接數據庫查詢 使用DataGridView展示查詢結果 https://blog.csdn.net/m0_37583098/article/details/88549461
  6. 管理開發系統六:winform連接數據庫修改 https://blog.csdn.net/m0_37583098/article/details/88550157
  7. 管理開發系統七:winform連接數據庫刪除 https://blog.csdn.net/m0_37583098/article/details/88578796
  8. 管理開發系統八:winform導出excel https://blog.csdn.net/m0_37583098/article/details/88579043
  9. 管理開發系統九:winform帶sql數據庫導出 https://blog.csdn.net/m0_37583098/article/details/88580311
  10. sql service 常用語句基礎https://blog.csdn.net/m0_37583098/article/details/87876264
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章