Esempio n. 1
0
 private void btnAdd_Click(object sender, EventArgs e)
 {
     if (txtName.Text == "" || txtExplain.Text == "")
     {
         MessageBox.Show("请输入内容");
     }
     else
     {
         Dbcontrol dbHelper = new Dbcontrol();
         if (rdoSingle.Checked)
         {
             string strEx = "insert into [sheet1$] (名称,解释) VALUES('" + txtName.Text.Trim() + "','" + txtExplain.Text.Trim() + "')";
             MessageBox.Show(dbHelper.ReExNum(strEx) > 0 ? "添加成功!" : "添加失败!");
         }
         else
         {
             string[] charSplit      = { "\n" };
             char     entrySeparator = txtName.Text[0];
             string[] entries        = txtExplain.Text.Trim().Replace("\r", "").Split(charSplit, StringSplitOptions.None);
             int      succeedCount   = 0;
             foreach (var item in entries)
             {
                 string[] data = item.Split(entrySeparator);
                 if (data.Length < 2)
                 {
                     continue;
                 }
                 succeedCount += dbHelper.ReExNum(string.Format("insert into [sheet1$] (名称,解释) VALUES('{0}','{1}');", data[0], data[1]));
             }
             MessageBox.Show("成功添加了【" + succeedCount + "】条记录。", "成功提示");
         }
         ClearForm();
     }
 }
Esempio n. 2
0
        private void btnDelete_Click(object sender, EventArgs e)
        {
            string name = lsbSearchName.Text.Trim();

            if (string.IsNullOrEmpty(name))
            {
                MessageBox.Show("选择的字符值为空白");
                return;
            }
            //UPDATE sheet1$ SET NAME = NULL, DeptName= NULL WHERE DeptId = 1;
            string excelSqlStr = "UPDATE [sheet1$] set 名称='',解释='' where 名称 ='" + name + "'";

            if (_dbc01.ReExNum(excelSqlStr) > 0)
            {
                LoadDefault();
            }
            else
            {
                MessageBox.Show("删除失败");
                UpdateStatusMessage("删除失败");
            }
        }