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

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_system_pos_store : System.Web.UI.Page
  13. {
  14.     protected void Page_Load(object sender, EventArgs e)
  15.     {
  16.         if (!IsPostBack)
  17.         {
  18.             UrlList.DataKeyNames = new string[] { "id" };
  19.             SqlConnection conn = dbConnection.getConnection();
  20.             conn.Open();
  21.             SqlCommand cmd = new SqlCommand("select max(sequence) from OA_POS_URL", conn);
  22.             MaxSequence.Value = cmd.ExecuteScalar().ToString();
  23.             //編輯
  24.             if (Request.QueryString["edit"] != null && Request.QueryString["p_id"] != null)
  25.             {
  26.                 BtnAdd.Visible = false;
  27.                 TblEdit.Visible = true;
  28.                 this.SetValue(Request.QueryString["p_id"]);
  29.             }
  30.             //凍結
  31.             if (Request.QueryString["isFreeze"] != null && Request.QueryString["p_id"] != null)
  32.             {
  33.                 cmd = new SqlCommand("update OA_POS_URL set is_freeze='" + Request.QueryString["isFreeze"] 
  34.                     + "' where id=" + Request.QueryString["p_id"], conn);
  35.                 cmd.ExecuteNonQuery();
  36.             }
  37.             //排序
  38.             if (Request.QueryString["act"] != null && Request.QueryString["p_id"] != null)
  39.             {
  40.                 this.UpdateSequence(Request.QueryString["act"], Request.QueryString["p_id"]);
  41.             }
  42.             conn.Close();
  43.         }
  44.     }
  45.     protected void UpdateSequence(string act, string id)
  46.     {
  47.         SqlConnection conn = dbConnection.getConnection();
  48.         conn.Open();
  49.         SqlTransaction tx = conn.BeginTransaction();
  50.         try
  51.         {
  52.             SqlCommand cmd = new SqlCommand("select sequence from OA_POS_URL where id=" + id, conn);
  53.             cmd.Transaction = tx;
  54.             int sequence = Convert.ToInt32(cmd.ExecuteScalar());
  55.             if (act.Equals("up"))
  56.             {
  57.                 cmd = new SqlCommand("update OA_POS_URL set sequence=sequence+1 where sequence=" + (sequence - 1), conn);
  58.                 cmd.Transaction = tx;
  59.                 cmd.ExecuteNonQuery();
  60.                 cmd = new SqlCommand("update OA_POS_URL set sequence=sequence-1 where id=" + id, conn);
  61.                 cmd.Transaction = tx;
  62.                 cmd.ExecuteNonQuery();
  63.             }
  64.             if (act.Equals("down"))
  65.             {
  66.                 cmd = new SqlCommand("update OA_POS_URL set sequence=sequence-1 where sequence=" + (sequence + 1), conn);
  67.                 cmd.Transaction = tx;
  68.                 cmd.ExecuteNonQuery();
  69.                 cmd = new SqlCommand("update OA_POS_URL set sequence=sequence+1 where id=" + id, conn);
  70.                 cmd.Transaction = tx;
  71.                 cmd.ExecuteNonQuery();
  72.             }
  73.             tx.Commit();
  74.         }
  75.         catch (Exception ex)
  76.         {
  77.             Response.Write(ex.Message);
  78.             tx.Rollback();
  79.         }
  80.         conn.Close();
  81.     }
  82.     protected void SetValue(string id)
  83.     {
  84.         SqlConnection conn = dbConnection.getConnection();
  85.         conn.Open();
  86.         SqlCommand cmd = new SqlCommand("select name, url, internal_url, is_freeze from OA_POS_URL where id="+id, conn);
  87.         SqlDataReader dr = cmd.ExecuteReader();
  88.         if (dr.Read())
  89.         {
  90.             TxtName.Text = dr["name"].ToString();
  91.             TxtUrl.Text = dr["url"].ToString();
  92.             TxtInternalUrl.Text = dr["internal_url"].ToString();
  93.             DdlFreeze.SelectedValue = dr["is_freeze"].ToString();
  94.         }
  95.         dr.Close();
  96.         conn.Close();
  97.     }
  98.     protected void UrlList_RowDataBound(object sender, GridViewRowEventArgs e)
  99.     {
  100.         //行高亮
  101.         if (e.Row.RowType == DataControlRowType.DataRow)
  102.         {
  103.             e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor; this.style.backgroundColor='#c8dafa';");
  104.             e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c;");
  105.             e.Row.Cells[e.Row.Cells.Count - 1].Attributes.Add("onclick", "return confirm('確定删除嗎?')");
  106.         }
  107.     }
  108.     protected void UrlList_RowCreated(object sender, GridViewRowEventArgs e)
  109.     {
  110.         if (e.Row.RowType == DataControlRowType.DataRow)
  111.         {
  112.             string id = UrlList.DataKeys[e.Row.RowIndex].Value.ToString();
  113.             int max_sequence = Convert.ToInt32(MaxSequence.Value);
  114.             SqlConnection conn = dbConnection.getConnection();
  115.             conn.Open();
  116.             SqlCommand cmd = new SqlCommand("select is_freeze, sequence, url, internal_url from OA_POS_URL where id="+
  117.                 UrlList.DataKeys[e.Row.RowIndex].Value.ToString(), conn);
  118.             SqlDataReader dr = cmd.ExecuteReader();
  119.             if (dr.Read())
  120.             {
  121.                 HyperLink hl = (HyperLink)e.Row.FindControl("HlIsFreeze");
  122.                 if (dr["is_freeze"].ToString().Equals("Y"))
  123.                 {
  124.                     hl.Text = "<font color='red'>是</font>";
  125.                     hl.NavigateUrl = "pos_store.aspx?p_id=" + id + "&isFreeze=N";
  126.                 }
  127.                 else 
  128.                 {
  129.                     hl.Text = "否";
  130.                     hl.NavigateUrl = "pos_store.aspx?p_id=" + id + "&isFreeze=Y";
  131.                 }
  132.                 if (dr["sequence"].ToString().Equals("1"))
  133.                 {
  134.                     HyperLink BtnUp = (HyperLink)e.Row.FindControl("BtnUp");
  135.                     BtnUp.Visible = false;
  136.                     HyperLink BtnDown = (HyperLink)e.Row.FindControl("BtnDown");
  137.                     BtnDown.NavigateUrl = "pos_store.aspx?p_id=" + id+"&act=down";
  138.                 }
  139.                 else if (dr["sequence"].ToString().Equals(max_sequence.ToString()))
  140.                 {
  141.                     HyperLink BtnDown = (HyperLink)e.Row.FindControl("BtnDown");
  142.                     BtnDown.Visible = false;
  143.                     HyperLink BtnUp = (HyperLink)e.Row.FindControl("BtnUp");
  144.                     BtnUp.NavigateUrl = "pos_store.aspx?p_id=" + id + "&act=up";
  145.                 }
  146.                 else
  147.                 {
  148.                     HyperLink BtnDown = (HyperLink)e.Row.FindControl("BtnDown");
  149.                     BtnDown.NavigateUrl = "pos_store.aspx?p_id=" + id + "&act=down";
  150.                     HyperLink BtnUp = (HyperLink)e.Row.FindControl("BtnUp");
  151.                     BtnUp.NavigateUrl = "pos_store.aspx?p_id=" + id + "&act=up";
  152.                 }
  153.                 HyperLink hlName = (HyperLink)e.Row.FindControl("HlName");
  154.                 hlName.Target = "_blank";
  155.                 string ip = Request.UserHostAddress;
  156.                 if (ip.Contains("10.100."))
  157.                 {
  158.                     hlName.NavigateUrl = dr["internal_url"].ToString();
  159.                 }
  160.                 else
  161.                 {
  162.                     hlName.NavigateUrl = dr["url"].ToString();
  163.                 }
  164.                 LinkButton btn = (LinkButton)e.Row.FindControl("BtnDelete");
  165.                 btn.CommandArgument = id;
  166.             }
  167.             dr.Close();
  168.             conn.Close();
  169.             HyperLink hlEdit = (HyperLink)e.Row.FindControl("HlEdit");
  170.             hlEdit.NavigateUrl = "pos_store.aspx?p_id=" + id + "&edit=true";
  171.         }
  172.     }
  173.     protected void BtnOk_Click(object sender, EventArgs e)
  174.     {
  175.         SqlConnection conn = dbConnection.getConnection();
  176.         conn.Open();
  177.         int id = 1;
  178.         SqlCommand cmd = new SqlCommand("select max(id) from OA_POS_URL", conn);
  179.         try
  180.         {
  181.             id = Convert.ToInt32(cmd.ExecuteScalar().ToString()) + 1;
  182.         }
  183.         catch { }
  184.         
  185.         int sequence = 1;
  186.         cmd = new SqlCommand("select max(sequence) from OA_POS_URL", conn);
  187.         try
  188.         {
  189.             sequence = Convert.ToInt32(cmd.ExecuteScalar().ToString()) + 1;
  190.         }
  191.         catch { }
  192.         if (Request.QueryString["edit"] != null && Request.QueryString["p_id"] != null)
  193.         {
  194.             cmd = new SqlCommand("update OA_POS_URL set name='" + TxtName.Text + "', url='" + TxtUrl.Text +
  195.                 "', internal_url='" + TxtInternalUrl.Text + "' where id=" + Request.QueryString["p_id"], conn);
  196.             cmd.ExecuteNonQuery();
  197.         }
  198.         else
  199.         {
  200.             cmd = new SqlCommand("insert into OA_POS_URL(id, name, url, internal_url, sequence)values(" +
  201.                 id + ",'" + TxtName.Text + "','" + TxtUrl.Text + "','" + TxtInternalUrl.Text + "', " + sequence + ")", conn);
  202.             cmd.ExecuteNonQuery();
  203.         }
  204.         conn.Close();
  205.         Response.Redirect("pos_store.aspx");
  206.     }
  207.     protected void UrlList_RowCommand(object sender, GridViewCommandEventArgs e)
  208.     {
  209.         if (e.CommandName.Equals("DeleteData"))
  210.         {
  211.             SqlConnection conn = dbConnection.getConnection();
  212.             conn.Open();
  213.             SqlTransaction tx = conn.BeginTransaction();
  214.             try
  215.             {
  216.                 string id = e.CommandArgument.ToString();
  217.                 SqlCommand cmd = new SqlCommand("select sequence from OA_POS_URL where id=" + id, conn);
  218.                 cmd.Transaction = tx;
  219.                 string sequence = cmd.ExecuteScalar().ToString();
  220.                 cmd = new SqlCommand("update OA_POS_URL set sequence=sequence-1 where sequence>" + sequence, conn);
  221.                 cmd.Transaction = tx;
  222.                 cmd.ExecuteNonQuery();
  223.                 cmd = new SqlCommand("delete from OA_POS_URL where id=" + id, conn);
  224.                 cmd.Transaction = tx;
  225.                 cmd.ExecuteNonQuery();
  226.                 tx.Commit();
  227.             }
  228.             catch (Exception ex)
  229.             {
  230.                 Response.Write(ex.Message);
  231.                 tx.Rollback();
  232.             }
  233.             conn.Close();
  234.             Response.Redirect("pos_store.aspx");
  235.         }
  236.     }
  237.     protected void BtnAdd_Click(object sender, EventArgs e)
  238.     {
  239.         TblEdit.Visible = true;
  240.     }
  241. }