fair_flow.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_personnel_curricula_vitae_fair_flow : System.Web.UI.Page
- {
- protected void Page_Load(object sender, EventArgs e)
- {
- if (!IsPostBack)
- {
- LoginDAO.CheckLogin(Session, Response, "../../", 2);
- FlowWizard.ActiveStepIndex = 0;
- if (Session["p_department_id"] != null)
- {
- DepartmentId.Value = Session["p_department_id"].ToString();
- SqlConnection conn = dbConnection.getConnection();
- conn.Open();
- SqlCommand cmd = new SqlCommand("select name from OA_DEPARTMENT where id=" + DepartmentId.Value, conn);
- try
- {
- TxtDepartment.Text = cmd.ExecuteScalar().ToString();
- }
- catch { }
- conn.Close();
- }
- DetailList.DataKeyNames = new string[] { "id" };
- }
- }
- protected void FlowWizard_NextButtonClick(object sender, WizardNavigationEventArgs e)
- {
- if (FlowWizard.ActiveStepIndex == 0)
- {
- int flag = 0;
- ArrayList position_ids = new ArrayList();
- for (int i = 0; i < ChkPosition.Items.Count; i++)
- {
- if (ChkPosition.Items[i].Selected)
- {
- flag = 1;
- position_ids.Add(ChkPosition.Items[i].Value.ToString());
- }
- }
- if (flag == 0)
- {
- Response.Write("<script language='javascript'>alert('請選擇職位');</script>");
- e.Cancel = true;
- }
- else
- {
- SqlConnection conn = dbConnection.getConnection();
- conn.Open();
- SqlTransaction tx = conn.BeginTransaction();
- try
- {
- if (MainId.Value.Equals("0"))
- {
- //新增
- int main_id = 1;
- SqlCommand cmd = new SqlCommand("select max(id) from OA_FAIR_FLOW_MAIN", conn);
- cmd.Transaction = tx;
- try
- {
- main_id = Convert.ToInt32(cmd.ExecuteScalar().ToString()) + 1;
- }
- catch { }
- cmd = new SqlCommand("insert into OA_FAIR_FLOW_MAIN(id, department_id)values(" + main_id
- + "," + DepartmentId.Value + ")", conn);
- cmd.Transaction = tx;
- cmd.ExecuteNonQuery();
- for (int i = 0; i < position_ids.Count; i++)
- {
- cmd = new SqlCommand("insert into OA_FAIR_FLOW_POSITION(main_id, position_id)values(" +
- main_id + "," + position_ids[i] + ")", conn);
- cmd.Transaction = tx;
- cmd.ExecuteNonQuery();
- }
- tx.Commit();
- MainId.Value = main_id.ToString();
- }
- else
- {
- //编辑
- SqlCommand cmd = new SqlCommand("delete from OA_FAIR_FLOW_POSITION where main_id=" + MainId.Value, conn);
- cmd.Transaction = tx;
- cmd.ExecuteNonQuery();
- for (int i = 0; i < position_ids.Count; i++)
- {
- cmd = new SqlCommand("insert into OA_FAIR_FLOW_POSITION(main_id, position_id)values(" +
- MainId.Value + "," + position_ids[i] + ")", conn);
- cmd.Transaction = tx;
- cmd.ExecuteNonQuery();
- }
- tx.Commit();
- }
- }
- catch (Exception ex)
- {
- tx.Rollback();
- Response.Write(ex.Message);
- }
- conn.Close();
- DetailList.DataKeyNames = new string[] { "id" };
- DetailList.DataBind();
- this.SetEmpty();
- }
- }
- }
- protected void BtnSaveDetail_Click(object sender, EventArgs e)
- {
- if (this.CheckValidate() && !MainId.Value.Equals("0"))
- {
- SqlConnection conn = dbConnection.getConnection();
- conn.Open();
- if (DetailId.Value.Equals("0"))
- {
- int detail_id = 1;
- SqlCommand cmd = new SqlCommand("select max(id) from OA_FAIR_FLOW_DETAIL", conn);
- try
- {
- detail_id = Convert.ToInt32(cmd.ExecuteScalar().ToString()) + 1;
- }
- catch { }
- cmd = new SqlCommand("insert into OA_FAIR_FLOW_DETAIL(id, main_id, operator_id, number) values (" +
- detail_id + "," + MainId.Value + ",'" + OperatorId.Value + "','" + TxtNumber.Text + "')", conn);
- cmd.ExecuteNonQuery();
- }
- else
- {
- SqlCommand cmd = new SqlCommand("update OA_FAIR_FLOW_DETAIL set operator_id='" + OperatorId.Value + "', " +
- "number='" + TxtNumber.Text + "' where id=" + DetailId.Value, conn);
- cmd.ExecuteNonQuery();
- }
- conn.Close();
- this.SetEmpty();
- DetailList.DataBind();
- MainList.DataBind();
- }
- }
- protected void SetEmpty()
- {
- TxtNumber.Text = "";
- OperatorId.Value = "0";
- TxtOperator.Text = "";
- DetailId.Value = "0";
- LblError.Text = "";
- }
- protected bool CheckValidate()
- {
- if (TxtNumber.Text.Trim().Equals(""))
- {
- LblError.Text = "編號不能為空";
- return false;
- }
- else
- {
- try
- {
- int number = Convert.ToInt32(TxtNumber.Text.Trim());
- }
- catch
- {
- LblError.Text = "編號必須為數字";
- return false;
- }
- }
- if (OperatorId.Value.Equals("0"))
- {
- LblError.Text = "辦理人不能為空";
- return false;
- }
- return true;
- }
- protected void DetailList_RowDataBound(object sender, GridViewRowEventArgs e)
- {
- //
- if (e.Row.RowType == DataControlRowType.DataRow)
- {
- e.Row.Cells[e.Row.Cells.Count - 1].Attributes.Add("onclick", "return confirm('確定删除嗎?')");
- }
- }
- protected void DetailList_RowCreated(object sender, GridViewRowEventArgs e)
- {
- if (e.Row.RowType == DataControlRowType.DataRow)
- {
- try
- {
- LinkButton btn = (LinkButton)e.Row.FindControl("LbEdit");
- btn.CommandArgument = DetailList.DataKeys[e.Row.RowIndex].Value.ToString();
- }
- catch
- {
- }
- }
- }
- protected void DetailList_RowCommand(object sender, GridViewCommandEventArgs e)
- {
- if (e.CommandName.Equals("EditData"))
- {
- string id = e.CommandArgument.ToString();
- this.SetValue(id);
- }
- }
- protected void SetValue(string id)
- {
- SqlConnection conn = dbConnection.getConnection();
- conn.Open();
- SqlCommand cmd = new SqlCommand("select d.number, d.operator_id, e.emp_name, e.emp_no, p.name position " +
- "from OA_FAIR_FLOW_DETAIL d inner join OA_EMPLOYEE e on d.operator_id=e.id inner join " +
- "OA_EMPLOYEE_POSITION p on e.position=p.id where d.id=" + id, conn);
- SqlDataReader dr = cmd.ExecuteReader();
- if (dr.Read())
- {
- TxtNumber.Text = dr["number"].ToString();
- OperatorId.Value = dr["operator_id"].ToString();
- TxtOperator.Text = dr["emp_no"].ToString() + " " + dr["emp_name"].ToString() + dr["position"].ToString();
- DetailId.Value = id;
- }
- dr.Close();
- conn.Close();
- }
- protected void FlowWizard_FinishButtonClick(object sender, WizardNavigationEventArgs e)
- {
- SqlConnection conn = dbConnection.getConnection();
- conn.Open();
- if (!MainId.Value.Equals("0"))
- {
- SqlCommand cmd = new SqlCommand("select count(id) from OA_FAIR_FLOW_DETAIL where main_id=" + MainId.Value, conn);
- int count = Convert.ToInt32(cmd.ExecuteScalar().ToString());
- if (count == 0)
- {
- Response.Write("<script language='javascript'>alert('請至少添加一個流程')</script>");
- e.Cancel = true;
- }
- else
- {
- MainList.DataBind();
- FlowWizard.Visible = false;
- }
- }
- else
- {
- MainList.DataBind();
- FlowWizard.Visible = false;
- }
- conn.Close();
- }
- protected void MainList_RowCreated(object sender, GridViewRowEventArgs e)
- {
- if (e.Row.RowType == DataControlRowType.DataRow)
- {
- string id = MainList.DataKeys[e.Row.RowIndex].Value.ToString();
- SqlConnection conn = dbConnection.getConnection();
- conn.Open();
- string position = "";
- string position_ids = "";
- SqlCommand cmd = new SqlCommand("select f.position_id, p.name position from OA_FAIR_FLOW_POSITION f inner join " +
- "OA_EMPLOYEE_POSITION p on f.position_id=p.id where f.main_id=" + id, conn);
- SqlDataReader dr = cmd.ExecuteReader();
- while (dr.Read())
- {
- position_ids = position_ids + dr["position_id"].ToString() + ",";
- position = position + dr["position"].ToString() + ";";
- }
- dr.Close();
- if (position.Length > 0)
- {
- LinkButton btn = (LinkButton)e.Row.FindControl("LbPosition");
- btn.Text = position.Substring(0, position.Length - 1);
- btn.CommandArgument = MainList.DataKeys[e.Row.RowIndex].Value.ToString();
- }
- PositionIds.Value = position_ids;
- conn.Close();
- }
- }
- protected void MainList_RowCommand(object sender, GridViewCommandEventArgs e)
- {
- if (e.CommandName.Equals("EditData"))
- {
- for (int i = 0; i < ChkPosition.Items.Count; i++)
- {
- ChkPosition.Items[i].Selected = false;
- }
- string id = e.CommandArgument.ToString();
- MainId.Value = id;
- SqlConnection conn = dbConnection.getConnection();
- conn.Open();
- SqlCommand cmd = new SqlCommand("select position_id from OA_FAIR_FLOW_POSITION where main_id=" + id, conn);
- SqlDataReader dr = cmd.ExecuteReader();
- while (dr.Read())
- {
- string position_id = dr["position_id"].ToString();
- for (int i = 0; i < ChkPosition.Items.Count; i++)
- {
- if (ChkPosition.Items[i].Value.Equals(position_id))
- {
- ChkPosition.Items[i].Selected = true;
- }
- }
- }
- dr.Close();
- conn.Close();
- FlowWizard.ActiveStepIndex = 0;
- FlowWizard.Visible = true;
- }
- }
- protected void MainList_RowDataBound(object sender, GridViewRowEventArgs e)
- {
- if (e.Row.RowType == DataControlRowType.DataRow)
- {
- e.Row.Cells[e.Row.Cells.Count - 1].Attributes.Add("onclick", "return confirm('確定删除嗎?')");
- }
- }
- protected void BtnAdd_Click(object sender, EventArgs e)
- {
- this.SetEmpty();
- }
- protected void BtnAddMain_Click(object sender, EventArgs e)
- {
- this.SetEmpty();
- FlowWizard.Visible = true;
- FlowWizard.ActiveStepIndex = 0;
- MainId.Value = "0";
- for (int i = 0; i < ChkPosition.Items.Count; i++)
- {
- ChkPosition.Items[i].Selected = false;
- }
- }
- }