///<summary>external callers should use InsertOrUpdate</summary> private static long Insert(PhoneGraph phoneGraph) { if (RemotingClient.RemotingRole == RemotingRole.ClientWeb) { phoneGraph.PhoneGraphNum = Meth.GetLong(MethodBase.GetCurrentMethod(), phoneGraph); return(phoneGraph.PhoneGraphNum); } return(Crud.PhoneGraphCrud.Insert(phoneGraph)); }
///<summary></summary> public static void Update(PhoneGraph phoneGraph) { if (RemotingClient.RemotingRole == RemotingRole.ClientWeb) { Meth.GetVoid(MethodBase.GetCurrentMethod(), phoneGraph); return; } Crud.PhoneGraphCrud.Update(phoneGraph); }
///<summary>Each date should have one (and only 1) PhoneGraph entry per employee. Some may already be entered as exceptions to the default. We will fill in the gaps here. This will only be done for today's date (once Today has passed the opportunity to fill the gaps has passed). We don't want to presume that if it was missing on a past date then we should add it. This assumption would fill in gaps on past dates for employees that may not even have worked here on that date.</summary> public static void AddMissingEntriesForToday(List <PhoneEmpDefault> peds) { if (RemotingClient.RemotingRole == RemotingRole.ClientWeb) { Meth.GetVoid(MethodBase.GetCurrentMethod(), peds); return; } //get all overrides created for this date List <PhoneGraph> listPhoneGraphs = GetAllForDate(DateTime.Today); List <Schedule> listSchedules = Schedules.GetDayList(DateTime.Today); //loop through all defaults and check if there are overrides added for (int iPed = 0; iPed < peds.Count; iPed++) { PhoneEmpDefault ped = peds[iPed]; bool hasPhoneGraphEntry = false; //we have a default, now loop through all known overrides and find a match for (int iPG = 0; iPG < listPhoneGraphs.Count; iPG++) { PhoneGraph pg = listPhoneGraphs[iPG]; if (ped.EmployeeNum == listPhoneGraphs[iPG].EmployeeNum) //found a match so no op necessary for this employee { hasPhoneGraphEntry = true; break; } } if (hasPhoneGraphEntry) //no entry needed, it's already there { continue; } //does employee have a schedule table entry for this date bool hasScheduleEntry = false; for (int iSch = 0; iSch < listSchedules.Count; iSch++) { Schedule schedule = listSchedules[iSch]; if (ped.EmployeeNum == listSchedules[iSch].EmployeeNum) //found a match so no op necessary for this employee { hasScheduleEntry = true; break; } } if (!hasScheduleEntry) //no entry needed if not on the schedule { continue; } //employee is on the schedule but does not have a phonegraph entry, so create one PhoneGraph pgNew = new PhoneGraph(); pgNew.EmployeeNum = ped.EmployeeNum; pgNew.DateEntry = DateTime.Today; pgNew.IsGraphed = ped.IsGraphed; Insert(pgNew); } }
/// <summary>user may have modified an existing PhoneGraph to look like a different existing so delete duplicates before inserting the new one</summary> public static void InsertOrUpdate(PhoneGraph phoneGraph) { if (RemotingClient.RemotingRole == RemotingRole.ClientWeb) { Meth.GetVoid(MethodBase.GetCurrentMethod(), phoneGraph); return; } //do we have any duplicates? string command = "SELECT PhoneGraphNum FROM PhoneGraph " + "WHERE EmployeeNum=" + POut.Long(phoneGraph.EmployeeNum) + " " + "AND DateEntry=" + POut.Date(phoneGraph.DateEntry); long phoneGraphNumOld = PIn.Long(Db.GetScalar(command)); if (phoneGraphNumOld > 0) //duplicate found, get rid of it { Delete(phoneGraphNumOld); } Insert(phoneGraph); //its now safe to insert }
private void butOK_Click(object sender,System.EventArgs e) { if(textDateEntry.Text=="" || textDateEntry.errorProvider1.GetError(textDateEntry)!="") { MsgBox.Show(this,"Please fix data entry errors first."); return; } //user brought in an existing entry and may have modified it so get rid of it and recreate it in its entirety //EG... //user brought in 9/27/13 Checked: TRUE... //then changed date to 9/28/13 Checked: FALSE... //user has expectation that the 9/27 entry will be gone and new 9/28 entry will be created if(!PhoneGraphCur.IsNew) { PhoneGraphs.Delete(PhoneGraphCur.PhoneGraphNum); } PhoneGraph pg=new PhoneGraph(); pg.EmployeeNum=EmployeeNum; pg.DateEntry=PIn.Date(textDateEntry.Text); pg.IsGraphed=checkIsGraphed.Checked; PhoneGraphs.InsertOrUpdate(pg); DialogResult=DialogResult.OK; }
/// <summary>use sparingly as this makes a db call every time. only used for validating user is not modifying "dirty" data</summary> public static bool GetGraphedStatusForEmployeeDate(long employeeNum, DateTime dateEntry) { if (RemotingClient.RemotingRole == RemotingRole.ClientWeb) { return(Meth.GetBool(MethodBase.GetCurrentMethod(), employeeNum, dateEntry)); } PhoneEmpDefault phoneEmpDefault = Crud.PhoneEmpDefaultCrud.SelectOne(employeeNum); if (phoneEmpDefault == null) { return(false); } bool isGraphed = phoneEmpDefault.IsGraphed; //get employee default PhoneGraph phoneGraph = PhoneGraphs.GetForEmployeeNumAndDate(employeeNum, dateEntry); //check for exception if (phoneGraph != null) //exception found so use that { isGraphed = phoneGraph.IsGraphed; } return(isGraphed); }
///<summary>external callers should use InsertOrUpdate</summary> private static long Insert(PhoneGraph phoneGraph){ if(RemotingClient.RemotingRole==RemotingRole.ClientWeb){ phoneGraph.PhoneGraphNum=Meth.GetLong(MethodBase.GetCurrentMethod(),phoneGraph); return phoneGraph.PhoneGraphNum; } return Crud.PhoneGraphCrud.Insert(phoneGraph); }
///<summary>Each date should have one (and only 1) PhoneGraph entry per employee. Some may already be entered as exceptions to the default. We will fill in the gaps here. This will only be done for today's date (once Today has passed the opportunity to fill the gaps has passed). We don't want to presume that if it was missing on a past date then we should add it. This assumption would fill in gaps on past dates for employees that may not even have worked here on that date.</summary> public static void AddMissingEntriesForToday(List<PhoneEmpDefault> peds) { if(RemotingClient.RemotingRole==RemotingRole.ClientWeb) { Meth.GetVoid(MethodBase.GetCurrentMethod(),peds); return; } //get all overrides created for this date List<PhoneGraph> listPhoneGraphs=GetAllForDate(DateTime.Today); List<Schedule> listSchedules=Schedules.GetDayList(DateTime.Today); //loop through all defaults and check if there are overrides added for(int iPed=0;iPed<peds.Count;iPed++) { PhoneEmpDefault ped=peds[iPed]; bool hasPhoneGraphEntry=false; //we have a default, now loop through all known overrides and find a match for(int iPG=0;iPG<listPhoneGraphs.Count;iPG++) { PhoneGraph pg=listPhoneGraphs[iPG]; if(ped.EmployeeNum==listPhoneGraphs[iPG].EmployeeNum) {//found a match so no op necessary for this employee hasPhoneGraphEntry=true; break; } } if(hasPhoneGraphEntry) {//no entry needed, it's already there continue; } //does employee have a schedule table entry for this date bool hasScheduleEntry=false; for(int iSch=0;iSch<listSchedules.Count;iSch++) { Schedule schedule=listSchedules[iSch]; if(ped.EmployeeNum==listSchedules[iSch].EmployeeNum) {//found a match so no op necessary for this employee hasScheduleEntry=true; break; } } if(!hasScheduleEntry) { //no entry needed if not on the schedule continue; } //employee is on the schedule but does not have a phonegraph entry, so create one PhoneGraph pgNew=new PhoneGraph(); pgNew.EmployeeNum=ped.EmployeeNum; pgNew.DateEntry=DateTime.Today; pgNew.IsGraphed=ped.IsGraphed; Insert(pgNew); } }
/// <summary>user may have modified an existing PhoneGraph to look like a different existing so delete duplicates before inserting the new one</summary> public static void InsertOrUpdate(PhoneGraph phoneGraph) { if(RemotingClient.RemotingRole==RemotingRole.ClientWeb) { Meth.GetVoid(MethodBase.GetCurrentMethod(),phoneGraph); return; } //do we have any duplicates? string command="SELECT PhoneGraphNum FROM PhoneGraph " +"WHERE EmployeeNum="+POut.Long(phoneGraph.EmployeeNum)+" " +"AND DateEntry="+POut.Date(phoneGraph.DateEntry); long phoneGraphNumOld=PIn.Long(Db.GetScalar(command)); if(phoneGraphNumOld>0) {//duplicate found, get rid of it Delete(phoneGraphNumOld); } Insert(phoneGraph); //its now safe to insert }
///<summary></summary> public static void Update(PhoneGraph phoneGraph){ if(RemotingClient.RemotingRole==RemotingRole.ClientWeb){ Meth.GetVoid(MethodBase.GetCurrentMethod(),phoneGraph); return; } Crud.PhoneGraphCrud.Update(phoneGraph); }
private void gridGraph_CellClick(object sender,ODGridClickEventArgs e) { //only allow clicking on the 'Desired Graph Status' column if(e.Col!=3 || gridGraph.Rows[e.Row].Tag==null || !(gridGraph.Rows[e.Row].Tag is PhoneEmpDefault)) { return; } PhoneEmpDefault phoneEmpDefault=(PhoneEmpDefault)gridGraph.Rows[e.Row].Tag; bool uiGraphStatus=gridGraph.Rows[e.Row].Cells[e.Col].Text.ToLower()=="x"; bool dbGraphStatus=PhoneEmpDefaults.GetGraphedStatusForEmployeeDate(phoneEmpDefault.EmployeeNum,DateEdit); if(uiGraphStatus!=dbGraphStatus) { MessageBox.Show(Lan.g(this,"Graph status has changed unexpectedly for employee: ")+phoneEmpDefault.EmpName+Lan.g(this,". Exit and reopen this form, and try again.")); return; } //flip the bit in the db and reload the grid PhoneGraph pg=new PhoneGraph(); pg.EmployeeNum=phoneEmpDefault.EmployeeNum; pg.DateEntry=DateEdit; pg.IsGraphed=!uiGraphStatus; //flip the bit PhoneGraphs.InsertOrUpdate(pg); //update the db FillGrid(); }