///<summary>Inserts one SupplyNeeded into the database. Returns the new priKey.</summary> internal static long Insert(SupplyNeeded supplyNeeded) { if(DataConnection.DBtype==DatabaseType.Oracle) { supplyNeeded.SupplyNeededNum=DbHelper.GetNextOracleKey("supplyneeded","SupplyNeededNum"); int loopcount=0; while(loopcount<100){ try { return Insert(supplyNeeded,true); } catch(Oracle.DataAccess.Client.OracleException ex){ if(ex.Number==1 && ex.Message.ToLower().Contains("unique constraint") && ex.Message.ToLower().Contains("violated")){ supplyNeeded.SupplyNeededNum++; loopcount++; } else{ throw ex; } } } throw new ApplicationException("Insert failed. Could not generate primary key."); } else { return Insert(supplyNeeded,false); } }
///<summary>Updates one SupplyNeeded in the database.</summary> public static void Update(SupplyNeeded supplyNeeded) { string command = "UPDATE supplyneeded SET " + "Description = '" + POut.String(supplyNeeded.Description) + "', " + "DateAdded = " + POut.Date(supplyNeeded.DateAdded) + " " + "WHERE SupplyNeededNum = " + POut.Long(supplyNeeded.SupplyNeededNum); Db.NonQ(command); }
///<summary>Converts a DataTable to a list of objects.</summary> public static List<SupplyNeeded> TableToList(DataTable table){ List<SupplyNeeded> retVal=new List<SupplyNeeded>(); SupplyNeeded supplyNeeded; for(int i=0;i<table.Rows.Count;i++) { supplyNeeded=new SupplyNeeded(); supplyNeeded.SupplyNeededNum= PIn.Long (table.Rows[i]["SupplyNeededNum"].ToString()); supplyNeeded.Description = PIn.String(table.Rows[i]["Description"].ToString()); supplyNeeded.DateAdded = PIn.Date (table.Rows[i]["DateAdded"].ToString()); retVal.Add(supplyNeeded); } return retVal; }
///<summary>Returns true if Update(SupplyNeeded,SupplyNeeded) 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(SupplyNeeded supplyNeeded, SupplyNeeded oldSupplyNeeded) { if (supplyNeeded.Description != oldSupplyNeeded.Description) { return(true); } if (supplyNeeded.DateAdded.Date != oldSupplyNeeded.DateAdded.Date) { return(true); } return(false); }
private void butAddNeeded_Click(object sender, EventArgs e) { SupplyNeeded supp = new SupplyNeeded(); supp.IsNew = true; supp.DateAdded = DateTime.Today; FormSupplyNeededEdit FormS = new FormSupplyNeededEdit(); FormS.Supp = supp; FormS.ShowDialog(); if (FormS.DialogResult == DialogResult.OK) { FillGridNeeded(); } }
///<summary>Converts a DataTable to a list of objects.</summary> public static List <SupplyNeeded> TableToList(DataTable table) { List <SupplyNeeded> retVal = new List <SupplyNeeded>(); SupplyNeeded supplyNeeded; foreach (DataRow row in table.Rows) { supplyNeeded = new SupplyNeeded(); supplyNeeded.SupplyNeededNum = PIn.Long(row["SupplyNeededNum"].ToString()); supplyNeeded.Description = PIn.String(row["Description"].ToString()); supplyNeeded.DateAdded = PIn.Date(row["DateAdded"].ToString()); retVal.Add(supplyNeeded); } return(retVal); }
///<summary>Updates one SupplyNeeded in the database.</summary> public static void Update(SupplyNeeded supplyNeeded) { string command = "UPDATE supplyneeded SET " + "Description = " + DbHelper.ParamChar + "paramDescription, " + "DateAdded = " + POut.Date(supplyNeeded.DateAdded) + " " + "WHERE SupplyNeededNum = " + POut.Long(supplyNeeded.SupplyNeededNum); if (supplyNeeded.Description == null) { supplyNeeded.Description = ""; } OdSqlParameter paramDescription = new OdSqlParameter("paramDescription", OdDbType.Text, POut.StringParam(supplyNeeded.Description)); Db.NonQ(command, paramDescription); }
///<summary>Converts a DataTable to a list of objects.</summary> internal static List <SupplyNeeded> TableToList(DataTable table) { List <SupplyNeeded> retVal = new List <SupplyNeeded>(); SupplyNeeded supplyNeeded; for (int i = 0; i < table.Rows.Count; i++) { supplyNeeded = new SupplyNeeded(); supplyNeeded.SupplyNeededNum = PIn.Long(table.Rows[i]["SupplyNeededNum"].ToString()); supplyNeeded.Description = PIn.String(table.Rows[i]["Description"].ToString()); supplyNeeded.DateAdded = PIn.Date(table.Rows[i]["DateAdded"].ToString()); retVal.Add(supplyNeeded); } return(retVal); }
///<summary>Inserts one SupplyNeeded into the database. Returns the new priKey. Doesn't use the cache.</summary> public static long InsertNoCache(SupplyNeeded supplyNeeded) { if (DataConnection.DBtype == DatabaseType.MySql) { return(InsertNoCache(supplyNeeded, false)); } else { if (DataConnection.DBtype == DatabaseType.Oracle) { supplyNeeded.SupplyNeededNum = DbHelper.GetNextOracleKey("supplyneeded", "SupplyNeededNum"); //Cacheless method } return(InsertNoCache(supplyNeeded, true)); } }
///<summary>Inserts one SupplyNeeded into the database. Provides option to use the existing priKey.</summary> public static long Insert(SupplyNeeded supplyNeeded,bool useExistingPK){ if(!useExistingPK && PrefC.RandomKeys) { supplyNeeded.SupplyNeededNum=ReplicationServers.GetKey("supplyneeded","SupplyNeededNum"); } string command="INSERT INTO supplyneeded ("; if(useExistingPK || PrefC.RandomKeys) { command+="SupplyNeededNum,"; } command+="Description,DateAdded) VALUES("; if(useExistingPK || PrefC.RandomKeys) { command+=POut.Long(supplyNeeded.SupplyNeededNum)+","; } command+= "'"+POut.String(supplyNeeded.Description)+"'," + POut.Date (supplyNeeded.DateAdded)+")"; if(useExistingPK || PrefC.RandomKeys) { Db.NonQ(command); } else { supplyNeeded.SupplyNeededNum=Db.NonQ(command,true); } return supplyNeeded.SupplyNeededNum; }
///<summary>Inserts one SupplyNeeded into the database. Provides option to use the existing priKey. Doesn't use the cache.</summary> public static long InsertNoCache(SupplyNeeded supplyNeeded, bool useExistingPK) { bool isRandomKeys = Prefs.GetBoolNoCache(PrefName.RandomPrimaryKeys); string command = "INSERT INTO supplyneeded ("; if (!useExistingPK && isRandomKeys) { supplyNeeded.SupplyNeededNum = ReplicationServers.GetKeyNoCache("supplyneeded", "SupplyNeededNum"); } if (isRandomKeys || useExistingPK) { command += "SupplyNeededNum,"; } command += "Description,DateAdded) VALUES("; if (isRandomKeys || useExistingPK) { command += POut.Long(supplyNeeded.SupplyNeededNum) + ","; } command += DbHelper.ParamChar + "paramDescription," + POut.Date(supplyNeeded.DateAdded) + ")"; if (supplyNeeded.Description == null) { supplyNeeded.Description = ""; } OdSqlParameter paramDescription = new OdSqlParameter("paramDescription", OdDbType.Text, POut.StringParam(supplyNeeded.Description)); if (useExistingPK || isRandomKeys) { Db.NonQ(command, paramDescription); } else { supplyNeeded.SupplyNeededNum = Db.NonQ(command, true, "SupplyNeededNum", "supplyNeeded", paramDescription); } return(supplyNeeded.SupplyNeededNum); }
///<summary>Updates one SupplyNeeded 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> internal static void Update(SupplyNeeded supplyNeeded,SupplyNeeded oldSupplyNeeded) { string command=""; if(supplyNeeded.Description != oldSupplyNeeded.Description) { if(command!=""){ command+=",";} command+="Description = '"+POut.String(supplyNeeded.Description)+"'"; } if(supplyNeeded.DateAdded != oldSupplyNeeded.DateAdded) { if(command!=""){ command+=",";} command+="DateAdded = "+POut.Date(supplyNeeded.DateAdded)+""; } if(command==""){ return; } command="UPDATE supplyneeded SET "+command +" WHERE SupplyNeededNum = "+POut.Long(supplyNeeded.SupplyNeededNum); Db.NonQ(command); }
///<summary>Updates one SupplyNeeded in the database.</summary> internal static void Update(SupplyNeeded supplyNeeded) { string command="UPDATE supplyneeded SET " +"Description = '"+POut.String(supplyNeeded.Description)+"', " +"DateAdded = "+POut.Date (supplyNeeded.DateAdded)+" " +"WHERE SupplyNeededNum = "+POut.Long(supplyNeeded.SupplyNeededNum); Db.NonQ(command); }
///<summary>Inserts one SupplyNeeded into the database. Returns the new priKey.</summary> public static long Insert(SupplyNeeded supplyNeeded) { return(Insert(supplyNeeded, false)); }