protected void gv_Result_RowCommand(object sender, GridViewCommandEventArgs e) { string command = e.CommandName; int id = Convert.ToInt32(e.CommandArgument); if (command.Equals("Chk"))//查看 { Response.Redirect("CheckAffairList_zxgz_Add.aspx?CommunicationId=" + id); } else if (command.Equals("Upd"))//修改 { Response.Redirect("CheckAffairList_zxgz_Add.aspx?CommunicationId=" + id); } else if (command.Equals("Del"))//删除 { bool result = SpecialWorkBusiness.DeleteCommunication(id); if (!result) { ScriptManager.RegisterStartupScript(UpdatePanel1, this.GetType(), "alter", "alert('删除失败,请重新再试!')", true); return; } LogInfoBusiness.AddLogInfo(Convert.ToInt32(log_userid), DateTime.Now, Convert.ToInt32(log_usertype), log_username, 3, "专项工作信息", log_ip, log_account);//删除添加日志 操作类型->3 RefreshView(0); } }
private void RefreshView(int NewIndex) { try { int size = this.gv_Result.PageSize; string name = tb_Name.Text.Trim(); string sex = ddl_sex.SelectedValue; var ps = SpecialWorkBusiness.GetCommunications(size, name, sex); this.gv_Result.PageIndex = NewIndex; this.gv_Result.DataSource = new PagedCollection <SpecialWork>(ps, NewIndex); this.gv_Result.DataBind(); this.Label_Result.Text = ps.GetResultCount().ToString(); } catch { ScriptManager.RegisterStartupScript(UpdatePanel1, this.GetType(), "alter", "alert('数据加载错误!')", true); } }
protected void btn_AddSimple_Click(object sender, EventArgs e) { int communicationId = SpecialWorkBusiness.AddCommunication(); Response.Redirect("CheckAffairList_zxgz_Add.aspx?CommunicationId=" + communicationId + "&IsNew=True"); }
private void Bind_statistic() { try { DataTable dt = SpecialWorkBusiness.GetStatisticBySex(); if (dt != null) { if (dt.Rows.Count == 1) { if (dt.Rows[0]["Column"].Equals("True")) { DataRow dr = dt.NewRow(); dr["Column"] = "False"; dr["Count"] = 0; dt.Rows.InsertAt(dr, 0); } else { DataRow dr1 = dt.NewRow(); dr1["Column"] = "True"; dr1["Count"] = 0; dt.Rows.Add(dr1); } } else if (dt.Rows.Count == 0) { DataRow dr = dt.NewRow(); dr["Column"] = "False"; dr["Count"] = 0; dt.Rows.Add(dr); DataRow dr1 = dt.NewRow(); dr1["Column"] = "True"; dr1["Count"] = 0; dt.Rows.Add(dr1); } dt.Columns["Column"].ColumnName = "Sex"; dt.Columns.Add("ItemName"); //item名称 dt.Columns.Add("Percent"); //百分比 int itemCount = dt.Rows.Count; //总项数 int totals = 0; //总人数 foreach (DataRow dr in dt.Rows) { totals += Convert.ToInt32(dr["Count"].ToString()); } foreach (DataRow dr in dt.Rows) { dr["ItemName"] = dr["Sex"].ToString().Equals("True") ? "女" : "男"; double percent = totals == 0 ? 0.0000 : Math.Round(Convert.ToDouble(dr["Count"].ToString()) / totals, 4); dr["Percent"] = percent * 100 + "%"; if (PercentString.Equals("")) { PercentString = "['" + dr["ItemName"] + "'," + percent + "]"; } else { PercentString += ",['" + dr["ItemName"] + "'," + percent + "]"; } } DataRow dr_total = dt.NewRow();//添加一条 总计 dr_total["ItemName"] = "总计"; dr_total["Count"] = totals; dr_total["Percent"] = totals == 0 ? "0.00%" : "100%"; dt.Rows.Add(dr_total); gv_result.DataSource = dt; gv_result.DataBind(); Label_Result.Text = itemCount.ToString(); } else { ScriptManager.RegisterStartupScript(UpdatePanel1, this.GetType(), "alter", "layer.alert('数据加载错误!')", true); } } catch (Exception ex) { ScriptManager.RegisterStartupScript(UpdatePanel1, this.GetType(), "alter", "layer.alert('数据加载错误!')", true); } }
protected void btn_submit_Click(object sender, EventArgs e) { try { //所有表单数据 string exchange = tb_Exchange.Text; string type = tb_Type.Text; string name = tb_Name.Text; bool sex = Radio_woman.Checked;//sex true女 false男 DateTime birth = new DateTime(1900, 1, 1); int specialWorkTypeId = Convert.ToInt32(ddl_SpecialWorkType.SelectedValue); DateTime workStartDate = new DateTime(1900, 1, 1); DateTime workEndDate = new DateTime(1900, 1, 1); if (specialWorkTypeId == 0) { Page.ClientScript.RegisterStartupScript(this.GetType(), "alter", "alert('请选择类别!')", true); return; } try { birth = tb_birth.Value.Equals("") ? birth : Convert.ToDateTime(tb_birth.Value); workStartDate = tb_workStartDate.Value.Equals("") ? workStartDate : Convert.ToDateTime(tb_workStartDate.Value); workEndDate = tb_workEndDate.Value.Equals("") ? workEndDate : Convert.ToDateTime(tb_workEndDate.Value); } catch (Exception ex) { text(ex.ToString()); Page.ClientScript.RegisterStartupScript(this.GetType(), "alter", "alert('日期输入格式不规范,请重新输入!')", true); return; } string company = tb_company.Text; string address = tb_address.Text; string phoneNo = tb_phoneNo.Text; double ballot = 0; try { ballot = tb_ballot.Text.ToString().IsNullOrEmpty() ? 0 : Convert.ToDouble(tb_ballot.Text); } catch (Exception ex) { text(ex.ToString()); Page.ClientScript.RegisterStartupScript(this.GetType(), "alter", "alert('当选得票数率输入格式不规范,请重新输入!')", true); return; } bool isReselect = Radio_IsReselect_Yes.Checked; string background = tb_Background.Text; string situation = tb_Situation.Text; if (communicationId != 0) { bool result = false; if (IsNew == null)//修改 { result = SpecialWorkBusiness.UpdateCommunication(communicationId, exchange, specialWorkTypeId, workStartDate, workEndDate, type, name, sex, birth, company, address, phoneNo, ballot, isReselect, background, situation); LogInfoBusiness.AddLogInfo(Convert.ToInt32(log_userid), DateTime.Now, Convert.ToInt32(log_usertype), log_username, 4, "专项工作信息", log_ip, log_account);//修改添加日志 操作类型->4 } else//新增 { result = SpecialWorkBusiness.UpdateCommunicationForNew(communicationId, exchange, specialWorkTypeId, workStartDate, workEndDate, type, name, sex, birth, company, address, phoneNo, ballot, isReselect, background, situation); LogInfoBusiness.AddLogInfo(Convert.ToInt32(log_userid), DateTime.Now, Convert.ToInt32(log_usertype), log_username, 2, "专项工作信息", log_ip, log_account);//新增添加日志 操作类型->2 } if (!result) { Page.ClientScript.RegisterStartupScript(this.GetType(), "alter", "alert('保存失败,请重新再试!')", true); return; } Response.Redirect("CheckAffairList_zxgz.aspx"); } else { Page.ClientScript.RegisterStartupScript(this.GetType(), "alter", "alert('数据加载错误,请重新再试!')", true); return; } } catch (Exception ex) { text(ex.ToString()); Page.ClientScript.RegisterStartupScript(this.GetType(), "alter", "alert('数据加载错误,请重新再试!')", true); } }
private DataTable GetDataTable() { try { DataTable dt_student = SpecialWorkBusiness.GetAllData(); int thisYear = DateTime.Now.Year; if (dt_student != null) { DataTable dt_grid = new DataTable(); dt_grid.Columns.Add("ItemName"); //item名称 dt_grid.Columns.Add("Count"); //item 人数 dt_grid.Columns.Add("Percent"); //百分比 int itemCount = 8; //总项数 20岁及以下、21-25岁、26-30岁、31-35岁、36-40岁、40-45岁、46-50岁、50岁以上 int totals = dt_student.Rows.Count; //总人数 if (true) { DataRow dr = dt_grid.NewRow();//grid 行数据 dr["ItemName"] = "20岁及以下"; int count = dt_student.Select("Birthday >= '" + new DateTime(thisYear - 20, 1, 1).ToString() + "'").Length; double percent = totals == 0 ? 0.0000 : Math.Round(1.0 * count / totals, 4); dr["Count"] = count; dr["Percent"] = percent * 100 + "%"; dt_grid.Rows.Add(dr); } if (true) { DataRow dr = dt_grid.NewRow(); dr["ItemName"] = "21-25岁"; int count = dt_student.Select("Birthday < '" + new DateTime(thisYear - 20, 1, 1).ToString() + "' and Birthday >= '" + new DateTime(thisYear - 25, 1, 1).ToString() + "'").Length; double percent = totals == 0 ? 0.0000 : Math.Round(1.0 * count / totals, 4); dr["Count"] = count; dr["Percent"] = percent * 100 + "%"; dt_grid.Rows.Add(dr); } if (true) { DataRow dr = dt_grid.NewRow(); dr["ItemName"] = "26-30岁"; int count = dt_student.Select("Birthday < '" + new DateTime(thisYear - 25, 1, 1).ToString() + "' and Birthday >= '" + new DateTime(thisYear - 30, 1, 1).ToString() + "'").Length; double percent = totals == 0 ? 0.0000 : Math.Round(1.0 * count / totals, 4); dr["Count"] = count; dr["Percent"] = percent * 100 + "%"; dt_grid.Rows.Add(dr); } if (true) { DataRow dr = dt_grid.NewRow(); dr["ItemName"] = "31-35岁"; int count = dt_student.Select("Birthday < '" + new DateTime(thisYear - 30, 1, 1).ToString() + "' and Birthday >= '" + new DateTime(thisYear - 35, 1, 1).ToString() + "'").Length; double percent = totals == 0 ? 0.0000 : Math.Round(1.0 * count / totals, 4); dr["Count"] = count; dr["Percent"] = percent * 100 + "%"; dt_grid.Rows.Add(dr); } if (true) { DataRow dr = dt_grid.NewRow(); dr["ItemName"] = "36-40岁"; int count = dt_student.Select("Birthday < '" + new DateTime(thisYear - 35, 1, 1).ToString() + "' and Birthday >= '" + new DateTime(thisYear - 40, 1, 1).ToString() + "'").Length; double percent = totals == 0 ? 0.0000 : Math.Round(1.0 * count / totals, 4); dr["Count"] = count; dr["Percent"] = percent * 100 + "%"; dt_grid.Rows.Add(dr); } if (true) { DataRow dr = dt_grid.NewRow(); dr["ItemName"] = "41-45岁"; int count = dt_student.Select("Birthday < '" + new DateTime(thisYear - 40, 1, 1).ToString() + "' and Birthday >= '" + new DateTime(thisYear - 45, 1, 1).ToString() + "'").Length; double percent = totals == 0 ? 0.0000 : Math.Round(1.0 * count / totals, 4); dr["Count"] = count; dr["Percent"] = percent * 100 + "%"; dt_grid.Rows.Add(dr); } if (true) { DataRow dr = dt_grid.NewRow(); dr["ItemName"] = "46-50岁"; int count = dt_student.Select("Birthday < '" + new DateTime(thisYear - 45, 1, 1).ToString() + "' and Birthday >= '" + new DateTime(thisYear - 50, 1, 1).ToString() + "'").Length; double percent = totals == 0 ? 0.0000 : Math.Round(1.0 * count / totals, 4); dr["Count"] = count; dr["Percent"] = percent * 100 + "%"; dt_grid.Rows.Add(dr); } if (true) { DataRow dr = dt_grid.NewRow(); dr["ItemName"] = "50岁以上"; int count = dt_student.Select("Birthday < '" + new DateTime(thisYear - 50, 1, 1).ToString() + "'").Length; double percent = totals == 0 ? 0.0000 : Math.Round(1.0 * count / totals, 4); dr["Count"] = count; dr["Percent"] = percent * 100 + "%"; dt_grid.Rows.Add(dr); } DataRow dr_total = dt_grid.NewRow();//添加一条 总计 dr_total["ItemName"] = "总计"; dr_total["Count"] = totals; dr_total["Percent"] = totals == 0 ? "0.00%" : "100%"; dt_grid.Rows.Add(dr_total); return(dt_grid); } else { ScriptManager.RegisterStartupScript(UpdatePanel1, this.GetType(), "alter", "layer.alert('数据加载错误!')", true); return(new DataTable()); } } catch (Exception ex) { ScriptManager.RegisterStartupScript(UpdatePanel1, this.GetType(), "alter", "layer.alert('数据加载错误!')", true); return(new DataTable()); } }
private void Bind_statistic() { try { DataTable dt_student = SpecialWorkBusiness.GetAllData(); int thisYear = DateTime.Now.Year; if (dt_student != null) { DataTable dt_grid = new DataTable(); dt_grid.Columns.Add("ItemName"); //item名称 dt_grid.Columns.Add("Count"); //item 人数 dt_grid.Columns.Add("Percent"); //百分比 int itemCount = 8; //总项数 20岁及以下、21-25岁、26-30岁、31-35岁、36-40岁、40-45岁、46-50岁、50岁以上 int totals = dt_student.Rows.Count; //总人数 StringBuilder sb_pic_x = new StringBuilder(); //sb_pic_x.Append("["); StringBuilder sb_pic_sum = new StringBuilder(); //sb_pic_sum.Append("{name: '总人数',data: ["); StringBuilder sb_pic_percent = new StringBuilder(); //sb_pic_percent.Append("{name: '所占比例',data: ["); if (true) { DataRow dr = dt_grid.NewRow();//grid 行数据 dr["ItemName"] = "20岁及以下"; int count = dt_student.Select("Birthday >= '" + new DateTime(thisYear - 20, 1, 1).ToString() + "'").Length; double percent = totals == 0 ? 0.0000 : Math.Round(1.0 * count / totals, 4); dr["Count"] = count; dr["Percent"] = percent * 100 + "%"; dt_grid.Rows.Add(dr); if (sb_pic_x.Length == 0)//柱状图 横坐标 { sb_pic_x.Append("'" + dr["ItemName"].ToString() + "'"); sb_pic_sum.Append(count); sb_pic_percent.Append(percent); } else { sb_pic_x.Append(",'" + dr["ItemName"].ToString() + "'"); sb_pic_sum.Append("," + count); sb_pic_percent.Append("," + percent); } } if (true) { DataRow dr = dt_grid.NewRow(); dr["ItemName"] = "21-25岁"; int count = dt_student.Select("Birthday < '" + new DateTime(thisYear - 20, 1, 1).ToString() + "' and Birthday >= '" + new DateTime(thisYear - 25, 1, 1).ToString() + "'").Length; double percent = totals == 0 ? 0.0000 : Math.Round(1.0 * count / totals, 4); dr["Count"] = count; dr["Percent"] = percent * 100 + "%"; dt_grid.Rows.Add(dr); if (sb_pic_x.Length == 0)//柱状图 横坐标 { sb_pic_x.Append("'" + dr["ItemName"].ToString() + "'"); sb_pic_sum.Append(count); sb_pic_percent.Append(percent); } else { sb_pic_x.Append(",'" + dr["ItemName"].ToString() + "'"); sb_pic_sum.Append("," + count); sb_pic_percent.Append("," + percent); } } if (true) { DataRow dr = dt_grid.NewRow(); dr["ItemName"] = "26-30岁"; int count = dt_student.Select("Birthday < '" + new DateTime(thisYear - 25, 1, 1).ToString() + "' and Birthday >= '" + new DateTime(thisYear - 30, 1, 1).ToString() + "'").Length; double percent = totals == 0 ? 0.0000 : Math.Round(1.0 * count / totals, 4); dr["Count"] = count; dr["Percent"] = percent * 100 + "%"; dt_grid.Rows.Add(dr); if (sb_pic_x.Length == 0)//柱状图 横坐标 { sb_pic_x.Append("'" + dr["ItemName"].ToString() + "'"); sb_pic_sum.Append(count); sb_pic_percent.Append(percent); } else { sb_pic_x.Append(",'" + dr["ItemName"].ToString() + "'"); sb_pic_sum.Append("," + count); sb_pic_percent.Append("," + percent); } } if (true) { DataRow dr = dt_grid.NewRow(); dr["ItemName"] = "31-35岁"; int count = dt_student.Select("Birthday < '" + new DateTime(thisYear - 30, 1, 1).ToString() + "' and Birthday >= '" + new DateTime(thisYear - 35, 1, 1).ToString() + "'").Length; double percent = totals == 0 ? 0.0000 : Math.Round(1.0 * count / totals, 4); dr["Count"] = count; dr["Percent"] = percent * 100 + "%"; dt_grid.Rows.Add(dr); if (sb_pic_x.Length == 0)//柱状图 横坐标 { sb_pic_x.Append("'" + dr["ItemName"].ToString() + "'"); sb_pic_sum.Append(count); sb_pic_percent.Append(percent); } else { sb_pic_x.Append(",'" + dr["ItemName"].ToString() + "'"); sb_pic_sum.Append("," + count); sb_pic_percent.Append("," + percent); } } if (true) { DataRow dr = dt_grid.NewRow(); dr["ItemName"] = "36-40岁"; int count = dt_student.Select("Birthday < '" + new DateTime(thisYear - 35, 1, 1).ToString() + "' and Birthday >= '" + new DateTime(thisYear - 40, 1, 1).ToString() + "'").Length; double percent = totals == 0 ? 0.0000 : Math.Round(1.0 * count / totals, 4); dr["Count"] = count; dr["Percent"] = percent * 100 + "%"; dt_grid.Rows.Add(dr); if (sb_pic_x.Length == 0)//柱状图 横坐标 { sb_pic_x.Append("'" + dr["ItemName"].ToString() + "'"); sb_pic_sum.Append(count); sb_pic_percent.Append(percent); } else { sb_pic_x.Append(",'" + dr["ItemName"].ToString() + "'"); sb_pic_sum.Append("," + count); sb_pic_percent.Append("," + percent); } } if (true) { DataRow dr = dt_grid.NewRow(); dr["ItemName"] = "41-45岁"; int count = dt_student.Select("Birthday < '" + new DateTime(thisYear - 40, 1, 1).ToString() + "' and Birthday >= '" + new DateTime(thisYear - 45, 1, 1).ToString() + "'").Length; double percent = totals == 0 ? 0.0000 : Math.Round(1.0 * count / totals, 4); dr["Count"] = count; dr["Percent"] = percent * 100 + "%"; dt_grid.Rows.Add(dr); if (sb_pic_x.Length == 0)//柱状图 横坐标 { sb_pic_x.Append("'" + dr["ItemName"].ToString() + "'"); sb_pic_sum.Append(count); sb_pic_percent.Append(percent); } else { sb_pic_x.Append(",'" + dr["ItemName"].ToString() + "'"); sb_pic_sum.Append("," + count); sb_pic_percent.Append("," + percent); } } if (true) { DataRow dr = dt_grid.NewRow(); dr["ItemName"] = "46-50岁"; int count = dt_student.Select("Birthday < '" + new DateTime(thisYear - 45, 1, 1).ToString() + "' and Birthday >= '" + new DateTime(thisYear - 50, 1, 1).ToString() + "'").Length; double percent = totals == 0 ? 0.0000 : Math.Round(1.0 * count / totals, 4); dr["Count"] = count; dr["Percent"] = percent * 100 + "%"; dt_grid.Rows.Add(dr); if (sb_pic_x.Length == 0)//柱状图 横坐标 { sb_pic_x.Append("'" + dr["ItemName"].ToString() + "'"); sb_pic_sum.Append(count); sb_pic_percent.Append(percent); } else { sb_pic_x.Append(",'" + dr["ItemName"].ToString() + "'"); sb_pic_sum.Append("," + count); sb_pic_percent.Append("," + percent); } } if (true) { DataRow dr = dt_grid.NewRow(); dr["ItemName"] = "50岁以上"; int count = dt_student.Select("Birthday < '" + new DateTime(thisYear - 50, 1, 1).ToString() + "'").Length; double percent = totals == 0 ? 0.0000 : Math.Round(1.0 * count / totals, 4); dr["Count"] = count; dr["Percent"] = percent * 100 + "%"; dt_grid.Rows.Add(dr); if (sb_pic_x.Length == 0)//柱状图 横坐标 { sb_pic_x.Append("'" + dr["ItemName"].ToString() + "'"); sb_pic_sum.Append(count); sb_pic_percent.Append(percent); } else { sb_pic_x.Append(",'" + dr["ItemName"].ToString() + "'"); sb_pic_sum.Append("," + count); sb_pic_percent.Append("," + percent); } } DataRow dr_total = dt_grid.NewRow();//添加一条 总计 dr_total["ItemName"] = "总计"; dr_total["Count"] = totals; dr_total["Percent"] = totals == 0 ? "0.00%" : "100%"; dt_grid.Rows.Add(dr_total); gv_result.DataSource = dt_grid; gv_result.DataBind(); Label_Result.Text = itemCount.ToString(); xAxis = sb_pic_x.ToString(); Data_Sum = "{name: '总人数',data: [" + sb_pic_sum + "]}"; Data_Percent = "{name: '所占比例',data: [" + sb_pic_sum + "]}"; } else { ScriptManager.RegisterStartupScript(UpdatePanel1, this.GetType(), "alter", "layer.alert('数据加载错误!')", true); } } catch (Exception ex) { ScriptManager.RegisterStartupScript(UpdatePanel1, this.GetType(), "alter", "layer.alert('数据加载错误!')", true); } }