コード例 #1
0
        ///<summary>Inserts one JobProject into the database.  Provides option to use the existing priKey.  Doesn't use the cache.</summary>
        public static long InsertNoCache(JobProject jobProject, bool useExistingPK)
        {
            bool   isRandomKeys = Prefs.GetBoolNoCache(PrefName.RandomPrimaryKeys);
            string command      = "INSERT INTO jobproject (";

            if (!useExistingPK && isRandomKeys)
            {
                jobProject.JobProjectNum = ReplicationServers.GetKeyNoCache("jobproject", "JobProjectNum");
            }
            if (isRandomKeys || useExistingPK)
            {
                command += "JobProjectNum,";
            }
            command += "RootProjectNum,ParentProjectNum,Title,Description,ProjectStatus) VALUES(";
            if (isRandomKeys || useExistingPK)
            {
                command += POut.Long(jobProject.JobProjectNum) + ",";
            }
            command +=
                POut.Long(jobProject.RootProjectNum) + ","
                + POut.Long(jobProject.ParentProjectNum) + ","
                + "'" + POut.String(jobProject.Title) + "',"
                + "'" + POut.String(jobProject.Description) + "',"
                + POut.Int((int)jobProject.ProjectStatus) + ")";
            if (useExistingPK || isRandomKeys)
            {
                Db.NonQ(command);
            }
            else
            {
                jobProject.JobProjectNum = Db.NonQ(command, true, "JobProjectNum", "jobProject");
            }
            return(jobProject.JobProjectNum);
        }
コード例 #2
0
        ///<summary>Inserts one JobProject into the database.  Provides option to use the existing priKey.</summary>
        public static long Insert(JobProject jobProject, bool useExistingPK)
        {
            if (!useExistingPK && PrefC.RandomKeys)
            {
                jobProject.JobProjectNum = ReplicationServers.GetKey("jobproject", "JobProjectNum");
            }
            string command = "INSERT INTO jobproject (";

            if (useExistingPK || PrefC.RandomKeys)
            {
                command += "JobProjectNum,";
            }
            command += "RootProjectNum,ParentProjectNum,Title,Description,ProjectStatus) VALUES(";
            if (useExistingPK || PrefC.RandomKeys)
            {
                command += POut.Long(jobProject.JobProjectNum) + ",";
            }
            command +=
                POut.Long(jobProject.RootProjectNum) + ","
                + POut.Long(jobProject.ParentProjectNum) + ","
                + "'" + POut.String(jobProject.Title) + "',"
                + "'" + POut.String(jobProject.Description) + "',"
                + POut.Int((int)jobProject.ProjectStatus) + ")";
            if (useExistingPK || PrefC.RandomKeys)
            {
                Db.NonQ(command);
            }
            else
            {
                jobProject.JobProjectNum = Db.NonQ(command, true, "JobProjectNum", "jobProject");
            }
            return(jobProject.JobProjectNum);
        }
コード例 #3
0
ファイル: JobProjectCrud.cs プロジェクト: royedwards/DRDNet
 ///<summary>Inserts one JobProject into the database.  Returns the new priKey.</summary>
 public static long Insert(JobProject jobProject)
 {
     if (DataConnection.DBtype == DatabaseType.Oracle)
     {
         jobProject.JobProjectNum = DbHelper.GetNextOracleKey("jobproject", "JobProjectNum");
         int loopcount = 0;
         while (loopcount < 100)
         {
             try {
                 return(Insert(jobProject, true));
             }
             catch (Oracle.ManagedDataAccess.Client.OracleException ex) {
                 if (ex.Number == 1 && ex.Message.ToLower().Contains("unique constraint") && ex.Message.ToLower().Contains("violated"))
                 {
                     jobProject.JobProjectNum++;
                     loopcount++;
                 }
                 else
                 {
                     throw ex;
                 }
             }
         }
         throw new ApplicationException("Insert failed.  Could not generate primary key.");
     }
     else
     {
         return(Insert(jobProject, false));
     }
 }
