department.aspx.cs
资源名称:web.rar [点击查看]
上传用户:xrffrp
上传日期:2022-03-25
资源大小:22155k
文件大小:13k
源码类别:
OA系统
开发平台:
ASP/ASPX
- using System;
- using System.Data;
- using System.Configuration;
- using System.Collections;
- using System.Web;
- using System.Web.Security;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- using System.Web.UI.WebControls.WebParts;
- using System.Web.UI.HtmlControls;
- using System.Data.SqlClient;
- public partial class web_department_department : System.Web.UI.Page
- {
- protected void Page_Load(object sender, EventArgs e)
- {
- LoginDAO.CheckLogin(Session, Response, "../../", 2);
- if (!IsPostBack)
- {
- Panel1.Visible = false;
- Panel2.Visible = false;
- Department_list.DataKeyNames = new string[] { "id" };
- if(Request.QueryString["id"]!=null)
- {
- SqlConnection conn = dbConnection.getConnection();
- conn.Open();
- SqlCommand cmd = new SqlCommand("select name from OA_DEPARTMENT where id=" + Request.QueryString["id"], conn);
- string name = cmd.ExecuteScalar().ToString();
- lblTitle.Text = name + "下级部門列表";
- lblLast_department.Text = name;
- cmd = new SqlCommand("select count(id) from OA_EMPLOYEE where department_id="+Request.QueryString["id"], conn);
- int count = Convert.ToInt32(cmd.ExecuteScalar());
- if (count > 0)
- {
- btnShowEmployee.Text = "本部門員工(" + count + "人)";
- }
- else
- {
- btnShowEmployee.Text = "添加員工";
- }
- conn.Close();
- //顯示本部門資訊
- this.setDepartmentShow(Request.QueryString["id"].ToString());
- //選擇部門按鈕添加javascript
- this.btnSelect.Attributes.Add("onclick", "selectDepartment()");
- }
- }
- }
- protected void Department_list_RowDataBound(object sender, GridViewRowEventArgs e)
- {
- //行高亮
- if (e.Row.RowType == DataControlRowType.DataRow)
- {
- e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor; this.style.backgroundColor='#c8dafa';this.style.cursor='pointer';");
- e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c;");
- }
- }
- protected void Department_list_RowCommand(object sender, GridViewCommandEventArgs e)
- {
- string id = e.CommandArgument.ToString();
- if (e.CommandName.Equals("Delete"))
- {
- if (!id.Equals("0"))
- {
- SqlConnection conn = dbConnection.getConnection();
- conn.Open();
- // 检查该部门是否有子部门
- SqlCommand cmd = new SqlCommand("select count(id) from OA_DEPARTMENT where last_id=" + id, conn);
- int count = Convert.ToInt32(cmd.ExecuteScalar());
- if (count == 0)
- {
- SqlConnection con = dbConnection.getConnection();
- con.Open();
- SqlCommand sqlcom = new SqlCommand("select count(id) from OA_EMPLOYEE where dimission_date='' and department_id=" + id, con);
- int num = Convert.ToInt32(sqlcom.ExecuteScalar());
- if (num == 0)
- {
- //没有子部门, 直接删除
- cmd = new SqlCommand("delete from OA_DEPARTMENT where id=" + id, conn);
- cmd.ExecuteNonQuery();
- }
- else
- {
- Response.Write("<script language='javascript'>alert('该部门下有员工,不能删除!');</script>");
- }
- con.Close();
- }
- else
- {
- //有子部门, 提示先删除子部门
- Response.Write("<script language='javascript'>alert('请先删除下级部门, 再删除上级部门!');</script>");
- }
- conn.Close();
- }
- //刷新樹
- Response.Write("<script language='javascript'>window.parent.frames.tree.location.reload()</script>");
- }
- }
- protected void btnOk_Click(object sender, EventArgs e)
- {
- int flag = 0;
- if (txtName.Text.Trim() == "")
- {
- flag = 1;
- lblName.Text = "部門名稱不能為空!";
- }
- int last_id = 0;
- if (Request.QueryString["id"] != null)
- {
- last_id = Convert.ToInt32(Request.QueryString["id"]);
- }
- //所有必填欄位都已填寫完畢
- if (flag == 0)
- {
- SqlConnection conn = dbConnection.getConnection();
- conn.Open();
- SqlCommand cmd = new SqlCommand("select max(id) from OA_DEPARTMENT", conn);
- int id = Convert.ToInt32(cmd.ExecuteScalar()) + 1;
- int sequence = 0;
- if (last_id == 1)
- {
- cmd = new SqlCommand("select max(sequence) from OA_DEPARTMENT where last_id="+last_id, conn);
- sequence = Convert.ToInt32(cmd.ExecuteScalar()) + 1;
- }
- string user_name = "";
- try
- {
- if (Session["user"] != null && Session["user"].ToString().Equals(""))
- {
- user_name = ((User)Session["user"]).Emp_name;
- }
- DateMgr mgr = new DateMgr();
- string time = mgr.getDateTime();
- string sql = "insert into OA_DEPARTMENT(id, name, code, tel, fax, [function], last_id, sequence,ceng,out)" +
- "values(" + id + ", '" + txtName.Text + "', '" + txtCode.Text + "', '" + txtTel.Text + "', '" + txtFax.Text + "', '" + txtFunction.Text +
- "'," + last_id + ", '" + sequence + "','"+textCeng.Text+"','"+Convert.ToInt32(DropDownList1.SelectedValue)+"')";
- cmd = new SqlCommand(sql, conn);
- cmd.ExecuteNonQuery();
- }
- catch (Exception ex)
- {
- Response.Write(ex.Message);
- }
- conn.Close();
- Department_list.DataBind();
- txtName.Text = "";
- txtCode.Text = "";
- txtFax.Text = "";
- txtTel.Text = "";
- txtFunction.Text = "";
- }
- Panel1.Visible = false;
- Panel2.Visible = false;
- Panel3.Visible = false;
- //刷新樹
- Response.Write("<script language='javascript'>window.parent.frames.tree.location.reload()</script>");
- }
- protected void Department_list_RowUpdating(object sender, GridViewUpdateEventArgs e)
- {
- try
- {
- string id = Department_list.DataKeys[e.RowIndex].Value.ToString();
- string name = ((TextBox)Department_list.Rows[e.RowIndex].Cells[1].Controls[0]).Text.Trim().ToString();
- string code = ((TextBox)Department_list.Rows[e.RowIndex].Cells[3].Controls[0]).Text.Trim().ToString();
- string tel = ((TextBox)Department_list.Rows[e.RowIndex].Cells[4].Controls[0]).Text.Trim().ToString();
- string fax = ((TextBox)Department_list.Rows[e.RowIndex].Cells[5].Controls[0]).Text.Trim().ToString();
- string function = ((TextBox)Department_list.Rows[e.RowIndex].Cells[6].Controls[0]).Text.Trim().ToString();
- string sql = "update OA_DEPARTMENT set name='" + name + "', code='" + code + "', tel='" + tel + "', " +
- "fax='" + fax + "', [function]='" + function + "' where id=" + id;
- SqlConnection conn = dbConnection.getConnection();
- conn.Open();
- SqlCommand cmd = new SqlCommand(sql, conn);
- cmd.ExecuteNonQuery();
- conn.Close();
- Department_list.DataBind();
- }
- catch (Exception ex)
- {
- Response.Write(ex.Message);
- }
- }
- protected void btnEdit_Click(object sender, EventArgs e)
- {
- int flag = 0;
- if (txtName2.Text.Trim() == "")
- {
- flag = 1;
- lblName2.Text = "部門名稱不能為空!";
- }
- int id = 0;
- if (Request.QueryString["id"] != null)
- {
- id = Convert.ToInt32(Request.QueryString["id"]);
- }
- //所有必填欄位都已填寫完畢
- if (flag == 0)
- {
- try
- {
- SqlConnection conn = dbConnection.getConnection();
- conn.Open();
- string sql = "update OA_DEPARTMENT set name='" + txtName2.Text + "', code='" + txtCode2.Text +
- "', tel='" + txtTel2.Text + "', fax='" + txtFax2.Text + "', [function]='" + txtFunction2.Text + "', last_id=" + lastDepartment_id.Value +
- ",ceng="+textCeng2.Text+",out='"+Convert.ToInt32(DropDownList2.SelectedValue)+"' where id=" + id;
- SqlCommand cmd = new SqlCommand(sql, conn);
- cmd.ExecuteNonQuery();
- conn.Close();
- lblTitle.Text = txtName2.Text + "下级部門列表";
- }
- catch (Exception ex)
- {
- Response.Write(ex.Message);
- }
- }
- Panel1.Visible = false;
- Panel2.Visible = false;
- Panel3.Visible = true;
- this.setDepartmentShow(id.ToString());
- //刷新樹
- Response.Write("<script language='javascript'>window.parent.frames.tree.location.reload()</script>");
- }
- protected void btnAddNew_Click(object sender, EventArgs e)
- {
- Panel2.Visible = false;
- Panel1.Visible = true;
- Panel3.Visible = false;
- }
- protected void btnEditDepartment_Click(object sender, EventArgs e)
- {
- Panel2.Visible = true;
- Panel1.Visible = false;
- Panel3.Visible = false;
- if (Request.QueryString["id"] != null)
- {
- try
- {
- string id = Request.QueryString["id"].ToString();
- SqlConnection conn = dbConnection.getConnection();
- conn.Open();
- SqlCommand cmd = new SqlCommand("select last_id, name, code, tel, fax, [function],ceng from OA_DEPARTMENT where id="+id, conn);
- int last_id = 0;
- SqlDataReader dr = cmd.ExecuteReader();
- if (dr.Read())
- {
- last_id = Convert.ToInt32(dr["last_id"]);
- lastDepartment_id.Value = last_id.ToString();
- txtName2.Text = dr["name"].ToString();
- txtCode2.Text = dr["code"].ToString();
- txtTel2.Text = dr["tel"].ToString();
- txtFax2.Text = dr["fax"].ToString();
- txtFunction2.Text = dr["function"].ToString();
- textCeng2.Text=dr["ceng"].ToString();
- }
- dr.Close();
- cmd = new SqlCommand("select name from OA_DEPARTMENT where id=" + last_id, conn);
- txtLastDepartment2.Text = cmd.ExecuteScalar().ToString();
- conn.Close();
- }
- catch (Exception ex)
- {
- Response.Write(ex.Message);
- }
- }
- }
- public void setDepartmentShow(string id)
- {
- try
- {
- SqlConnection conn = dbConnection.getConnection();
- conn.Open();
- SqlCommand cmd = new SqlCommand("select name, code, last_id, tel, fax, [function],ceng,out from OA_DEPARTMENT where id="+id, conn);
- SqlDataReader dr = cmd.ExecuteReader();
- int last_id = 0;
- if (dr.Read())
- {
- lblDepartmentName.Text = dr["name"].ToString();
- lblDepartmentCode.Text = dr["code"].ToString();
- last_id = Convert.ToInt32(dr["last_id"]);
- lblTel.Text = dr["tel"].ToString();
- lblFax.Text = dr["fax"].ToString();
- lblFunction.Text = dr["function"].ToString();
- lblCeng.Text = dr["ceng"].ToString();
- int var = Convert.ToInt32(dr["out"]);
- if (var == 1)
- {
- lblcompany.Text = "津味";
- }
- else if (var == 2)
- {
- lblcompany.Text = "和夏";
- }
- else
- {
- lblcompany.Text = "";
- }
- }
- dr.Close();
- cmd = new SqlCommand("select name from OA_DEPARTMENT where id="+last_id, conn);
- lblLastDepartment.Text = cmd.ExecuteScalar().ToString();
- conn.Close();
- }
- catch (Exception ex)
- {
- Response.Write(ex.Message);
- }
- }
- protected void btnShow_Click(object sender, EventArgs e)
- {
- Panel1.Visible = false;
- Panel2.Visible = false;
- Panel3.Visible = true;
- }
- protected void btnShowEmployee_Click(object sender, EventArgs e)
- {
- if (Request.QueryString["id"] != null)
- {
- Response.Redirect("../employee/employee_list.aspx?department_id="+Request.QueryString["id"]+"&department=true");
- }
- }
- }