public static int InsertActivity(Actiivity A) { int n = 0; string sql = "Insert ActivityInfo(AName,ATime,ATimeEnd) "; sql += "Values ('{0}','{1}','{2}')"; sql = string.Format(sql, A.AName, A.ATime, A.ATimeEnd); n = DBHelper.ExecuteNonQuery(sql); return(n); }
public static List <Actiivity> SelectFestivalActivityAll() { List <Actiivity> tb = new List <Actiivity>(); string sql = "select top 200 * from TextActivityInfo"; SqlDataReader dr = DBHelper.ExecuteReader(sql); while (dr.Read()) { Actiivity tbs = new Actiivity(); tbs.AName = (string)dr["AName"]; tbs.ATime = (DateTime)dr["ATime"]; tbs.ATimeEnd = (DateTime)dr["ATimeEnd"]; tb.Add(tbs); } dr.Close(); DBHelper.Closecon(); return(tb); }
private void btnSave_Click(object sender, EventArgs e) { if (txtUpdate.Visible == false) { Actiivity F = new Actiivity() { AName = txtActivityTitle.Text, ATime = dtpStartTime.Value, ATimeEnd = dtpOverTime.Value, }; int n = InsertTextActivity(F); if (n > 0) { dgvTextAInfo.RowsDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter; dgvTextAInfo.DataSource = ActivityManager.SelectFestivalActivityAll(); MessageBox.Show("添加成功"); lbl.Visible = false; txtUpdate.Visible = false; btnSave.Visible = false; } } if (txtUpdate.Visible == true) { string name = txtUpdate.Text; string name2 = txtActivityTitle.Text; DateTime time = dtpStartTime.Value; DateTime time2 = dtpOverTime.Value; int n = ActivityManager.UpdateActivity(name, time, time2, name2); if (n > 0) { dgvTextAInfo.RowsDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter; dgvTextAInfo.DataSource = ActivityManager.SelectFestivalActivityAll(); MessageBox.Show("修改成功!"); lbl.Visible = false; txtUpdate.Visible = false; btnSave.Visible = false; } } }