pos_store.aspx.cs
资源名称:web.rar [点击查看]
上传用户:xrffrp
上传日期:2022-03-25
资源大小:22155k
文件大小:10k
源码类别:
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_system_pos_store : System.Web.UI.Page
- {
- protected void Page_Load(object sender, EventArgs e)
- {
- if (!IsPostBack)
- {
- UrlList.DataKeyNames = new string[] { "id" };
- SqlConnection conn = dbConnection.getConnection();
- conn.Open();
- SqlCommand cmd = new SqlCommand("select max(sequence) from OA_POS_URL", conn);
- MaxSequence.Value = cmd.ExecuteScalar().ToString();
- //編輯
- if (Request.QueryString["edit"] != null && Request.QueryString["p_id"] != null)
- {
- BtnAdd.Visible = false;
- TblEdit.Visible = true;
- this.SetValue(Request.QueryString["p_id"]);
- }
- //凍結
- if (Request.QueryString["isFreeze"] != null && Request.QueryString["p_id"] != null)
- {
- cmd = new SqlCommand("update OA_POS_URL set is_freeze='" + Request.QueryString["isFreeze"]
- + "' where id=" + Request.QueryString["p_id"], conn);
- cmd.ExecuteNonQuery();
- }
- //排序
- if (Request.QueryString["act"] != null && Request.QueryString["p_id"] != null)
- {
- this.UpdateSequence(Request.QueryString["act"], Request.QueryString["p_id"]);
- }
- conn.Close();
- }
- }
- protected void UpdateSequence(string act, string id)
- {
- SqlConnection conn = dbConnection.getConnection();
- conn.Open();
- SqlTransaction tx = conn.BeginTransaction();
- try
- {
- SqlCommand cmd = new SqlCommand("select sequence from OA_POS_URL where id=" + id, conn);
- cmd.Transaction = tx;
- int sequence = Convert.ToInt32(cmd.ExecuteScalar());
- if (act.Equals("up"))
- {
- cmd = new SqlCommand("update OA_POS_URL set sequence=sequence+1 where sequence=" + (sequence - 1), conn);
- cmd.Transaction = tx;
- cmd.ExecuteNonQuery();
- cmd = new SqlCommand("update OA_POS_URL set sequence=sequence-1 where id=" + id, conn);
- cmd.Transaction = tx;
- cmd.ExecuteNonQuery();
- }
- if (act.Equals("down"))
- {
- cmd = new SqlCommand("update OA_POS_URL set sequence=sequence-1 where sequence=" + (sequence + 1), conn);
- cmd.Transaction = tx;
- cmd.ExecuteNonQuery();
- cmd = new SqlCommand("update OA_POS_URL set sequence=sequence+1 where id=" + id, conn);
- cmd.Transaction = tx;
- cmd.ExecuteNonQuery();
- }
- tx.Commit();
- }
- catch (Exception ex)
- {
- Response.Write(ex.Message);
- tx.Rollback();
- }
- conn.Close();
- }
- protected void SetValue(string id)
- {
- SqlConnection conn = dbConnection.getConnection();
- conn.Open();
- SqlCommand cmd = new SqlCommand("select name, url, internal_url, is_freeze from OA_POS_URL where id="+id, conn);
- SqlDataReader dr = cmd.ExecuteReader();
- if (dr.Read())
- {
- TxtName.Text = dr["name"].ToString();
- TxtUrl.Text = dr["url"].ToString();
- TxtInternalUrl.Text = dr["internal_url"].ToString();
- DdlFreeze.SelectedValue = dr["is_freeze"].ToString();
- }
- dr.Close();
- conn.Close();
- }
- protected void UrlList_RowDataBound(object sender, GridViewRowEventArgs e)
- {
- //行高亮
- 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", "return confirm('確定删除嗎?')");
- }
- }
- protected void UrlList_RowCreated(object sender, GridViewRowEventArgs e)
- {
- if (e.Row.RowType == DataControlRowType.DataRow)
- {
- string id = UrlList.DataKeys[e.Row.RowIndex].Value.ToString();
- int max_sequence = Convert.ToInt32(MaxSequence.Value);
- SqlConnection conn = dbConnection.getConnection();
- conn.Open();
- SqlCommand cmd = new SqlCommand("select is_freeze, sequence, url, internal_url from OA_POS_URL where id="+
- UrlList.DataKeys[e.Row.RowIndex].Value.ToString(), conn);
- SqlDataReader dr = cmd.ExecuteReader();
- if (dr.Read())
- {
- HyperLink hl = (HyperLink)e.Row.FindControl("HlIsFreeze");
- if (dr["is_freeze"].ToString().Equals("Y"))
- {
- hl.Text = "<font color='red'>是</font>";
- hl.NavigateUrl = "pos_store.aspx?p_id=" + id + "&isFreeze=N";
- }
- else
- {
- hl.Text = "否";
- hl.NavigateUrl = "pos_store.aspx?p_id=" + id + "&isFreeze=Y";
- }
- if (dr["sequence"].ToString().Equals("1"))
- {
- HyperLink BtnUp = (HyperLink)e.Row.FindControl("BtnUp");
- BtnUp.Visible = false;
- HyperLink BtnDown = (HyperLink)e.Row.FindControl("BtnDown");
- BtnDown.NavigateUrl = "pos_store.aspx?p_id=" + id+"&act=down";
- }
- else if (dr["sequence"].ToString().Equals(max_sequence.ToString()))
- {
- HyperLink BtnDown = (HyperLink)e.Row.FindControl("BtnDown");
- BtnDown.Visible = false;
- HyperLink BtnUp = (HyperLink)e.Row.FindControl("BtnUp");
- BtnUp.NavigateUrl = "pos_store.aspx?p_id=" + id + "&act=up";
- }
- else
- {
- HyperLink BtnDown = (HyperLink)e.Row.FindControl("BtnDown");
- BtnDown.NavigateUrl = "pos_store.aspx?p_id=" + id + "&act=down";
- HyperLink BtnUp = (HyperLink)e.Row.FindControl("BtnUp");
- BtnUp.NavigateUrl = "pos_store.aspx?p_id=" + id + "&act=up";
- }
- HyperLink hlName = (HyperLink)e.Row.FindControl("HlName");
- hlName.Target = "_blank";
- string ip = Request.UserHostAddress;
- if (ip.Contains("10.100."))
- {
- hlName.NavigateUrl = dr["internal_url"].ToString();
- }
- else
- {
- hlName.NavigateUrl = dr["url"].ToString();
- }
- LinkButton btn = (LinkButton)e.Row.FindControl("BtnDelete");
- btn.CommandArgument = id;
- }
- dr.Close();
- conn.Close();
- HyperLink hlEdit = (HyperLink)e.Row.FindControl("HlEdit");
- hlEdit.NavigateUrl = "pos_store.aspx?p_id=" + id + "&edit=true";
- }
- }
- protected void BtnOk_Click(object sender, EventArgs e)
- {
- SqlConnection conn = dbConnection.getConnection();
- conn.Open();
- int id = 1;
- SqlCommand cmd = new SqlCommand("select max(id) from OA_POS_URL", conn);
- try
- {
- id = Convert.ToInt32(cmd.ExecuteScalar().ToString()) + 1;
- }
- catch { }
- int sequence = 1;
- cmd = new SqlCommand("select max(sequence) from OA_POS_URL", conn);
- try
- {
- sequence = Convert.ToInt32(cmd.ExecuteScalar().ToString()) + 1;
- }
- catch { }
- if (Request.QueryString["edit"] != null && Request.QueryString["p_id"] != null)
- {
- cmd = new SqlCommand("update OA_POS_URL set name='" + TxtName.Text + "', url='" + TxtUrl.Text +
- "', internal_url='" + TxtInternalUrl.Text + "' where id=" + Request.QueryString["p_id"], conn);
- cmd.ExecuteNonQuery();
- }
- else
- {
- cmd = new SqlCommand("insert into OA_POS_URL(id, name, url, internal_url, sequence)values(" +
- id + ",'" + TxtName.Text + "','" + TxtUrl.Text + "','" + TxtInternalUrl.Text + "', " + sequence + ")", conn);
- cmd.ExecuteNonQuery();
- }
- conn.Close();
- Response.Redirect("pos_store.aspx");
- }
- protected void UrlList_RowCommand(object sender, GridViewCommandEventArgs e)
- {
- if (e.CommandName.Equals("DeleteData"))
- {
- SqlConnection conn = dbConnection.getConnection();
- conn.Open();
- SqlTransaction tx = conn.BeginTransaction();
- try
- {
- string id = e.CommandArgument.ToString();
- SqlCommand cmd = new SqlCommand("select sequence from OA_POS_URL where id=" + id, conn);
- cmd.Transaction = tx;
- string sequence = cmd.ExecuteScalar().ToString();
- cmd = new SqlCommand("update OA_POS_URL set sequence=sequence-1 where sequence>" + sequence, conn);
- cmd.Transaction = tx;
- cmd.ExecuteNonQuery();
- cmd = new SqlCommand("delete from OA_POS_URL where id=" + id, conn);
- cmd.Transaction = tx;
- cmd.ExecuteNonQuery();
- tx.Commit();
- }
- catch (Exception ex)
- {
- Response.Write(ex.Message);
- tx.Rollback();
- }
- conn.Close();
- Response.Redirect("pos_store.aspx");
- }
- }
- protected void BtnAdd_Click(object sender, EventArgs e)
- {
- TblEdit.Visible = true;
- }
- }