コード例 #4
0
        ///<summary>Updates one JobProject 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(JobProject jobProject, JobProject oldJobProject)
        {
            string command = "";

            if (jobProject.RootProjectNum != oldJobProject.RootProjectNum)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "RootProjectNum = " + POut.Long(jobProject.RootProjectNum) + "";
            }
            if (jobProject.ParentProjectNum != oldJobProject.ParentProjectNum)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "ParentProjectNum = " + POut.Long(jobProject.ParentProjectNum) + "";
            }
            if (jobProject.Title != oldJobProject.Title)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "Title = '" + POut.String(jobProject.Title) + "'";
            }
            if (jobProject.Description != oldJobProject.Description)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "Description = '" + POut.String(jobProject.Description) + "'";
            }
            if (jobProject.ProjectStatus != oldJobProject.ProjectStatus)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "ProjectStatus = " + POut.Int((int)jobProject.ProjectStatus) + "";
            }
            if (command == "")
            {
                return(false);
            }
            command = "UPDATE jobproject SET " + command
                      + " WHERE JobProjectNum = " + POut.Long(jobProject.JobProjectNum);
            Db.NonQ(command);
            return(true);
        }
コード例 #5
0
        ///<summary>Updates one JobProject in the database.</summary>
        public static void Update(JobProject jobProject)
        {
            string command = "UPDATE jobproject SET "
                             + "RootProjectNum  =  " + POut.Long(jobProject.RootProjectNum) + ", "
                             + "ParentProjectNum=  " + POut.Long(jobProject.ParentProjectNum) + ", "
                             + "Title           = '" + POut.String(jobProject.Title) + "', "
                             + "Description     = '" + POut.String(jobProject.Description) + "', "
                             + "ProjectStatus   =  " + POut.Int((int)jobProject.ProjectStatus) + " "
                             + "WHERE JobProjectNum = " + POut.Long(jobProject.JobProjectNum);

            Db.NonQ(command);
        }
コード例 #6
0
 public ActionResult CreateJobProject(JobProject userInput)
 {
     ViewBag.Category = new SelectList(db.JobProjectsCategories, "Id", "Name");
     if (ModelState.IsValid)
     {
         List <JobProject> projectList = TempData.Peek("ProjectList") == null ? new List <JobProject>() : (List <JobProject>)TempData.Peek("ProjectList");
         userInput.JobProjectsCategory = db.JobProjectsCategories.Where(x => x.Id == userInput.Category).First();
         userInput.Id = Guid.NewGuid();
         projectList.Add(userInput);
         TempData["ProjectList"] = projectList;
     }
     return(View());
 }
コード例 #7
0
ファイル: JobProjectCrud.cs プロジェクト: royedwards/DRDNet
 ///<summary>Inserts one JobProject into the database.  Returns the new priKey.  Doesn't use the cache.</summary>
 public static long InsertNoCache(JobProject jobProject)
 {
     if (DataConnection.DBtype == DatabaseType.MySql)
     {
         return(InsertNoCache(jobProject, false));
     }
     else
     {
         if (DataConnection.DBtype == DatabaseType.Oracle)
         {
             jobProject.JobProjectNum = DbHelper.GetNextOracleKey("jobproject", "JobProjectNum");                  //Cacheless method
         }
         return(InsertNoCache(jobProject, true));
     }
 }
コード例 #8
0
        public ActionResult EditJobProject(JobProject userInput)
        {
            if (!ModelState.IsValid)
            {
                ViewBag.Category1 = new SelectList(db.JobProjectsCategories, "Id", "Name");
                return(View(userInput));
            }

            List <JobProject> projectList = TempData.Peek("ProjectList") == null ? new List <JobProject>() : (List <JobProject>)TempData.Peek("ProjectList");

            projectList.Remove(projectList.Where(x => x.Id == userInput.Id).First());
            userInput.JobProjectsCategory = db.JobProjectsCategories.Where(x => x.Id == userInput.Category).First();
            projectList.Add(userInput);
            TempData["ProjectList"] = projectList;
            return(RedirectToAction("CreateJobProject"));
        }
