add_property.aspx.cs
上传用户:xrffrp
上传日期:2022-03-25
资源大小:22155k
文件大小:3k
源码类别:

OA系统

开发平台:

ASP/ASPX

  1. using System;
  2. using System.Data;
  3. using System.Configuration;
  4. using System.Collections;
  5. using System.Web;
  6. using System.Web.Security;
  7. using System.Web.UI;
  8. using System.Web.UI.WebControls;
  9. using System.Web.UI.WebControls.WebParts;
  10. using System.Web.UI.HtmlControls;
  11. using System.Data.SqlClient;
  12. public partial class web_approvel_flow_add_property : System.Web.UI.Page
  13. {
  14.     protected void Page_Load(object sender, EventArgs e)
  15.     {
  16.         if (!IsPostBack)
  17.         {
  18.             LoginDAO.CheckLogin(Session, Response, "../../", 2);
  19.         }
  20.     }
  21.     protected void BtnOk_Click(object sender, EventArgs e)
  22.     { 
  23.         SqlConnection conn = dbConnection.getConnection();
  24.         conn.Open();
  25.         SqlTransaction tx = conn.BeginTransaction();
  26.         int id = 1;
  27.         try
  28.         {
  29.             SqlCommand cmd = new SqlCommand("select max(id) from OA_FLOW_MAIN", conn);
  30.             cmd.Transaction = tx;
  31.             try
  32.             {
  33.                 id = Convert.ToInt32(cmd.ExecuteScalar().ToString()) + 1;
  34.             }
  35.             catch { }
  36.             if (!DepartmentIds.Value.Equals(""))
  37.             {
  38.                 string cre_user = "";
  39.                 DateMgr mgr = new DateMgr();
  40.                 if (Session["user"] != null)
  41.                 {
  42.                     User user = (User)Session["user"];
  43.                     cre_user = user.Emp_name;
  44.                 }
  45.                 cmd = new SqlCommand("insert into OA_FLOW_MAIN(id, name, description, "+
  46.                     "type, cre_user, cre_date) values ("+id+",'"+TxtName.Text+"','"+TxtDescription.Text+
  47.                     "','" + RbType.SelectedValue + "','" + cre_user + "','" + mgr.getDateTime() + "')", conn);
  48.                 cmd.Transaction = tx;
  49.                 cmd.ExecuteNonQuery();
  50.                 string[] ids = DepartmentIds.Value.Split(new char[] { ',' });
  51.                 int department_id = 1;
  52.                 cmd = new SqlCommand("select max(id) from OA_FLOW_DEPARTMENT", conn);
  53.                 cmd.Transaction = tx;
  54.                 try
  55.                 {
  56.                     department_id = Convert.ToInt32(cmd.ExecuteScalar().ToString())+1;
  57.                 }
  58.                 catch{ }
  59.                 for (int i = 0; i < ids.Length; i++)
  60.                 {
  61.                     cmd = new SqlCommand("insert into OA_FLOW_DEPARTMENT(id, main_id, department_id)"+
  62.                         "values("+department_id+",'"+id+"','"+ids[i]+"')", conn);
  63.                     cmd.Transaction = tx;
  64.                     cmd.ExecuteNonQuery();
  65.                     department_id++;
  66.                 }
  67.             }
  68.             tx.Commit();
  69.         }
  70.         catch (Exception ex)
  71.         {
  72.             Response.Write(ex.Message);
  73.             tx.Rollback();
  74.         }
  75.         conn.Close();
  76.         Session["main"] = id.ToString();
  77.         Response.Write("<script language='javascript'>window.parent.location='flow_index.aspx'</script>");
  78.     }
  79. }