department_main.aspx.cs
资源名称:web.rar [点击查看]
上传用户:xrffrp
上传日期:2022-03-25
资源大小:22155k
文件大小:6k
源码类别:
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_main : System.Web.UI.Page
- {
- protected void Page_Load(object sender, EventArgs e)
- {
- LoginDAO.CheckLogin(Session, Response, "../../", 2);
- int row = Department_list.Rows.Count;
- if (Request.QueryString["act"] != null && Request.QueryString["id"]!=null)
- {
- this.updateSequence(Request.QueryString["act"].ToString(), Convert.ToInt32(Request.QueryString["id"]));
- }
- HyperLink link = (HyperLink)Department_list.Rows[0].Cells[1].FindControl("linkUp");
- link.Visible = false;
- link = (HyperLink)Department_list.Rows[row - 1].Cells[1].FindControl("linkDown");
- link.Visible = false;
- for (int i = 0; i < row; i++)
- {
- String id = Department_list.Rows[i].Cells[2].Text;
- HyperLink link_u = (HyperLink)Department_list.Rows[i].Cells[1].FindControl("linkUp");
- link_u.NavigateUrl = "department_main.aspx?act=up&id=" + id;
- HyperLink link_d = (HyperLink)Department_list.Rows[i].Cells[1].FindControl("linkDown");
- link_d.NavigateUrl = "department_main.aspx?act=down&id=" + id;
- }
- //Department_list.Columns[2].Visible = false;
- if (!IsPostBack)
- {
- SqlConnection conn = dbConnection.getConnection();
- conn.Open();
- SqlCommand cmd = new SqlCommand("select name from OA_DEPARTMENT where id=1", conn);
- string name = cmd.ExecuteScalar().ToString();
- lblLast_department.Text = name;
- }
- }
- //更新部門排序
- public void updateSequence(string act, int id)
- {
- try
- {
- SqlConnection conn = dbConnection.getConnection();
- conn.Open();
- int sequence = 0;
- SqlCommand cmd = new SqlCommand("select sequence from OA_DEPARTMENT where id="+id, conn);
- sequence = Convert.ToInt32(cmd.ExecuteScalar());
- if(act.Equals("up"))
- {
- cmd = new SqlCommand("update OA_DEPARTMENT set sequence=sequence+1 where sequence=" + (sequence - 1), conn);
- cmd.ExecuteNonQuery();
- cmd = new SqlCommand("update OA_DEPARTMENT set sequence=sequence-1 where id=" + id, conn);
- cmd.ExecuteNonQuery();
- }
- else
- {
- cmd = new SqlCommand("update OA_DEPARTMENT set sequence=sequence-1 where sequence=" + (sequence + 1), conn);
- cmd.ExecuteNonQuery();
- cmd = new SqlCommand("update OA_DEPARTMENT set sequence=sequence+1 where id=" + id, conn);
- cmd.ExecuteNonQuery();
- }
- conn.Close();
- SqlDataSource1.SelectCommand = "select id, name from OA_DEPARTMENT where last_id=1 order by sequence";
- Department_list.DataBind();
- }
- catch(Exception e)
- {
- Response.Write(e.Message);
- }
- }
- protected void Department_list_RowDataBound(object sender, GridViewRowEventArgs e)
- {
- //判断是否是DataRow,以防止鼠标经过Header也有效果
- if (e.Row.RowType == DataControlRowType.DataRow)
- {
- e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor; this.style.backgroundColor='#c8dafa';");
- e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c;");
- //删除键在最后一列
- e.Row.Cells[e.Row.Cells.Count - 1].Attributes.Add("onclick", "DeleteConfirm(event)");
- }
- }
- protected void btnOk_Click(object sender, EventArgs e)
- {
- int flag = 0;
- if (txtName.Text == "")
- {
- flag = 1;
- lblName.Text = "部門名稱不能為空";
- }
- //所有數據已填完, 添加部門
- 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;
- cmd = new SqlCommand("select max(sequence) from OA_DEPARTMENT where last_id=1", 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, cre_user, cre_date)" +
- "values(" + id + ", '" + txtName.Text + "', '" + txtCode.Text + "', '" + txtTel.Text + "', '" + txtFax.Text + "', '" + txtFunction.Text +
- "'," + 1 + ", " + sequence + ", '" + user_name + "', '" + time + "')";
- 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 = "";
- //刷新樹
- Response.Write("<script language='javascript'>window.parent.frames.tree.location.reload()</script>");
- }
- }
- }