PageRenderTime 37ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 1ms

/Facility Audit/CompanySector.aspx.cs

https://bitbucket.org/venkadesan/customersfeedback
C# | 375 lines | 293 code | 60 blank | 22 comment | 52 complexity | 1b33ed1a848ff99798dcc99cb274a508 MD5 | raw file
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.UI;
  6. using System.Web.UI.WebControls;
  7. using System.Data;
  8. using FacilityAudit.BLL;
  9. using KB = Kowni.BusinessLogic;
  10. using KCB = Kowni.Common.BusinessLogic;
  11. using FacilityAudit.Code;
  12. using System.Text;
  13. using BL;
  14. using System.Configuration;
  15. namespace Facility_Audit
  16. {
  17. public partial class CompanySector : System.Web.UI.Page
  18. {
  19. #region Properties
  20. private bool IsAdd
  21. {
  22. get
  23. {
  24. if (!ID.HasValue)
  25. return false;
  26. else if (ID.Value != 0)
  27. return false;
  28. else
  29. return true;
  30. }
  31. }
  32. private int? ID
  33. {
  34. get
  35. {
  36. if (ViewState["id"] == null)
  37. ViewState["id"] = 0;
  38. return (int?)ViewState["id"];
  39. }
  40. set
  41. {
  42. ViewState["id"] = value;
  43. }
  44. }
  45. private bool DisableStatus
  46. {
  47. get
  48. {
  49. if (ViewState["disablestatus"] == null)
  50. ViewState["disablestatus"] = 0;
  51. return (bool)ViewState["disablestatus"];
  52. }
  53. set
  54. {
  55. ViewState["disablestatus"] = value;
  56. }
  57. }
  58. #endregion
  59. BLGroupcompany objgrp = new BLGroupcompany();
  60. BLGroupcompany objgrpcmp = new BLGroupcompany();
  61. KB.BLUser.BLUserLocation objuserLocation1 = new KB.BLUser.BLUserLocation();
  62. protected void Page_Load(object sender, EventArgs e)
  63. {
  64. if (!IsPostBack)
  65. {
  66. loadsector();
  67. loadrprtdetails();
  68. }
  69. }
  70. private void ButtonStatus(Common.ButtonStatus status)
  71. {
  72. ddlsector.ClearSelection();
  73. this.ddlsector.Items.FindByValue(UserSession.sectorid.ToString()).Selected = true;
  74. //ddlgroup.ClearSelection();
  75. if (status == Common.ButtonStatus.New)
  76. {
  77. this.lblError.Text = "";
  78. divmsg.Visible = false;
  79. }
  80. else if (status == Common.ButtonStatus.Edit)
  81. {
  82. this.lblError.Text = "";
  83. divmsg.Visible = false;
  84. }
  85. else if (status == Common.ButtonStatus.Cancel)
  86. {
  87. this.ID = 0;
  88. divrep.Visible = true;
  89. // loadrprtdetails();
  90. this.lblError.Text = "";
  91. divmsg.Visible = false;
  92. }
  93. else if (status == Common.ButtonStatus.Save)
  94. {
  95. this.ID = 0;
  96. divrep.Visible = true;
  97. loadrprtdetails();
  98. }
  99. }
  100. public void NotifyMessages(string message, Common.ErrorType et)
  101. {
  102. divmsg.Visible = true;
  103. lblError.Text = message;
  104. if (et == Common.ErrorType.Error)
  105. {
  106. }
  107. else if (et == Common.ErrorType.Information)
  108. {
  109. }
  110. }
  111. private void loadsector()
  112. {
  113. try
  114. {
  115. DataSet ds = new DataSet();
  116. ds = objgrp.getsector();
  117. if (UserSession.sectorid == 0)
  118. {
  119. if (ds.Tables[0].Rows.Count > 0)
  120. {
  121. ddlsector.DataSource = ds;
  122. ddlsector.DataTextField = "locationsectorname";
  123. ddlsector.DataValueField = "locationsectorid";
  124. ddlsector.DataBind();
  125. UserSession.sectorid = Convert.ToInt32(this.ddlsector.Items[0].Value);
  126. }
  127. }
  128. else
  129. {
  130. if (ds.Tables[0].Rows.Count > 0)
  131. {
  132. ddlsector.DataSource = ds;
  133. ddlsector.DataTextField = "locationsectorname";
  134. ddlsector.DataValueField = "locationsectorid";
  135. ddlsector.DataBind();
  136. }
  137. this.ddlsector.ClearSelection();
  138. this.ddlsector.Items.FindByValue(UserSession.sectorid.ToString()).Selected = true;
  139. }
  140. }
  141. catch { }
  142. }
  143. protected void btnsave_Click(object sender, EventArgs e)
  144. {
  145. try
  146. {
  147. string XmLIS = string.Empty;
  148. if (this.IsAdd)
  149. {
  150. //if (objgrp.updatecompanynsector(Convert.ToInt32(UserSession.locationid), Convert.ToInt32(ddlsector.SelectedValue)) > 0)
  151. //{
  152. // NotifyMessages("Saved successfully", Common.ErrorType.Information);
  153. //}
  154. //else
  155. //{
  156. // NotifyMessages("Not saved sucessfully", Common.ErrorType.Error);
  157. // return;
  158. //}
  159. StringBuilder sb = new StringBuilder();
  160. sb.Append("<root>");
  161. for (int item = 0; item < rptrsector.Items.Count; item++)
  162. {
  163. HiddenField hCompanyID = rptrsector.Items[item].FindControl("hidcompanyid") as HiddenField;
  164. Repeater rptLocation = rptrsector.Items[item].FindControl("rptrLocation") as Repeater;
  165. for (int items = 0; items < rptLocation.Items.Count; items++)
  166. {
  167. CheckBox chkLocation = (CheckBox)rptLocation.Items[items].FindControl("chkLocation");
  168. if (chkLocation.Checked)
  169. {
  170. HiddenField hLocationID = (HiddenField)rptLocation.Items[items].FindControl("hLocationID");
  171. sb.Append(
  172. "<files sectorid=\"" + Convert.ToInt32(ddlsector.SelectedValue)+ "\"" +
  173. " companyid=\"" + Convert.ToInt32(hCompanyID.Value) + "\"" +
  174. " locationid=\"" + Convert.ToInt32(hLocationID.Value) + "\"" +
  175. " cuid=\"" + Convert.ToInt32(UserSession.UserID) + "\"" +
  176. " cdate=\"" + DateTime.Now.AddHours(Convert.ToInt32(ConfigurationManager.AppSettings["addhour"].ToString())).AddMinutes(Convert.ToInt32(ConfigurationManager.AppSettings["addminute"].ToString())) + "\" />");
  177. }
  178. }
  179. }
  180. sb.Append("</root>");
  181. XmLIS = sb.ToString();
  182. DataSet ds = new DataSet();
  183. if ( objgrpcmp.addsectorlocation(XmLIS) > 0)
  184. {
  185. NotifyMessages("Saved Sucessfully", Common.ErrorType.Information);
  186. ButtonStatus(Common.ButtonStatus.Save);
  187. }
  188. }
  189. else if (this.ID != null && this.ID.Value > 0)
  190. {
  191. // if (objgrp.updatecompanynsector(Convert.ToInt32(UserSession.locationid), Convert.ToInt32(ddlsector.SelectedValue)) > 0)
  192. // {
  193. // NotifyMessages("Updated successfully", Common.ErrorType.Information);
  194. // }
  195. // else
  196. // {
  197. // NotifyMessages("Not saved sucessfully", Common.ErrorType.Information);
  198. // return;
  199. // }
  200. //}
  201. UserSession.sectorid = Convert.ToInt32(ddlsector.SelectedValue);
  202. StringBuilder sb = new StringBuilder();
  203. sb.Append("<root>");
  204. for (int item = 0; item < rptrsector.Items.Count; item++)
  205. {
  206. HiddenField hCompanyID = rptrsector.Items[item].FindControl("hidcompanyid") as HiddenField;
  207. Repeater rptLocation = rptrsector.Items[item].FindControl("rptrLocation") as Repeater;
  208. for (int items = 0; items < rptLocation.Items.Count; items++)
  209. {
  210. CheckBox chkLocation = (CheckBox)rptLocation.Items[items].FindControl("chkLocation");
  211. if (chkLocation.Checked)
  212. {
  213. HiddenField hLocationID = (HiddenField)rptLocation.Items[items].FindControl("hLocationID");
  214. sb.Append(
  215. "<files sectorid=\"" + Convert.ToInt32(ddlsector.SelectedValue) + "\"" +
  216. " companyid=\"" + Convert.ToInt32(hCompanyID.Value) + "\"" +
  217. " locationid=\"" + Convert.ToInt32(hLocationID.Value) +
  218. " cuid=\"" + Convert.ToInt32(UserSession.UserID) + "\"" +
  219. " cdate=\"" + DateTime.Now.AddHours(Convert.ToInt32(ConfigurationManager.AppSettings["addhour"].ToString())).AddMinutes(Convert.ToInt32(ConfigurationManager.AppSettings["addminute"].ToString())) + "\" />");
  220. }
  221. }
  222. }
  223. sb.Append("</root>");
  224. XmLIS = sb.ToString();
  225. DataSet ds = new DataSet();
  226. if (objgrpcmp.addsectorlocation(XmLIS) > 0)
  227. {
  228. NotifyMessages("Saved Sucessfully", Common.ErrorType.Information);
  229. ButtonStatus(Common.ButtonStatus.Save);
  230. }
  231. }
  232. }
  233. catch { }
  234. }
  235. private void loadrprtdetails()
  236. {
  237. try
  238. {
  239. DataSet ds = new DataSet();
  240. ds = objgrpcmp.getcompanybygroupid(UserSession.GroupID, UserSession.RoleID);
  241. if (ds.Tables[0].Rows.Count > 0)
  242. {
  243. rptrsector.DataSource = ds;
  244. rptrsector.DataBind();
  245. ButtonStatus(Common.ButtonStatus.Cancel);
  246. }
  247. else
  248. {
  249. rptrsector.DataSource = ds;
  250. rptrsector.DataBind();
  251. divmsg.Visible = false;
  252. }
  253. loaddata();
  254. }
  255. catch { }
  256. }
  257. private void loaddata()
  258. {
  259. try
  260. {
  261. DataSet Ds = new DataSet();
  262. Ds = objgrpcmp.getsectorlocation(Convert.ToInt32(ddlsector.SelectedValue));
  263. if (Ds.Tables[0].Rows.Count > 0)
  264. {
  265. for (int item = 0; item < rptrsector.Items.Count; item++)
  266. {
  267. Repeater rptLocation = rptrsector.Items[item].FindControl("rptrLocation") as Repeater;
  268. for (int items = 0; items < rptLocation.Items.Count; items++)
  269. {
  270. CheckBox chkLocation = (CheckBox)rptLocation.Items[items].FindControl("chkLocation");
  271. HiddenField hLocationID = (HiddenField)rptLocation.Items[items].FindControl("hLocationID");
  272. DataRow[] FilterValue = Ds.Tables[0].Select("locationid=" + hLocationID.Value + "");
  273. if (FilterValue.Length > 0)
  274. chkLocation.Checked = true;
  275. }
  276. }
  277. }
  278. }
  279. catch { }
  280. }
  281. protected void rptrsector_ItemDataBound(object sender, RepeaterItemEventArgs e)
  282. {
  283. if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
  284. {
  285. HiddenField hCompanyID = (HiddenField)e.Item.FindControl("hidcompanyid");
  286. Repeater rptrLocation = (Repeater)e.Item.FindControl("rptrLocation");
  287. DataSet ds = new DataSet();
  288. int companyid = Convert.ToInt32(hCompanyID.Value);
  289. //ds = objuserLocation1.GetUserLocation(UserSession.UserID, companyid);
  290. ds = objgrpcmp.getlocationbylocationsector(UserSession.UserID, companyid,Convert.ToInt32(ddlsector.SelectedValue));
  291. if (ds.Tables[0].Rows.Count > 0)
  292. {
  293. rptrLocation.DataSource = ds;
  294. rptrLocation.DataBind();
  295. }
  296. }
  297. }
  298. protected void btncncl_Click(object sender, EventArgs e)
  299. {
  300. ButtonStatus(Common.ButtonStatus.Cancel);
  301. loadrprtdetails();
  302. }
  303. protected void ddllocation_SelectedIndexChanged(object sender, EventArgs e)
  304. {
  305. loadrprtdetails();
  306. }
  307. protected void ddlsector_SelectedIndexChanged(object sender, EventArgs e)
  308. {
  309. UserSession.sectorid = Convert.ToInt32(this.ddlsector.SelectedItem.Value);
  310. this.ddlsector.ClearSelection();
  311. this.ddlsector.Items.FindByValue(UserSession.sectorid.ToString()).Selected = true;
  312. loadrprtdetails();
  313. }
  314. }
  315. }