3功能模块设计3.1用户登陆模块系统的登录界面,需要家庭成员才能登录进入使用系统,当输入错误的帐号、密码会有提示框提醒重新输入。
如图8所示:图8 用户登录模块主要代码如下:private void chkUser(){if (TxtUserName.Text == "" && TxtPassword.Text == ""){Alert.AlertAndRedirect("没有输入账号和密码!", "Login.aspx");}else{dr = data.GetDataReader("select * from [Users] where Name='" +TxtUserName.Text.Trim() + "'and Pwd='" + TxtPassword.Text.Trim() + "'");if (dr.Read()){Session["User"] = dr["Name"].ToString();Response.Redirect("Default.aspx");}else{Alert.AlertAndRedirect("账号或者密码不对请重新登陆!", "Login.aspx");}}}protected void ImageButton1_Click(object sender, ImageClickEventArgs e){chkUser();}protected void ImageButton2_Click(object sender, ImageClickEventArgs e){TxtPassword.Text = "";TxtUserName.Text = "";}protected void LinkButton1_Click(object sender, EventArgs e){Response.Redirect("Login.aspx");}3.2 账目管理模块进入账簿管理可以对录入的收支项目进行查看、修改、删除、新增和查找管理账目信息。
如下图9所示:图9 账目管理模块主要代码如下:protected void gvFilms_RowDeleting(object sender, GridViewDeleteEventArgs e){SqlHelper mydata = new SqlHelper();string ID = gvFilms.DataKeys[e.RowIndex].Values[0].ToString();try{mydata.RunSql("delete from F_Money where id='" + ID + "'");Label4.Text = "删除成功!";gvFilms.EditIndex = -1;Get_Article();}图10 添加模块主要代码如下:Alert alert = new Alert();SqlHelper data = new SqlHelper();public string DownPath;protected void Page_Load(object sender, EventArgs e){if (!IsPostBack){Type();Users();}}private void Type(){drpParentItem.DataSource = data.GetDataReader("select * from Type ");drpParentItem.DataTextField = "name";drpParentItem.DataValueField = "id";drpParentItem.DataBind();}private void Users(){drpUserName.DataSource = data.GetDataReader("select * from Users ");drpUserName.DataTextField = "RealName";drpUserName.DataValueField = "id";drpUserName.DataBind();}protected void IbnOk_Click(object sender, ImageClickEventArgs e){data.RunSql("insert into F_Money(name,Type,UserName,AddMoney,Ds)values('" + drpParentItem.SelectedItem.Text + "','" + drpSubItem.SelectedItem.Text + "','" +drpUserName.SelectedItem.Text + "','" + TxtMoney.Text + "','" + TxtStatement.Text + "')");Alert.AlertAndRedirect("添加成功!", "MangerZb.aspx");}protected void IbnCanel_Click(object sender, ImageClickEventArgs e){Response.Redirect("MangerZb.aspx");}3.4 查找账目信息家庭成员登陆后进入账簿管理,可以按时间对账目信息进行查询。
如图11所示:图11 查找模块主要代码如下:protected void IbnOk_Click(object sender, ImageClickEventArgs e){string beingtime = txttime1.Value;string endtime = Text1.Value;Response.Redirect("SearchList.aspx?b="+beingtime+"&e="+endtime);}protected void IbnCanel_Click1(object sender, ImageClickEventArgs e){Response.Redirect("MangerZb.aspx");}3.5 家庭人员管理模块家庭成员登陆后,进入家庭成员管理模块,对现有的家庭成员进行添加、删除和修改。
如图12所示:图12 家庭成员管理模块主要代码如下:protected void ImageButton2_Click1(object sender, ImageClickEventArgs e){Response.Redirect("AddUser.aspx");}protected void ImageButton1_Click(object sender, ImageClickEventArgs e){data.RunSql("insert into Users(Pwd,Name,RealName)values('" + TextBox4.Text + "','" + TextBox3.Text + "','" + TextBox2.Text + "')");Alert.AlertAndRedirect("添加成功!", "UserList.aspx");}3.6 账目类别信息管理家庭成员登陆后,进入收支项目管理可以对所需要的项目进行添加、修改和删除账目类别信息。
如图13所示:图13收支项目管理模块主要代码如下:protected void InitData(){SqlHelper mydata = new SqlHelper();GridView1.DataSource = mydata.GetDataReader("select * from Type");GridView1.DataBind();}//GridView控件RowDeleting事件protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e){SqlHelper mydata = new SqlHelper();string ID = GridView1.DataKeys[e.RowIndex].Values[0].ToString();try{mydata.RunSql("delete from Type where id='" + ID + "'");Label4.Text = "删除成功!";GridView1.EditIndex = -1;InitData();}catch{Label4.Text = "删除失败!";}}3.7 账目统计信息家庭成员登陆后,进入报表统计模块,可以查询现有账目信息,可以导出Excel 保存和打印所需要的数据。
如图14所示:图14 账目统计模块主要代码如下:public DataSet GetCodeBy(int iCount){SqlHelper date = new SqlHelper();string strTop = "";if (iCount > 1){strTop = "top " + iCount.ToString();}string sql = "select " + strTop + " * from [F_Money] ";SqlConnection con = new SqlConnection(SqlHelper.connstring);SqlCommand cmd = new SqlCommand(sql, con);SqlDataAdapter da = new SqlDataAdapter(cmd);DataSet ds = null;try{con.Open();ds = new DataSet();da.Fill(ds);}catch (SqlException ex){ throw ex;}catch (Exception ex){throw ex;}finally{con.Close();}return ds;}private void DisableControls(Control gv){。