private void detach_tblTime_Records(tblTime_Record entity) { this.SendPropertyChanging(); entity.tblStaff_info = null; }
partial void DeletetblTime_Record(tblTime_Record instance);
partial void InserttblTime_Record(tblTime_Record instance);
partial void UpdatetblTime_Record(tblTime_Record instance);
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e) { try { TextBox txtdate = (TextBox)GridView1.FooterRow.FindControl("txtdate"); TextBox txttime = (TextBox)GridView1.FooterRow.FindControl("txttime"); TextBox txtweek = (TextBox)GridView1.FooterRow.FindControl("txtweek"); TextBox txtdaystatus = (TextBox)GridView1.FooterRow.FindControl("txtdaystatus"); // GridView1.DataBind(); if (e.CommandName.Equals("ADD")) { try { TextBox date1 = new TextBox(); TextBox time = new TextBox(); TextBox week = new TextBox(); TextBox day = new TextBox(); GridViewRow grid1 = (GridViewRow)((Button)e.CommandSource).NamingContainer; date1 = (TextBox)grid1.FindControl("Date"); time = (TextBox)grid1.FindControl("time"); week = (TextBox)grid1.FindControl("week"); day = (TextBox)grid1.FindControl("Day"); Label t = (Label)grid1.FindControl("staffid"); Label tt = (Label)grid1.FindControl("lblstatus"); // Label2.Text = time.Text; if (date1.Equals(null)) { Response.Write("<script>alert ('Please Fill a value ');</script>"); } else { var result = (from x in db.tblTime_Records where x.Staff_id == Convert.ToInt32(t.Text) && x.Date == DateTime.Today.Date orderby x.Time descending select x).FirstOrDefault(); if (result == null) { tblTime_Record trecord = new tblTime_Record(); trecord.Staff_id = Convert.ToInt32(t.Text); trecord.Date = Convert.ToDateTime(date1.Text); // trecord.Time = Convert.ToDateTime(time.Text,TimeSpan ("hh:mm")); DateTime dd = DateTime.Now; trecord.Time = dd.TimeOfDay; trecord.Week_id = week.Text; trecord.Day_status = day.Text; trecord.Status = "in"; trecord.Total_per_day = 0; db.tblTime_Records.InsertOnSubmit(trecord); db.SubmitChanges(); BindData(); GridView1.Rows[GridView1.EditIndex].Cells[9].Text = "in"; } else if (result.Status == "out") { tblTime_Record trecord = new tblTime_Record(); trecord.Staff_id = Convert.ToInt32(t.Text); trecord.Date = Convert.ToDateTime(date1.Text); // trecord.Time = Convert.ToDateTime(time.Text,TimeSpan ("hh:mm")); DateTime dd = DateTime.Now; trecord.Time = dd.TimeOfDay; trecord.Week_id = week.Text; trecord.Day_status = day.Text; trecord.Status = "in"; trecord.Total_per_day = 0; BindData(); GridView1.Rows[GridView1.EditIndex].Cells[9].Text = "in"; db.tblTime_Records.InsertOnSubmit(trecord); db.SubmitChanges(); } else if (result.Status == "in") { tblTime_Record trecord = new tblTime_Record(); trecord.Staff_id = Convert.ToInt32(t.Text); trecord.Date = Convert.ToDateTime(date1.Text); DateTime dd = DateTime.Now; trecord.Time = dd.TimeOfDay; trecord.Week_id = week.Text; trecord.Day_status = day.Text; trecord.Status = "out"; trecord.Total_per_day = dd.TimeOfDay.TotalHours - result.Time.TotalHours; BindData(); GridView1.Rows[GridView1.EditIndex].Cells[9].Text = "out"; db.tblTime_Records.InsertOnSubmit(trecord); db.SubmitChanges(); } } } catch (Exception ex) { // Label2.Text = ex.ToString(); Response.Write("<script>alert ('Please try again ');</script>"); return; } finally { // BindData(); } } else if (e.CommandName == "ADDd") { try { //adding holidays var rst = from xx in db.tblStaff_infos select new { xx.Staff_id }; foreach (var add in rst) { tblTime_Record hol = new tblTime_Record(); hol.Staff_id = add.Staff_id; hol.Date = Convert.ToDateTime(txtdate.Text); DateTime dd = new DateTime(); dd = Convert.ToDateTime(txttime.Text); hol.Time = dd.TimeOfDay; hol.Week_id = txtweek.Text; hol.Day_status = txtdaystatus.Text; db.tblTime_Records.InsertOnSubmit(hol); db.SubmitChanges(); } } catch (Exception ex) { Response.Write("<script>alert ('Please try again ');</script>"); return; } } } catch (Exception ex) { Response.Write("<script>alert ('Please try again ');</script>"); return; } }