private void checkIsGraphed_Click(object sender, EventArgs e) { if (Security.IsAuthorized(Permissions.Schedules)) { PhoneGraph phoneGraph = PhoneGraphs.GetForEmployeeNumAndDate(PedCur.EmployeeNum, DateTime.Today); //check for override if (phoneGraph == null) //no existing entry so exit { return; } if (checkIsGraphed.Checked == phoneGraph.IsGraphed) //default matches existing entry so exit { return; } //we have an existing entry so ask if they want to get rid of it if (!MsgBox.Show(this, MsgBoxButtons.YesNo, "Phone Graph override exists to the contrary of new setting for this employee. Do you want to delete the override and use the default?")) { return; } //get rid of the existing PhoneGraphs.Delete(phoneGraph.PhoneGraphNum); FillGrid(); return; } //Put the checkbox back the way it was before user clicked on it. if (checkIsGraphed.Checked) { checkIsGraphed.Checked = false; } else { checkIsGraphed.Checked = true; } }
///<summary>Inserts one PhoneGraph into the database. Provides option to use the existing priKey. Doesn't use the cache.</summary> public static long InsertNoCache(PhoneGraph phoneGraph, bool useExistingPK) { bool isRandomKeys = Prefs.GetBoolNoCache(PrefName.RandomPrimaryKeys); string command = "INSERT INTO phonegraph ("; if (!useExistingPK && isRandomKeys) { phoneGraph.PhoneGraphNum = ReplicationServers.GetKeyNoCache("phonegraph", "PhoneGraphNum"); } if (isRandomKeys || useExistingPK) { command += "PhoneGraphNum,"; } command += "EmployeeNum,IsGraphed,DateEntry) VALUES("; if (isRandomKeys || useExistingPK) { command += POut.Long(phoneGraph.PhoneGraphNum) + ","; } command += POut.Long(phoneGraph.EmployeeNum) + "," + POut.Bool(phoneGraph.IsGraphed) + "," + POut.Date(phoneGraph.DateEntry) + ")"; if (useExistingPK || isRandomKeys) { Db.NonQ(command); } else { phoneGraph.PhoneGraphNum = Db.NonQ(command, true, "PhoneGraphNum", "phoneGraph"); } return(phoneGraph.PhoneGraphNum); }
///<summary>Inserts one PhoneGraph into the database. Provides option to use the existing priKey.</summary> public static long Insert(PhoneGraph phoneGraph, bool useExistingPK) { if (!useExistingPK && PrefC.RandomKeys) { phoneGraph.PhoneGraphNum = ReplicationServers.GetKey("phonegraph", "PhoneGraphNum"); } string command = "INSERT INTO phonegraph ("; if (useExistingPK || PrefC.RandomKeys) { command += "PhoneGraphNum,"; } command += "EmployeeNum,IsGraphed,DateEntry) VALUES("; if (useExistingPK || PrefC.RandomKeys) { command += POut.Long(phoneGraph.PhoneGraphNum) + ","; } command += POut.Long(phoneGraph.EmployeeNum) + "," + POut.Bool(phoneGraph.IsGraphed) + "," + POut.Date(phoneGraph.DateEntry) + ")"; if (useExistingPK || PrefC.RandomKeys) { Db.NonQ(command); } else { phoneGraph.PhoneGraphNum = Db.NonQ(command, true); } return(phoneGraph.PhoneGraphNum); }
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(); }
///<summary>Inserts one PhoneGraph into the database. Returns the new priKey.</summary> public static long Insert(PhoneGraph phoneGraph) { if (DataConnection.DBtype == DatabaseType.Oracle) { phoneGraph.PhoneGraphNum = DbHelper.GetNextOracleKey("phonegraph", "PhoneGraphNum"); int loopcount = 0; while (loopcount < 100) { try { return(Insert(phoneGraph, true)); } catch (Oracle.DataAccess.Client.OracleException ex) { if (ex.Number == 1 && ex.Message.ToLower().Contains("unique constraint") && ex.Message.ToLower().Contains("violated")) { phoneGraph.PhoneGraphNum++; loopcount++; } else { throw ex; } } } throw new ApplicationException("Insert failed. Could not generate primary key."); } else { return(Insert(phoneGraph, false)); } }
///<summary>Updates one PhoneGraph in the database.</summary> public static void Update(PhoneGraph phoneGraph) { string command = "UPDATE phonegraph SET " + "EmployeeNum = " + POut.Long(phoneGraph.EmployeeNum) + ", " + "IsGraphed = " + POut.Bool(phoneGraph.IsGraphed) + ", " + "DateEntry = " + POut.Date(phoneGraph.DateEntry) + " " + "WHERE PhoneGraphNum = " + POut.Long(phoneGraph.PhoneGraphNum); Db.NonQ(command); }
///<summary>Converts a DataTable to a list of objects.</summary> public static List<PhoneGraph> TableToList(DataTable table){ List<PhoneGraph> retVal=new List<PhoneGraph>(); PhoneGraph phoneGraph; for(int i=0;i<table.Rows.Count;i++) { phoneGraph=new PhoneGraph(); phoneGraph.PhoneGraphNum= PIn.Long (table.Rows[i]["PhoneGraphNum"].ToString()); phoneGraph.EmployeeNum = PIn.Long (table.Rows[i]["EmployeeNum"].ToString()); phoneGraph.IsGraphed = PIn.Bool (table.Rows[i]["IsGraphed"].ToString()); phoneGraph.DateEntry = PIn.Date (table.Rows[i]["DateEntry"].ToString()); retVal.Add(phoneGraph); } return retVal; }
private void gridGraph_CellDoubleClick(object sender, ODGridClickEventArgs e) { //edit this entry if (gridGraph.Rows[e.Row].Tag == null || !(gridGraph.Rows[e.Row].Tag is PhoneGraph)) { return; } PhoneGraph phoneGraph = (PhoneGraph)gridGraph.Rows[e.Row].Tag; FormPhoneGraphEdit FormPGE = new FormPhoneGraphEdit(PedCur.EmployeeNum); FormPGE.PhoneGraphCur = phoneGraph; FormPGE.ShowDialog(); FillGrid(); }
///<summary>Inserts one PhoneGraph into the database. Returns the new priKey. Doesn't use the cache.</summary> public static long InsertNoCache(PhoneGraph phoneGraph) { if (DataConnection.DBtype == DatabaseType.MySql) { return(InsertNoCache(phoneGraph, false)); } else { if (DataConnection.DBtype == DatabaseType.Oracle) { phoneGraph.PhoneGraphNum = DbHelper.GetNextOracleKey("phonegraph", "PhoneGraphNum"); //Cacheless method } return(InsertNoCache(phoneGraph, true)); } }
///<summary>Converts a DataTable to a list of objects.</summary> public static List <PhoneGraph> TableToList(DataTable table) { List <PhoneGraph> retVal = new List <PhoneGraph>(); PhoneGraph phoneGraph; foreach (DataRow row in table.Rows) { phoneGraph = new PhoneGraph(); phoneGraph.PhoneGraphNum = PIn.Long(row["PhoneGraphNum"].ToString()); phoneGraph.EmployeeNum = PIn.Long(row["EmployeeNum"].ToString()); phoneGraph.IsGraphed = PIn.Bool(row["IsGraphed"].ToString()); phoneGraph.DateEntry = PIn.Date(row["DateEntry"].ToString()); retVal.Add(phoneGraph); } return(retVal); }
///<summary>Returns true if Update(PhoneGraph,PhoneGraph) would make changes to the database. ///Does not make any changes to the database and can be called before remoting role is checked.</summary> public static bool UpdateComparison(PhoneGraph phoneGraph, PhoneGraph oldPhoneGraph) { if (phoneGraph.EmployeeNum != oldPhoneGraph.EmployeeNum) { return(true); } if (phoneGraph.IsGraphed != oldPhoneGraph.IsGraphed) { return(true); } if (phoneGraph.DateEntry.Date != oldPhoneGraph.DateEntry.Date) { return(true); } return(false); }
///<summary>Converts a DataTable to a list of objects.</summary> public static List <PhoneGraph> TableToList(DataTable table) { List <PhoneGraph> retVal = new List <PhoneGraph>(); PhoneGraph phoneGraph; for (int i = 0; i < table.Rows.Count; i++) { phoneGraph = new PhoneGraph(); phoneGraph.PhoneGraphNum = PIn.Long(table.Rows[i]["PhoneGraphNum"].ToString()); phoneGraph.EmployeeNum = PIn.Long(table.Rows[i]["EmployeeNum"].ToString()); phoneGraph.IsGraphed = PIn.Bool(table.Rows[i]["IsGraphed"].ToString()); phoneGraph.DateEntry = PIn.Date(table.Rows[i]["DateEntry"].ToString()); retVal.Add(phoneGraph); } return(retVal); }
///<summary>Updates one PhoneGraph in the database. Uses an old object to compare to, and only alters changed fields. This prevents collisions and concurrency problems in heavily used tables. Returns true if an update occurred.</summary> public static bool Update(PhoneGraph phoneGraph, PhoneGraph oldPhoneGraph) { string command = ""; if (phoneGraph.EmployeeNum != oldPhoneGraph.EmployeeNum) { if (command != "") { command += ","; } command += "EmployeeNum = " + POut.Long(phoneGraph.EmployeeNum) + ""; } if (phoneGraph.IsGraphed != oldPhoneGraph.IsGraphed) { if (command != "") { command += ","; } command += "IsGraphed = " + POut.Bool(phoneGraph.IsGraphed) + ""; } if (phoneGraph.DateEntry.Date != oldPhoneGraph.DateEntry.Date) { if (command != "") { command += ","; } command += "DateEntry = " + POut.Date(phoneGraph.DateEntry) + ""; } if (command == "") { return(false); } command = "UPDATE phonegraph SET " + command + " WHERE PhoneGraphNum = " + POut.Long(phoneGraph.PhoneGraphNum); Db.NonQ(command); return(true); }
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>Inserts one PhoneGraph into the database. Provides option to use the existing priKey.</summary> public static long Insert(PhoneGraph phoneGraph,bool useExistingPK){ if(!useExistingPK && PrefC.RandomKeys) { phoneGraph.PhoneGraphNum=ReplicationServers.GetKey("phonegraph","PhoneGraphNum"); } string command="INSERT INTO phonegraph ("; if(useExistingPK || PrefC.RandomKeys) { command+="PhoneGraphNum,"; } command+="EmployeeNum,IsGraphed,DateEntry) VALUES("; if(useExistingPK || PrefC.RandomKeys) { command+=POut.Long(phoneGraph.PhoneGraphNum)+","; } command+= POut.Long (phoneGraph.EmployeeNum)+"," + POut.Bool (phoneGraph.IsGraphed)+"," + POut.Date (phoneGraph.DateEntry)+")"; if(useExistingPK || PrefC.RandomKeys) { Db.NonQ(command); } else { phoneGraph.PhoneGraphNum=Db.NonQ(command,true); } return phoneGraph.PhoneGraphNum; }
///<summary>Inserts one PhoneGraph into the database. Returns the new priKey.</summary> public static long Insert(PhoneGraph phoneGraph){ if(DataConnection.DBtype==DatabaseType.Oracle) { phoneGraph.PhoneGraphNum=DbHelper.GetNextOracleKey("phonegraph","PhoneGraphNum"); int loopcount=0; while(loopcount<100){ try { return Insert(phoneGraph,true); } catch(Oracle.DataAccess.Client.OracleException ex){ if(ex.Number==1 && ex.Message.ToLower().Contains("unique constraint") && ex.Message.ToLower().Contains("violated")){ phoneGraph.PhoneGraphNum++; loopcount++; } else{ throw ex; } } } throw new ApplicationException("Insert failed. Could not generate primary key."); } else { return Insert(phoneGraph,false); } }
private void FillGrid() { //get PhoneGraph entries for this date ListPhoneGraphsForDate = PhoneGraphs.GetAllForDate(DateEdit); //get current employee defaults ListPhoneEmpDefaults = PhoneEmpDefaults.Refresh(); ListPhoneEmpDefaults.Sort(new PhoneEmpDefaults.PhoneEmpDefaultComparer(PhoneEmpDefaults.PhoneEmpDefaultComparer.SortBy.name)); //get schedules ListSchedulesForDate = Schedules.GetDayList(DateEdit); long selectedEmployeeNum = -1; if (gridGraph.Rows.Count >= 1 && gridGraph.GetSelectedIndex() >= 0 && gridGraph.Rows[gridGraph.GetSelectedIndex()].Tag != null && gridGraph.Rows[gridGraph.GetSelectedIndex()].Tag is PhoneEmpDefault) { selectedEmployeeNum = ((PhoneEmpDefault)gridGraph.Rows[gridGraph.GetSelectedIndex()].Tag).EmployeeNum; } gridGraph.BeginUpdate(); gridGraph.Columns.Clear(); ODGridColumn col = new ODGridColumn(Lan.g("TablePhoneGraphDate", "Employee"), 80); gridGraph.Columns.Add(col); //column 0 (name - not clickable) col = new ODGridColumn(Lan.g("TablePhoneGraphDate", "Schedule"), 130); col.TextAlign = HorizontalAlignment.Center; gridGraph.Columns.Add(col); //column 1 (schedule - clickable) col = new ODGridColumn(Lan.g("TablePhoneGraphDate", "Graph Default"), 90); col.TextAlign = HorizontalAlignment.Center; gridGraph.Columns.Add(col); //column 2 (default - not clickable) col = new ODGridColumn(Lan.g("TablePhoneGraphDate", "Set Graph Status"), 110); col.TextAlign = HorizontalAlignment.Center; gridGraph.Columns.Add(col); //column 3 (set graph status - clickable) col = new ODGridColumn(Lan.g("TablePhoneGraphDate", "Is Overridden?"), 80); col.TextAlign = HorizontalAlignment.Center; gridGraph.Columns.Add(col); //column 4 (is value an overridde of default? - not clickable) gridGraph.Rows.Clear(); int selectedRow = -1; //loop through all employee defaults and create 1 row per employee for (int iPED = 0; iPED < ListPhoneEmpDefaults.Count; iPED++) { PhoneEmpDefault phoneEmpDefault = ListPhoneEmpDefaults[iPED]; Employee employee = Employees.GetEmp(phoneEmpDefault.EmployeeNum); if (employee == null || employee.IsHidden) //only deal with current employees { continue; } List <Schedule> scheduleForEmployee = Schedules.GetForEmployee(ListSchedulesForDate, phoneEmpDefault.EmployeeNum); bool isGraphed = phoneEmpDefault.IsGraphed; //set default bool hasOverride = false; for (int iPG = 0; iPG < ListPhoneGraphsForDate.Count; iPG++) //we have a default, now loop through all known exceptions and find a match { PhoneGraph phoneGraph = ListPhoneGraphsForDate[iPG]; if (phoneEmpDefault.EmployeeNum == ListPhoneGraphsForDate[iPG].EmployeeNum) //found a match so no op necessary for this employee { isGraphed = phoneGraph.IsGraphed; hasOverride = true; break; } } ODGridRow row; row = new ODGridRow(); row.Cells.Add(phoneEmpDefault.EmpName); //column 0 (name - not clickable) row.Cells.Add(Schedules.GetCommaDelimStringForScheds(scheduleForEmployee).Replace(", ", "\r\n")); //column 1 (shift times - not clickable) row.Cells.Add(phoneEmpDefault.IsGraphed?"X":""); //column 2 (default - not clickable) row.Cells.Add(isGraphed?"X":""); //column 3 (set graph status - clickable) row.Cells.Add(hasOverride && isGraphed != phoneEmpDefault.IsGraphed?"X":""); //column 4 (is overridden to IsGraphed? - not clickable) row.Tag = phoneEmpDefault; //store the employee for click events int rowIndex = gridGraph.Rows.Add(row); if (selectedEmployeeNum == phoneEmpDefault.EmployeeNum) { selectedRow = rowIndex; } } gridGraph.EndUpdate(); if (selectedRow >= 0) { gridGraph.SetSelected(selectedRow, true); } }
///<summary>Inserts one PhoneGraph into the database. Returns the new priKey.</summary> public static long Insert(PhoneGraph phoneGraph) { return(Insert(phoneGraph, false)); }
///<summary>Updates one PhoneGraph in the database. Uses an old object to compare to, and only alters changed fields. This prevents collisions and concurrency problems in heavily used tables.</summary> public static void Update(PhoneGraph phoneGraph,PhoneGraph oldPhoneGraph){ string command=""; if(phoneGraph.EmployeeNum != oldPhoneGraph.EmployeeNum) { if(command!=""){ command+=",";} command+="EmployeeNum = "+POut.Long(phoneGraph.EmployeeNum)+""; } if(phoneGraph.IsGraphed != oldPhoneGraph.IsGraphed) { if(command!=""){ command+=",";} command+="IsGraphed = "+POut.Bool(phoneGraph.IsGraphed)+""; } if(phoneGraph.DateEntry != oldPhoneGraph.DateEntry) { if(command!=""){ command+=",";} command+="DateEntry = "+POut.Date(phoneGraph.DateEntry)+""; } if(command==""){ return; } command="UPDATE phonegraph SET "+command +" WHERE PhoneGraphNum = "+POut.Long(phoneGraph.PhoneGraphNum); Db.NonQ(command); }
///<summary>Updates one PhoneGraph in the database.</summary> public static void Update(PhoneGraph phoneGraph){ string command="UPDATE phonegraph SET " +"EmployeeNum = "+POut.Long (phoneGraph.EmployeeNum)+", " +"IsGraphed = "+POut.Bool (phoneGraph.IsGraphed)+", " +"DateEntry = "+POut.Date (phoneGraph.DateEntry)+" " +"WHERE PhoneGraphNum = "+POut.Long(phoneGraph.PhoneGraphNum); Db.NonQ(command); }