Form2.cs 2.44 KB
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 HaierExe04
{
    public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();
        }

        LinkSqlDB SqlDbItem = new LinkSqlDB();

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                if (textBox1.Text != "" && textBox2.Text != "" && textBox3.Text != "" && textBox4.Text != "" && textBox5.Text!= "" && textBox6.Text != "" && textBox7.Text != "")
                {
                    if (textBox2.Text.Length == 9)
                    {
                        MessageBox.Show("条码录入的长度必须为9");
                        textBox2.Focus();
                    }
                    else 
                    {
                        string strInsert = "Insert into T_BarcodeRules(Brand,Code,[Type],ExternalSerial,Serial,[Platform],ProductType,SaleTo)values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}')";
                        string strSql = string.Format(strInsert, textBox1.Text, textBox2.Text, textBox3.Text, textBox4.Text, textBox5.Text, textBox6.Text, textBox7.Text, comboBox1.Text);
                        if (SqlDbItem.Exists("T_BarcodeRules", "Code", textBox2.Text) != 0)
                        {
                            if (SqlDbItem.Insert(strSql) == true)
                            {
                                label17.Text = "导入成功!!!";
                                label17.ForeColor = Color.Green;
                            }
                            else
                            {
                                label17.Text = "导入失败!!!";
                                label17.ForeColor = Color.Red;
                            }
                        }
                        else
                        {
                            MessageBox.Show("条码的前9位信息已经存在!!!,请核对");
                        }
                    }
                }
                else
                {
                    MessageBox.Show("录入信息项目不允许出现为空!!!,请核对项目");
                }
            }
            catch (Exception ex)
            {
                LogExecute.WriteExceptionLog("手工导入", ex);
            }
        }
    }
}