document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. using System;
  2. using System.Web.UI;
  3. using System.Web.UI.WebControls;
  4. using System.Data.SqlClient;
  5. using System.Configuration;
  6. using Telerik.Web.UI;
  7. using System.Data;
  8.  
  9. namespace GestaoStocksFap
  10. {
  11.  
  12. public partial class ArmEstruturas : System.Web.UI.Page
  13. {
  14.  
  15. protected void Page_Load(object sender, EventArgs e)
  16. {
  17.  
  18. }
  19.  
  20. protected void FillGrid()
  21. {
  22. SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["GestaoStocksFap"].ConnectionString);
  23. con.Open();
  24.  
  25. Label query = (Label)LoginView1.FindControl("query");
  26.  
  27.  
  28. string GetDadosTabela = query.Text;
  29.  
  30. SqlDataAdapter busca = new SqlDataAdapter(GetDadosTabela, con);
  31.  
  32. try
  33. {
  34.  
  35. GridView GridView1 = (GridView)LoginView1.FindControl("GridView1");
  36.  
  37. DataSet ds = new DataSet();
  38. busca.Fill(ds);
  39. con.Close();
  40.  
  41. GridView1.DataSource = ds;
  42. GridView1.DataBind();
  43.  
  44. }
  45. catch (Exception erro)
  46. {
  47. Response.Write(erro.Message);
  48. }
  49. }
  50.  
  51.  
  52. protected void RadButton1_Click(object sender, EventArgs e)
  53. {
  54. RadWindow RadWindow1 = new RadWindow();
  55. RadWindow1 = (RadWindow)LoginView1.FindControl("RadWindow1");
  56.  
  57. string script = "function f(){$find(\\"" + RadWindow1.ClientID + "\\").show(); Sys.Application.remove_load(f);} Sys.Application.add_load(f);";
  58. ScriptManager.RegisterStartupScript(Page, Page.GetType(), "key", script, true);
  59. }
  60.  
  61.  
  62. protected void Button1_Click(object sender, EventArgs e)
  63. {
  64. Button Button1 = (Button)LoginView1.FindControl("Button1");
  65. Button BtnComp = (Button)LoginView1.FindControl("BtnComp");
  66. Button BtnEst = (Button)LoginView1.FindControl("BtnEst");
  67. Button BtnPrat = (Button)LoginView1.FindControl("BtnPrat");
  68. Button BtnCol = (Button)LoginView1.FindControl("BtnCol");
  69. HiddenField h1 = (HiddenField)LoginView1.FindControl("switch");
  70.  
  71.  
  72. if (h1.Value == "On")
  73. {
  74. Button1.Text = "Adicionar estruturas";
  75. BtnComp.Visible = false;
  76. BtnEst.Visible = false;
  77. BtnPrat.Visible = false;
  78. BtnCol.Visible = false;
  79. h1.Value = "Off";
  80. }
  81. else
  82. {
  83. Button1.Text = "Fechar";
  84. BtnComp.Visible = true;
  85. BtnEst.Visible = true;
  86. BtnPrat.Visible = true;
  87. BtnCol.Visible = true;
  88. h1.Value = "On";
  89. }
  90. }
  91.  
  92. protected void BtnEst_Click(object sender, EventArgs e)
  93. {
  94. RadWindow RadWindow2 = new RadWindow();
  95. RadWindow2 = (RadWindow)LoginView1.FindControl("RadWindow2");
  96.  
  97. string script = "function f(){$find(\\"" + RadWindow2.ClientID + "\\").show(); Sys.Application.remove_load(f);} Sys.Application.add_load(f);";
  98. ScriptManager.RegisterStartupScript(Page, Page.GetType(), "key", script, true);
  99. }
  100.  
  101. protected void BtnPrat_Click(object sender, EventArgs e)
  102. {
  103. RadWindow RadWindow3 = new RadWindow();
  104. RadWindow3 = (RadWindow)LoginView1.FindControl("RadWindow3");
  105.  
  106. string script = "function f(){$find(\\"" + RadWindow3.ClientID + "\\").show(); Sys.Application.remove_load(f);} Sys.Application.add_load(f);";
  107. ScriptManager.RegisterStartupScript(Page, Page.GetType(), "key", script, true);
  108. }
  109.  
  110. protected void BtnCol_Click(object sender, EventArgs e)
  111. {
  112. RadWindow RadWindow4 = new RadWindow();
  113. RadWindow4 = (RadWindow)LoginView1.FindControl("RadWindow4");
  114.  
  115. string script = "function f(){$find(\\"" + RadWindow4.ClientID + "\\").show(); Sys.Application.remove_load(f);} Sys.Application.add_load(f);";
  116. ScriptManager.RegisterStartupScript(Page, Page.GetType(), "key", script, true);
  117. }
  118.  
  119. protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
  120. {
  121. Label LblHeader = (Label)LoginView1.FindControl("LblHeader");
  122. DropDownList DropDownList1 = (DropDownList)LoginView1.FindControl("DropDownList1");
  123. GridView GridView1 = (GridView)LoginView1.FindControl("GridView1");
  124.  
  125. LblHeader.Text = DropDownList1.SelectedValue;
  126.  
  127. if (DropDownList1.SelectedValue == "Escolher")
  128. {
  129. GridView1.Visible = false;
  130. }
  131.  
  132. if (DropDownList1.SelectedValue == "Compartimento")
  133. {
  134. GridView1.Visible = true;
  135.  
  136. Label query = (Label)LoginView1.FindControl("query");
  137. Label ddl = (Label)LoginView1.FindControl("ddl");
  138. Label update = (Label)LoginView1.FindControl("update");
  139. Label delete = (Label)LoginView1.FindControl("delete");
  140.  
  141. query.Text = "SELECT distinct Compartimento.CompId AS IdA, Compartimento.DesigArm, Compartimento.Descricao, Armazem.Designacao AS DesigFk FROM Compartimento,Armazem WHERE Compartimento.ArmazemId = Armazem.ArmazemId";
  142.  
  143. ddl.Text = "SELECT distinct Armazem.ArmazemId AS Id, Armazem.Designacao FROM Armazem";
  144.  
  145. update.Text = "UPDATE Compartimento SET DesigArm=@DesigArm, Descricao=@Descricao, ArmazemId=@DesigFk WHERE CompId=@CompId";
  146.  
  147. FillGrid();
  148. }
  149. }
  150.  
  151. protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
  152. {
  153. GridView GridView1 = (GridView)LoginView1.FindControl("GridView1");
  154. GridView1.PageIndex = e.NewPageIndex;
  155. FillGrid();
  156. }
  157.  
  158. protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
  159. {
  160. GridView GridView1 = (GridView)LoginView1.FindControl("GridView1");
  161. GridView1.EditIndex = -1;
  162. FillGrid();
  163. }
  164.  
  165. protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
  166. {
  167.  
  168. if (e.Row.RowState == DataControlRowState.Edit)
  169. {
  170. DropDownList DdlFk = (DropDownList)e.Row.FindControl("DdlFk");
  171.  
  172. //encher a droplist
  173.  
  174. SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["GestaoStocksFap"].ConnectionString);
  175. con.Open();
  176.  
  177. Label ddl = (Label)LoginView1.FindControl("ddl");
  178.  
  179. SqlDataAdapter busca = new SqlDataAdapter(ddl.Text, con);
  180.  
  181. try
  182. {
  183. DataTable dt = new DataTable();
  184. busca.Fill(dt);
  185. con.Close();
  186.  
  187. //DdlFk.Items.Clear();
  188. DdlFk.DataSource = dt;
  189. DdlFk.DataBind();
  190.  
  191. }
  192. catch (Exception erro)
  193. {
  194. Response.Write(erro.Message);
  195. }
  196. }
  197. }
  198.  
  199. protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
  200. {
  201.  
  202. }
  203.  
  204. protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
  205. {
  206. GridView GridView1 = (GridView)LoginView1.FindControl("GridView1");
  207. GridView1.EditIndex = e.NewEditIndex;
  208.  
  209. FillGrid();
  210. }
  211.  
  212. protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
  213. {
  214. GridView GridView1 = (GridView)LoginView1.FindControl("GridView1");
  215. string Id = GridView1.DataKeys[e.RowIndex].Value.ToString();
  216. TextBox txtDesig = (TextBox)GridView1.Rows[e.RowIndex].FindControl("txtDesig");
  217. TextBox txtDesc = (TextBox)GridView1.Rows[e.RowIndex].FindControl("txtDesc");
  218. DropDownList ddl = (DropDownList)GridView1.Rows[e.RowIndex].FindControl("DdlFk");
  219.  
  220. Label update = (Label)LoginView1.FindControl("update");
  221.  
  222. SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["GestaoStocksFap"].ConnectionString);
  223. con.Open();
  224.  
  225. string upd = update.Text;
  226. SqlCommand updBd = new SqlCommand(upd, con);
  227. updBd.Parameters.Add("@DesigArm", SqlDbType.NVarChar).Value = txtDesig.Text;
  228. updBd.Parameters.Add("@Descricao", SqlDbType.NVarChar).Value = txtDesc.Text;
  229. updBd.Parameters.Add("@DesigFk", SqlDbType.NVarChar).Value = ddl.SelectedValue;
  230. updBd.Parameters.Add("@CompId", SqlDbType.NVarChar).Value = Convert.ToInt32(Id);
  231.  
  232. updBd.ExecuteNonQuery();
  233. con.Close();
  234. GridView1.EditIndex = -1;
  235. FillGrid();
  236. }
  237.  
  238. protected void GridView1_Sorting(object sender, GridViewSortEventArgs e)
  239. {
  240. //string[] strSortExpression = ViewState["SortExpression"].ToString().Split(' ');
  241.  
  242. //if (strSortExpression[0] == e.SortExpression)
  243. //{
  244. // if (strSortExpression[1]=="ASC")
  245. // {
  246. // ViewState["SortExpression"] = e.SortExpression + " " + "DESC";
  247. // }
  248. // else
  249. // {
  250. // ViewState["SortExpression"] = e.SortExpression + " " + "ASC";
  251. // }
  252. //}
  253. //else
  254. //{
  255. // ViewState["SortExpression"] = e.SortExpression + " " + "ASC";
  256. //}
  257.  
  258. //FillGrid();
  259. }
  260.  
  261. }
  262. }
');