日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 综合教程 >内容正文

综合教程

编程序

發(fā)布時(shí)間:2023/12/19 综合教程 28 生活家
生活随笔 收集整理的這篇文章主要介紹了 编程序 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

后面的分別改為txtname spec price

雙擊保存

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;

using System.Data.SqlClient;//連接數(shù)據(jù)
using System.Configuration;

namespace ERPforms
{
    public partial class Form1 : Form
    {
        //定義錯(cuò)誤信息
        string[] strMessage = new string[]{
            "編號(hào)不能為空!","物料不能為空!","價(jià)格或輸入格式不對(duì)!"
        };
        public Form1()
        {
            InitializeComponent();
        }      
        private void textBox4_TextChanged(object sender, EventArgs e)
        {

        }        
        private void label1_Click(object sender, EventArgs e)
        {

        }          
        private void btnSave_Click(object sender, EventArgs e)
        {

        }       
        private void textBox3_TextChanged(object sender, EventArgs e)
        {

        }
        private void textBox2_TextChanged(object sender, EventArgs e)
        {

        }
        private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }
       //保存數(shù)據(jù)(新增物料)
        private void btmsave_Click(object sender, EventArgs e)
        {
            if (Validation() != -1)
                MessageBox.Show(strMessage[Validation()]);
            else
            {
                AddItems();
            }
        }
        //添加物料信息
        private void AddItems()
        {
            //連接數(shù)據(jù)庫(kù)
            string connString=ConfigurationManager.ConnectionStrings["connString"].ToString();
            SqlConnection conn=new SqlConnection(connString);//實(shí)例化連接對(duì)象
            string sql="insert into Items values('"+txtNo.Text+"',"+"'"+txtName.Text+"','"+txtSpec.Text+"',"+txtPrice.Text+")";
            //數(shù)據(jù)庫(kù)操作
            conn.Open();//打開連接
            try
            {
                SqlCommand cmd = new SqlCommand(sql, conn);
                cmd.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                throw new Exception(ex.ToString());
            }
            finally
            {
                conn.Close();
            }
            
        }
        //數(shù)據(jù)驗(yàn)證
        private int Validation()
        {
            int price = 0;
            int status = -1;
            if (txtNo.Text == "")//驗(yàn)證編號(hào)
                status = 0;
            else if (txtName.Text == "")
                status = 1;
            else if (txtPrice.Text == "" &&
                int.TryParse(txtPrice.Text, out price))
                status = 2;
            return status;

        }
    }
}

總結(jié)

以上是生活随笔為你收集整理的编程序的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。