public static Object InsertRoasterManagement(string rosterdetail) { bool insertFlag = false; //bool UpdateFlag = false; string roosterNumber = string.Empty; ArrayList roosterNumberlist = new ArrayList(); IEnumerable<dynamic> intersectResult = null; List<Roster> RosterDetails = null; RoasterManagementBLL objRoasterManagementBLL = null; RoasterManagement objRoasterManagement = null; try { objRoasterManagementBLL = new RoasterManagementBLL(); objRoasterManagement = new RoasterManagement(); objRoasterManagement.PreFix = System.DateTime.Now.ToString("yyMMdd"); bool CreateRosterNoFlag=false; RosterDetails = objRoasterManagementBLL.GetRoasterDetail(objRoasterManagement.PreFix); int commonRow = 0; DataTable dt = new DataTable(); dt = RosterDt.Copy(); if (RosterDetails != null) { var query1 = dt.AsEnumerable().Select(a => new { CabNo = a["CabNo"].ToString(), ShiftTime = Convert.ToDateTime(a["Shift Timings"]).TimeOfDay.ToString(), RoosterDate = Convert.ToDateTime(a["Date"]).ToShortDateString(), }); var query2 = RosterDetails.AsEnumerable().Select(b => new { CabNo = b.Cabno, ShiftTime = b.ShiftTime, RoosterDate = Convert.ToDateTime(b.RousterDate).ToShortDateString() }); intersectResult = query1.Intersect(query2);//existing row commonRow = intersectResult.Count(); } if (commonRow == 0)//there is no duplicate record in database { var distinctCabs = dt.AsEnumerable().Select(a => new { CabNo = a["CabNo"].ToString(), ShiftTime = Convert.ToDateTime(a["Shift Timings"]).TimeOfDay.ToString(), RoosterDate = Convert.ToDateTime(a["Date"]).ToShortDateString() }).Distinct(); foreach (var c in distinctCabs) { CreateRosterNoFlag = CreateRosterNo(objRoasterManagement.PreFix, out roosterNumber); //roosterNumberlist.Add(roosterNumber); if (CreateRosterNoFlag == true)//insert { roosterNumberlist.Add(roosterNumber); objRoasterManagement.RosterDetailDT = new DataTable(); var rows = from row in dt.AsEnumerable() where row.Field<string>("CabNo").Trim() == c.CabNo && row.Field<DateTime>("Shift Timings").TimeOfDay == Convert.ToDateTime(c.ShiftTime).TimeOfDay && Convert.ToDateTime(row.Field<string>("Date")).ToShortDateString()== Convert.ToDateTime(c.RoosterDate).ToShortDateString() select row; objRoasterManagement.RosterDetailDT = rows.CopyToDataTable(); insertFlag = objRoasterManagementBLL.InsertRoasterDetail(objRoasterManagement); } } } } catch (Exception ex) { Common.WriteError(ex); } finally { objRoasterManagementBLL = null; } var result = new { Flag = insertFlag, roosternumber = roosterNumberlist, commonrow = intersectResult }; return result; }
public static void GetRoosterWiseRecords(List<string> roosterNumbers) { List<Roster> RosterDetails = null; RoasterManagementBLL objRoasterManagementBLL = null; string PreFix = System.DateTime.Now.ToString("yyMMdd"); try { objRoasterManagementBLL = new RoasterManagementBLL(); RosterDetails = objRoasterManagementBLL.GetRoasterDetail(PreFix); DataSet ds = new DataSet(); foreach (var rooster in roosterNumbers) { var rostertable = RosterDetails .Where(p => p.RoosterNumber == rooster) .Select(p => new { p.RousterDate, p.EmployeeNo, p.EmployeeName, p.Address, p.PickUpOrder, p.PickupTime, p.ShiftTime, p.Cabno, p.CabType, p.Vendor, p.Signature }).ToList(); Utility utility = new Utility(); DataTable dt = utility.ToDataTable(rostertable); dt.TableName = "Roster-" + rooster; ds.Tables.Add(dt); } ConvrtPDF(ds, roosterNumbers, PreFix); //isFlag = true; } catch (Exception ex) { Common.WriteError(ex); } finally { objRoasterManagementBLL = null; } //return RosterDetails; }