PageRenderTime 46ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/Abhiruchi_Phase1/UC_ORG_Task.xaml.cs

http://AbhiruchiPhase1.codeplex.com
C# | 269 lines | 240 code | 26 blank | 3 comment | 55 complexity | b09640009eb13350f4fcb409f148a62e MD5 | raw file
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Windows;
  6. using System.Windows.Controls;
  7. using System.Windows.Data;
  8. using System.Windows.Documents;
  9. using System.Windows.Input;
  10. using System.Windows.Media;
  11. using System.Windows.Media.Imaging;
  12. using System.Windows.Navigation;
  13. using System.Windows.Shapes;
  14. using System.Data;
  15. using System.Data.SqlClient;
  16. using System.Text.RegularExpressions;
  17. namespace Abhiruchi_Phase1
  18. {
  19. /// <summary>
  20. /// Interaction logic for UC_ORG_Task.xaml
  21. /// </summary>
  22. public partial class UC_ORG_Task : UserControl
  23. {
  24. public static string Mode = "";
  25. public UC_ORG_Task()
  26. {
  27. InitializeComponent();
  28. #region Load Basic Details
  29. DataTable mydtFrCmbSection = ORGTaskMasterDAL.GetDBDetails(6);
  30. GetTaskIdentity();
  31. if (mydtFrCmbSection.Rows.Count > 0)
  32. {
  33. cmbShowSec.DataContext = mydtFrCmbSection.DefaultView;
  34. cmbShowSec.DisplayMemberPath = mydtFrCmbSection.Columns["SectionName"].ToString();
  35. cmbShowSec.SelectedValuePath = mydtFrCmbSection.Columns["SectionId"].ToString();
  36. }
  37. cmbShowGen.Items.Add("Select");
  38. cmbShowGen.Items.Add("Male");
  39. cmbShowGen.Items.Add("Female");
  40. cmbShowHours.Items.Add("Select");
  41. for (int i = 1; i <= 24; i++)
  42. {
  43. cmbShowHours.Items.Add(i);
  44. }
  45. cmbShowSec.SelectedIndex = -1;
  46. chkStatus.IsChecked = true;
  47. #endregion
  48. }
  49. #region Automatic TaskID Generation
  50. public void GetTaskIdentity()
  51. {
  52. DataTable mydtFrTskIdentity = ORGTaskMasterDAL.GetDBDetails(5);
  53. if (mydtFrTskIdentity.Rows.Count > 0)
  54. {
  55. if (mydtFrTskIdentity.Rows[0][0].ToString() == "0" || mydtFrTskIdentity.Rows[0][0].ToString() == "")
  56. {
  57. lblShowTskID.Content = 1.ToString();
  58. }
  59. else
  60. {
  61. lblShowTskID.Content = (Int32.Parse(mydtFrTskIdentity.Rows[0][0].ToString()) + 1).ToString();
  62. }
  63. }
  64. }
  65. #endregion
  66. #region Clear Form
  67. private void btnClear_Click(object sender, RoutedEventArgs e)
  68. {
  69. GetTaskIdentity();
  70. cmbShowGen.SelectedIndex = 0;
  71. cmbShowHours.SelectedIndex = 0;
  72. cmbShowSec.SelectedIndex = -1;
  73. txtTaskShowNm.Text = "";
  74. txtShowPPDay.Text = "";
  75. txtShowDesc.Text = "";
  76. chkStatus.IsChecked = true;
  77. }
  78. #endregion
  79. #region Display Selected Section Details
  80. private void cmbShowSec_SelectionChanged(object sender, SelectionChangedEventArgs e)
  81. {
  82. if (cmbShowSec.SelectedIndex == -1)
  83. {
  84. return;
  85. }
  86. DataTable mydt = ORGTaskMasterDAL.GetDBDetails(7, ((DataRowView)cmbShowSec.Items[cmbShowSec.SelectedIndex]).Row[1].ToString());
  87. grdDisp.ItemsSource = mydt;
  88. }
  89. #endregion
  90. #region Save Details
  91. private void btnSave_Click(object sender, RoutedEventArgs e)
  92. {
  93. if (validation())
  94. {
  95. DataTable mydt = new DataTable();
  96. int isselect = 1;
  97. if (chkStatus.IsChecked == false)
  98. {
  99. isselect = 0;
  100. }
  101. if (Mode == "")
  102. {
  103. mydt = ORGTaskMasterDAL.InsertAndGetDetails(Int32.Parse(((DataRowView)cmbShowSec.Items[cmbShowSec.SelectedIndex]).Row[0].ToString()), txtTaskShowNm.Text, cmbShowGen.Text + "_" + cmbShowHours.Text + "_" + txtShowPPDay.Text, txtShowDesc.Text, isselect, ((DataRowView)cmbShowSec.Items[cmbShowSec.SelectedIndex]).Row[1].ToString(), 8);
  104. MessageBox.Show("Details Inserted Sucessfully", "Information", MessageBoxButton.OK, MessageBoxImage.Information);
  105. }
  106. if (Mode == "Update")
  107. {
  108. mydt = ORGTaskMasterDAL.UpdateAndSelectDetails(Int32.Parse(lblShowTskID.Content.ToString()), Int32.Parse(((DataRowView)cmbShowSec.Items[cmbShowSec.SelectedIndex]).Row[0].ToString()), txtTaskShowNm.Text, cmbShowGen.Text + "_" + cmbShowHours.Text + "_" + txtShowPPDay.Text, txtShowDesc.Text, isselect, ((DataRowView)cmbShowSec.Items[cmbShowSec.SelectedIndex]).Row[1].ToString(), 11);
  109. MessageBox.Show("Details Updated Sucessfully", "Information", MessageBoxButton.OK, MessageBoxImage.Information);
  110. Mode = "";
  111. }
  112. grdDisp.ItemsSource = mydt;
  113. this.btnClear_Click(this, e);
  114. }
  115. }
  116. #endregion
  117. #region Validation
  118. public bool validation()
  119. {
  120. bool status = false;
  121. if (cmbShowSec.SelectedIndex == -1)
  122. {
  123. MessageBox.Show("Section Must be Selected", "Information", MessageBoxButton.OK, MessageBoxImage.Information);
  124. cmbShowSec.Focus();
  125. return false;
  126. }
  127. if (txtTaskShowNm.Text == "")
  128. {
  129. MessageBox.Show("Task Name is required", "Information", MessageBoxButton.OK, MessageBoxImage.Information);
  130. txtTaskShowNm.Focus();
  131. return false;
  132. }
  133. if (cmbShowGen.SelectedIndex == 0)
  134. {
  135. MessageBox.Show("Gender Must be Selected", "Information", MessageBoxButton.OK, MessageBoxImage.Information);
  136. cmbShowGen.Focus();
  137. return false;
  138. }
  139. if (cmbShowHours.SelectedIndex == 0)
  140. {
  141. MessageBox.Show("Hours Must be Selected", "Information", MessageBoxButton.OK, MessageBoxImage.Information);
  142. cmbShowHours.Focus();
  143. return false;
  144. }
  145. if (txtShowPPDay.Text == "")
  146. {
  147. MessageBox.Show("Pay per day should be mentioned", "Information", MessageBoxButton.OK, MessageBoxImage.Information);
  148. txtShowPPDay.Focus();
  149. return false;
  150. }
  151. if (txtShowPPDay.Text != "")
  152. {
  153. if (!Regex.Match(txtShowPPDay.Text, @"^[-+]?[0-9]*\.?[0-9]+$").Success)
  154. {
  155. MessageBox.Show(" Please Enter Correct Amount", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning);
  156. txtShowPPDay.Clear();
  157. txtShowPPDay.Focus();
  158. return false;
  159. }
  160. }
  161. return true;
  162. }
  163. #endregion
  164. #region DatagridView Activated Row
  165. private void grdDisp_RowActivated(object sender, Telerik.Windows.Controls.GridView.RowEventArgs e)
  166. {
  167. Mode = "Update";
  168. if (grdDisp.SelectionMode == SelectionMode.Single)
  169. {
  170. DataTable mydt = ORGTaskMasterDAL.GetDBDetails(10, ((Telerik.Windows.Controls.GridView.GridViewCell)(e.Row.Cells[0])).Value.ToString());
  171. for (int i = 0; i < mydt.Rows.Count; i++)
  172. {
  173. if ((mydt.Rows[i][2].ToString() == (((Telerik.Windows.Controls.GridView.GridViewCell)(e.Row.Cells[1])).Value.ToString())))
  174. {
  175. lblShowTskID.Content = mydt.Rows[i][0].ToString();
  176. cmbShowSec.Text = mydt.Rows[i][1].ToString();
  177. txtTaskShowNm.Text = mydt.Rows[i][2].ToString();
  178. string[] tskmtrx = (mydt.Rows[i][3].ToString()).Split('_');
  179. cmbShowGen.Text = tskmtrx[0].ToString();
  180. cmbShowHours.Text = tskmtrx[1].ToString();
  181. txtShowPPDay.Text = tskmtrx[2].ToString();
  182. txtShowDesc.Text = mydt.Rows[i][4].ToString();
  183. if (mydt.Rows[i][5].ToString() == "1")
  184. {
  185. chkStatus.IsChecked = true;
  186. }
  187. else
  188. {
  189. chkStatus.IsChecked = false;
  190. }
  191. }
  192. }
  193. }
  194. }
  195. #endregion
  196. #region Duplication Checking for TaskName and Task Matrix
  197. private void txtShowPPDay_LostFocus(object sender, RoutedEventArgs e)
  198. {
  199. bool status = false;
  200. if (cmbShowGen.SelectedIndex != 0 && cmbShowHours.SelectedIndex != 0 && txtShowPPDay.Text != "")
  201. {
  202. DataTable mydt = ORGTaskMasterDAL.GetDetailsforValidation(Int32.Parse(((DataRowView)cmbShowSec.Items[cmbShowSec.SelectedIndex]).Row[0].ToString()), 9);
  203. for (int i = 0; i < mydt.Rows.Count; i++)
  204. {
  205. if (cmbShowGen.Text + "_" + cmbShowHours.Text + "_" + txtShowPPDay.Text == mydt.Rows[i][1].ToString())
  206. {
  207. status = true;
  208. }
  209. }
  210. if (status == true)
  211. {
  212. MessageBox.Show(cmbShowGen.Text + "_" + cmbShowHours.Text + "_" + txtShowPPDay.Text + " for " + cmbShowSec.Text + " is already utilized, please choose another Task Matrix ", "Duplicate Task Matrix", MessageBoxButton.OK, MessageBoxImage.Error);
  213. cmbShowGen.SelectedIndex = 0;
  214. cmbShowHours.SelectedIndex = 0;
  215. txtShowPPDay.Text = "";
  216. cmbShowGen.Focus();
  217. }
  218. }
  219. }
  220. private void txtTaskShowNm_LostFocus(object sender, RoutedEventArgs e)
  221. {
  222. bool flag = true;
  223. if (txtTaskShowNm.Text != "")
  224. {
  225. DataTable mydt = ORGTaskMasterDAL.GetDetailsforValidation(Int32.Parse(((DataRowView)cmbShowSec.Items[cmbShowSec.SelectedIndex]).Row[0].ToString()), 9);
  226. for (int i = 0; i < mydt.Rows.Count; i++)
  227. {
  228. if (txtTaskShowNm.Text == mydt.Rows[i][0].ToString())
  229. {
  230. flag = false;
  231. }
  232. }
  233. }
  234. if (flag == false)
  235. {
  236. MessageBox.Show(txtTaskShowNm.Text + " for " + cmbShowSec.Text + " is already utilized, please choose another Task Name ", "Duplicate Task Name", MessageBoxButton.OK, MessageBoxImage.Error);
  237. cmbShowGen.Focus();
  238. txtTaskShowNm.Clear();
  239. }
  240. }
  241. #endregion
  242. }
  243. }