private void button1_Click(object sender, EventArgs e)
        {
            sqlDbHelper sdh = new sqlDbHelper();
            string      TypeName;

            if (radioButton1.Checked)
            {
                TypeName = "收入";
            }
            else
            {
                TypeName = "支出";
            }
            SqlParameter[] pa = { new SqlParameter("@tyName", TypeName), new SqlParameter("@ieTypeName", textBox1.Text), new SqlParameter("@rm", textBox2.Text) };
            int            c  = sdh.ExecuteNonquery("insert into IncomeExpendType values (@tyName, @ieTypeName, @rm)", CommandType.Text, pa);

            if (c > 0)
            {
                MessageBox.Show("添加成功");
                if (checkBox1.Checked)
                {
                    this.Call(sender, e);
                }
                else
                {
                    Close();
                }
            }
            else
            {
                MessageBox.Show("添加失败");
            }
        }
        private void 添加收支分类_Load(object sender, EventArgs e)
        {
            sqlDbHelper sdh = new sqlDbHelper();
            int         b   = (int)sdh.ExecuteScalar("select count(*) from IncomeExpendType");

            textBox1.Text = b.ToString();
        }
        private void  除ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (listView1.SelectedItems.Count <= 0)
            {
                MessageBox.Show("请选中至少一项");
            }
            sqlDbHelper helper = new sqlDbHelper();

            for (int i = 0; i < listView1.SelectedItems.Count; i++)
            {
                string strid = listView1.SelectedItems[i].SubItems[2].Text;
                helper.ExecuteNonquery("delete from IncomeExpendType where IncomeExependTypeId = @id", CommandType.Text, new SqlParameter("id", strid));
            }
            BindInExpType(sender, e);
        }
        private void BindInExpType(object sender, EventArgs e)
        {
            listView1.Items.Clear();
            sqlDbHelper   helper = new sqlDbHelper();
            SqlDataReader reader = helper.ExecuteReader("select * from IncomeExpendType");

            while (reader.Read())
            {
                ListViewItem lv = new ListViewItem(reader.GetString(2));
                lv.SubItems.Add(reader.GetString(1));
                lv.SubItems.Add(reader.GetInt32(0).ToString());
                lv.SubItems.Add(reader.GetString(3));
                listView1.Items.Add(lv);
            }
            reader.Close();
        }
Example #5
0
        private void dataBind(object sender, EventArgs e)
        {
            string strSql = "select * from IncomeExpendDet where UserLoginID = @ulid";

            SqlParameter[] sp = new SqlParameter[] { new SqlParameter("@ulid", "1") };
            con = new SqlConnection("Data Source=DESKTOP-7OA7319;Database=note;Integrated Security=true;");
            sda = sqlDbHelper.ExecuteAdapter(strSql, CommandType.Text, sp, con);
            scb = new SqlCommandBuilder(sda);
            dataGridView1.AutoGenerateColumns = false;
            ds = new DataSet();
            sda.Fill(ds, "ttt");
            dtinfor = ds.Tables[0];
            bindingSource1.DataSource                 = dtinfor;
            dataGridView1.DataSource                  = bindingSource1;
            bindingNavigator1.BindingSource           = bindingSource1;
            dtinfor.Columns[2].DefaultValue           = "1";
            dataGridView1.Columns[0].DataPropertyName = dtinfor.Columns[0].ColumnName;
            dataGridView1.Columns[1].DataPropertyName = dtinfor.Columns[1].ColumnName;
            dataGridView1.Columns[2].DataPropertyName = dtinfor.Columns[2].ColumnName;
            dataGridView1.Columns[3].DataPropertyName = dtinfor.Columns[3].ColumnName;
            dataGridView1.Columns[4].DataPropertyName = dtinfor.Columns[4].ColumnName;
            dataGridView1.Columns[5].DataPropertyName = dtinfor.Columns[5].ColumnName;

            string sql = "select IncomeExependTypeId, IncomeExpendTypeName from IncomeExpendType";

            sqlDbHelper sdh = new sqlDbHelper();
            DataTable   dt  = sdh.ExecuteDataTable(sql, CommandType.Text, null);

            收支类目.DataSource    = dt;
            收支类目.DisplayMember = "IncomeExpendTypeName";
            收支类目.ValueMember   = "IncomeExependTypeId";
            //User.DataSource = dt;
            //User.DisplayMember = "IncomeExependTypeId";
            //User.ValueMember = "IncomeExpendTypeName";
            cmbType.DataSource    = dt;
            cmbType.DisplayMember = "IncomeExpendTypeName";
            cmbType.ValueMember   = "IncomeExependTypeId";
            con.Close();
        }