/// <summary> /// This method is used to save the employee leave with the help of ProLeaveEntry Procedure /// before check the date if Leave save already in this given date then first delete the record /// and save the record update otherwise save the record in Leave_Register table. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnApply_Click(object sender, System.EventArgs e) { EmployeeClass obj = new EmployeeClass(); try { #region Check Validation if (DateTime.Compare(ToMMddYYYY(txtDateFrom.Text), ToMMddYYYY(txtDateTO.Text)) > 0) { MessageBox.Show("Date From Should Be Less Than Date To"); return; } if (DateTime.Compare(ToMMddYYYY(GenUtil.str2DDMMYYYY(GenUtil.trimDate(DateTime.Now.ToString()))), ToMMddYYYY(txtDateFrom.Text)) > 0) { MessageBox.Show("Date From Should Be Gratter Or Equal to Date To"); return; } int Count = 0; string str = "select count(*) from Leave_Register where Emp_ID='" + DropEmpName.SelectedItem.Value.Substring(0, DropEmpName.SelectedItem.Value.LastIndexOf(":")) + "' and cast(floor(cast(cast(date_from as datetime) as float)) as datetime) <='" + GenUtil.str2MMDDYYYY(txtDateFrom.Text) + "' and cast(floor(cast(cast(date_to as datetime) as float)) as datetime)>='" + GenUtil.str2MMDDYYYY(txtDateFrom.Text) + "' and isSanction=1"; dbobj.ExecuteScalar(str, ref Count); if (Count > 0) { MessageBox.Show("Employee already allow leave is given date"); return; } str = "select * from Leave_Register where Emp_ID='" + DropEmpName.SelectedItem.Value.Substring(0, DropEmpName.SelectedItem.Value.LastIndexOf(":")) + "' and cast(floor(cast(cast(date_from as datetime) as float)) as datetime) <='" + GenUtil.str2MMDDYYYY(txtDateFrom.Text) + "' and cast(floor(cast(cast(date_to as datetime) as float)) as datetime)>='" + GenUtil.str2MMDDYYYY(txtDateFrom.Text) + "' and isSanction=0"; dbobj.ExecuteScalar(str, ref Count); if (Count > 0) { int x = 0; dbobj.Insert_or_Update("delete from Leave_Register where Emp_ID='" + DropEmpName.SelectedItem.Value.Substring(0, DropEmpName.SelectedItem.Value.LastIndexOf(":")) + "' and cast(floor(cast(cast(date_from as datetime) as float)) as datetime) <='" + GenUtil.str2MMDDYYYY(txtDateFrom.Text) + "' and cast(floor(cast(cast(date_to as datetime) as float)) as datetime)>='" + GenUtil.str2MMDDYYYY(txtDateFrom.Text) + "' and isSanction=0", ref x); } #endregion obj.Emp_Name = DropEmpName.SelectedItem.Value.Substring(0, DropEmpName.SelectedItem.Value.LastIndexOf(":")); obj.Date_From = ToMMddYYYY(txtDateFrom.Text).ToShortDateString(); obj.Date_To = ToMMddYYYY(txtDateTO.Text).ToShortDateString(); obj.Reason = StringUtil.FirstCharUpper(txtReason.Text.ToString()); obj.Days = txtleaveday.Text.ToString().Trim(); //add by vikas 17.11.2012 // calls fuction to insert the leave obj.InsertLeave(); MessageBox.Show("Leave Application Saved"); Clear(); CreateLogFiles.ErrorLog("Form:Leave_Register.aspx,Method:btnApply_Click" + " empname :" + obj.Emp_Name + " datefrom " + obj.Date_From + " uptodate " + obj.Date_To + " for Reason " + obj.Reason + " is saved " + " userid: " + uid); } catch (Exception ex) { CreateLogFiles.ErrorLog("Form:Leave_Register.aspx,Method:btnApply_Click" + " empname :" + obj.Emp_Name + " is saved " + " EXCEPTION " + ex.Message + " userid: " + uid); } }
/// <summary> /// This method is used to delete the particular record select record from dropdownlist. /// </summary> protected void Button3_Click(object sender, System.EventArgs e) { try { if (drp_pname.SelectedIndex == 0) { MessageBox.Show("Please Select The Product Name"); return; } int x = 0; string pid = ""; obj.SelectQuery("select Prod_ID from products where prod_name like '" + drp_pname.SelectedItem.Text + "'", "Prod_ID", ref pid); obj.Insert_or_Update("delete from tax_entry where productid='" + pid + "'", ref x); MessageBox.Show("Tax Entry Deleted"); Clear(); drp_pname.SelectedIndex = 0; CreateLogFiles.ErrorLog("Form:TaxEntry_Master.aspx,Method:button_Click, Deleted tax entry for product " + drp_pname.SelectedItem.Text + " userid " + uid); } catch (Exception ex) { CreateLogFiles.ErrorLog("Form:TaxEntry_Master.aspx,Method:button3_Click" + " EXCEPTION " + ex.Message + " userid " + uid); } }
/// <summary> /// This method is used to save the employee leave with the help of ProLeaveEntry Procedure /// before check the date if Leave save already in this given date then first delete the record /// and save the record update otherwise save the record in Leave_Register table. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnApply_Click(object sender, System.EventArgs e) { EmployeeClass obj = new EmployeeClass(); try { #region Check Validation if (DateTime.Compare(ToMMddYYYY(txtDateFrom.Text), ToMMddYYYY(txtDateTO.Text)) > 0) { MessageBox.Show("Date From Should Be Less Than Date To"); return; } if (DateTime.Compare(ToMMddYYYY(GenUtil.str2DDMMYYYY(GenUtil.trimDate(DateTime.Now.ToString()))), ToMMddYYYY(txtDateFrom.Text)) > 0) { MessageBox.Show("Date From Should Be Gratter Or Equal to Date To"); return; } int Count = 0, Count1 = 0; string str1, str2, str3; str1 = DropEmpName.SelectedItem.Value.Substring(0, DropEmpName.SelectedItem.Value.LastIndexOf(":"));; str2 = GenUtil.str2MMDDYYYY(txtDateFrom.Text); str3 = GenUtil.str2MMDDYYYY(txtDateFrom.Text); using (var client = new HttpClient()) { client.BaseAddress = new Uri(BaseUri); client.DefaultRequestHeaders.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); var Res = client.GetAsync("api/LeaveRegister/CountLeaveRegister?str1=" + str1 + "&str2=" + str2 + "&str3=" + str3).Result; if (Res.IsSuccessStatusCode) { var id = Res.Content.ReadAsStringAsync().Result; Count1 = JsonConvert.DeserializeObject <int>(id); } else { Res.EnsureSuccessStatusCode(); } } Count = Count1; // string str = "select count(*) from Leave_Register where Emp_ID='"+DropEmpName.SelectedItem.Value.Substring(0,DropEmpName.SelectedItem.Value.LastIndexOf(":"))+"' and cast(floor(cast(cast(date_from as datetime) as float)) as datetime) <='"+GenUtil.str2MMDDYYYY(txtDateFrom.Text)+"' and cast(floor(cast(cast(date_to as datetime) as float)) as datetime)>='"+GenUtil.str2MMDDYYYY(txtDateFrom.Text)+"' and isSanction=1"; //dbobj.ExecuteScalar(str,ref Count); if (Count > 0) { MessageBox.Show("Employee already allow leave is given date"); return; } str1 = DropEmpName.SelectedItem.Value.Substring(0, DropEmpName.SelectedItem.Value.LastIndexOf(":")); str2 = GenUtil.str2MMDDYYYY(txtDateFrom.Text); str3 = GenUtil.str2MMDDYYYY(txtDateFrom.Text); using (var client = new HttpClient()) { client.BaseAddress = new Uri(BaseUri); client.DefaultRequestHeaders.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); var Res = client.GetAsync("api/LeaveRegister/GetLeaveRegister?str1=" + str1 + "&str2=" + str2 + "&str3=" + str3).Result; if (Res.IsSuccessStatusCode) { var id = Res.Content.ReadAsStringAsync().Result; Count1 = JsonConvert.DeserializeObject <int>(id); } else { Res.EnsureSuccessStatusCode(); } } Count = Count1; // str = "select * from Leave_Register where Emp_ID='"+DropEmpName.SelectedItem.Value.Substring(0,DropEmpName.SelectedItem.Value.LastIndexOf(":"))+"' and cast(floor(cast(cast(date_from as datetime) as float)) as datetime) <='"+GenUtil.str2MMDDYYYY(txtDateFrom.Text)+"' and cast(floor(cast(cast(date_to as datetime) as float)) as datetime)>='"+GenUtil.str2MMDDYYYY(txtDateFrom.Text)+"' and isSanction=0"; //dbobj.ExecuteScalar(str,ref Count); if (Count > 0) { int x = 0; dbobj.Insert_or_Update("delete from Leave_Register where Emp_ID='" + DropEmpName.SelectedItem.Value.Substring(0, DropEmpName.SelectedItem.Value.LastIndexOf(":")) + "' and cast(floor(cast(cast(date_from as datetime) as float)) as datetime) <='" + GenUtil.str2MMDDYYYY(txtDateFrom.Text) + "' and cast(floor(cast(cast(date_to as datetime) as float)) as datetime)>='" + GenUtil.str2MMDDYYYY(txtDateFrom.Text) + "' and isSanction=0", ref x); } #endregion obj.Emp_Name = DropEmpName.SelectedItem.Value.Substring(0, DropEmpName.SelectedItem.Value.LastIndexOf(":")); obj.Date_From = ToMMddYYYY(txtDateFrom.Text).ToShortDateString(); obj.Date_To = ToMMddYYYY(txtDateTO.Text).ToShortDateString(); obj.Reason = StringUtil.FirstCharUpper(txtReason.Text.ToString()); obj.Days = txtleaveday.Text.ToString().Trim(); //add by vikas 17.11.2012 // calls fuction to insert the leave obj.InsertLeave(); MessageBox.Show("Leave Application Saved"); Clear(); CreateLogFiles.ErrorLog("Form:Leave_Register.aspx,Method:btnApply_Click" + " empname :" + obj.Emp_Name + " datefrom " + obj.Date_From + " uptodate " + obj.Date_To + " for Reason " + obj.Reason + " is saved " + " userid: " + uid); } catch (Exception ex) { CreateLogFiles.ErrorLog("Form:Leave_Register.aspx,Method:btnApply_Click" + " empname :" + obj.Emp_Name + " is saved " + " EXCEPTION " + ex.Message + " userid: " + uid); Response.Redirect("../../Sysitem/ErrorPage.aspx", false); } }