コード例 #9
0
        ///<summary>Converts a DataTable to a list of objects.</summary>
        public static List <JobProject> TableToList(DataTable table)
        {
            List <JobProject> retVal = new List <JobProject>();
            JobProject        jobProject;

            foreach (DataRow row in table.Rows)
            {
                jobProject = new JobProject();
                jobProject.JobProjectNum    = PIn.Long(row["JobProjectNum"].ToString());
                jobProject.RootProjectNum   = PIn.Long(row["RootProjectNum"].ToString());
                jobProject.ParentProjectNum = PIn.Long(row["ParentProjectNum"].ToString());
                jobProject.Title            = PIn.String(row["Title"].ToString());
                jobProject.Description      = PIn.String(row["Description"].ToString());
                jobProject.ProjectStatus    = (OpenDentBusiness.JobProjectStatus)PIn.Int(row["ProjectStatus"].ToString());
                retVal.Add(jobProject);
            }
            return(retVal);
        }
コード例 #10
0
        public ActionResult Proceed()
        {
            List <JobProject> projectList = TempData.Peek("ProjectList") == null ? new List <JobProject>() : (List <JobProject>)TempData.Peek("ProjectList");
            Guid    studentId             = (Guid)TempData.Peek("studentId");
            Student student           = db.Students.Where(x => x.Id == studentId).First();
            var     studentJobProject = student.JobProjects;

            for (int i = 0; i < studentJobProject.Count; i++)
            {
                var currentJobProject = student.JobProjects.ToArray()[i];
                if (projectList.Where(x => x.Id == currentJobProject.Id).Count() == 0)
                {
                    db.Entry(currentJobProject).State = System.Data.Entity.EntityState.Deleted;
                    db.SaveChanges();
                }
            }

            foreach (JobProject jobProject in projectList)
            {
                if (db.JobProjects.Find(jobProject.Id) != null)
                {
                    JobProject sh = db.JobProjects.Find(jobProject.Id);
                    sh.Name     = jobProject.Name;
                    sh.Descri   = jobProject.Descri;
                    sh.Duration = jobProject.Duration;
                    sh.Salary   = jobProject.Salary;
                    sh.Category = jobProject.Category;
                    db.JobProjects.Attach(sh);
                    db.Entry(sh).State = System.Data.Entity.EntityState.Modified;
                    db.SaveChanges();
                }
                else
                {
                    jobProject.JobProjectsCategory = null;
                    student.JobProjects.Add(jobProject);
                    db.SaveChanges();
                }
            }

            TempData["studentId"] = student.Id;

            TempData.Remove("ProjectList");
            return(RedirectToAction("Create", "AreaInterests"));
        }
コード例 #11
0
 ///<summary>Returns true if Update(JobProject,JobProject) 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(JobProject jobProject, JobProject oldJobProject)
 {
     if (jobProject.RootProjectNum != oldJobProject.RootProjectNum)
     {
         return(true);
     }
     if (jobProject.ParentProjectNum != oldJobProject.ParentProjectNum)
     {
         return(true);
     }
     if (jobProject.Title != oldJobProject.Title)
     {
         return(true);
     }
     if (jobProject.Description != oldJobProject.Description)
     {
         return(true);
     }
     if (jobProject.ProjectStatus != oldJobProject.ProjectStatus)
     {
         return(true);
     }
     return(false);
 }
コード例 #12
0
 ///<summary>Inserts one JobProject into the database.  Returns the new priKey.  Doesn't use the cache.</summary>
 public static long InsertNoCache(JobProject jobProject)
 {
     return(InsertNoCache(jobProject, false));
 }