示例#1
0
        public static string Commit(string sessionID, List <int> rowNumbers)
        {
            SessionStore session = OMS.Sessions.Find(delegate(SessionStore s) { return(s.SessionID == sessionID); });

            if (session == null)
            {
                return("INVALID_SESSION");
            }

            List <CommittedStore>      comitted   = SelectScenario.GetCommittedForCopy(session.SimulationID);
            List <ActivityResultStore> activities = SelectScenario.GetRecommendedActivities(session.SimulationID);

            try
            {
                using (SqlConnection connection = new SqlConnection(DB.ConnectionString))
                {
                    connection.Open();
                    string     insert    = "INSERT INTO " + DB.TablePrefix + "COMMITTED_ (SIMULATIONID,SECTIONID,YEARS,TREATMENTNAME,OMS_IS_NOT_ALLOWED) VALUES(@simulationID,@sectionID,@years,@treatmentName,0)";
                    SqlCommand cmdCommit = new SqlCommand(insert, connection);
                    cmdCommit.Parameters.Add(new SqlParameter("simulationID", SqlDbType.Int, 0));
                    cmdCommit.Parameters.Add(new SqlParameter("sectionID", SqlDbType.Int, 0));
                    cmdCommit.Parameters.Add(new SqlParameter("years", SqlDbType.Int, 0));
                    cmdCommit.Parameters.Add(new SqlParameter("treatmentName", SqlDbType.VarChar, 50));
                    cmdCommit.Prepare();

                    //Update the report table to show that they are committed.
                    string     update    = "UPDATE " + DB.TablePrefix + "REPORT_1_" + session.SimulationID.ToString() + " SET RESULT_TYPE=1 WHERE SECTIONID=@sectionID AND TREATMENT<>'No Treatment' AND RESULT_TYPE=0";
                    SqlCommand cmdUpdate = new SqlCommand(update, connection);
                    cmdUpdate.Parameters.Add(new SqlParameter("sectionID", SqlDbType.Int, 0));
                    cmdUpdate.Prepare();

                    foreach (int rowNumber in rowNumbers)
                    {
                        string sectionID = session.OIDs[rowNumber];
                        List <ActivityResultStore> rowActivities = activities.FindAll(delegate(ActivityResultStore a) { return(a.OID == sectionID); });
                        if (rowActivities != null)
                        {
                            foreach (ActivityResultStore activity in rowActivities)
                            {
                                //Add each to the committed table.
                                cmdCommit.Parameters[0].Value = Convert.ToInt32(session.SimulationID);
                                cmdCommit.Parameters[1].Value = Convert.ToInt32(activity.OID);
                                cmdCommit.Parameters[2].Value = Convert.ToInt32(activity.Year);
                                cmdCommit.Parameters[3].Value = activity.ActivityName;
                                cmdCommit.ExecuteNonQuery();

                                //Update the report table to show that they are committed.
                                cmdUpdate.Parameters[0].Value = sectionID;
                                cmdUpdate.ExecuteNonQuery();
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Utility.ExceptionHandling.DataAccessExceptionHandler.HandleException(ex, false);
            }
            return("SUCCESS");
        }
示例#2
0
        private static void CopyCommitted(string simulationID, string newSimulationID)
        {
            List <CommittedStore> committeds = SelectScenario.GetCommittedForCopy(simulationID);
            String myDocumentsFolder         = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);

            myDocumentsFolder += "\\RoadCare Projects\\Temp";
            Directory.CreateDirectory(myDocumentsFolder);
            string     fileOut = myDocumentsFolder + "\\oms_committed_copy_" + newSimulationID + ".txt";
            TextWriter tw      = new StreamWriter(fileOut);
            string     lineOut = null;

            foreach (CommittedStore committed in committeds)
            {
                try
                {
                    lineOut = "\t" + newSimulationID + ","
                              + committed.SectionID.ToString() + ","
                              + committed.Years.ToString() + ","
                              + committed.YearsSame.ToString() + ","
                              + committed.YearsAny.ToString() + ","
                              + committed.Budget.ToString() + ","
                              + committed.Cost.ToString() + ",";
                    if (committed.OMSIsRepeat)
                    {
                        lineOut += "1,";
                    }
                    else
                    {
                        lineOut += "0,";
                    }

                    if (committed.OMSIsExclusive)
                    {
                        lineOut += "1,";
                    }
                    else
                    {
                        lineOut += "0,";
                    }

                    if (committed.OMSIsNotAllowed)
                    {
                        lineOut += "1";
                    }
                    else
                    {
                        lineOut += "0";
                    }
                    tw.WriteLine(lineOut);
                }
                catch (Exception ex)
                {
                    int test = ex.Message.Length;
                }
            }
            tw.Close();
            using (SqlConnection connection = new SqlConnection(DB.ConnectionString))
            {
                string password   = ParsePassword(DB.ConnectionString);
                string username   = ParseUserName(DB.ConnectionString);
                string datasource = connection.DataSource;
                string database   = connection.Database;
                char   delimiter  = ',';
                string bcp        = "\"" + database + ".dbo." + DB.TablePrefix + "COMMITTED_" + "\" IN \"" + fileOut + "\" /S " + datasource + " -t\"" + delimiter + "\" -c -q -U " + username + " -P " + password;;
                System.Diagnostics.Process proc = new System.Diagnostics.Process();
                proc.EnableRaisingEvents   = false;
                proc.StartInfo.FileName    = "bcp";
                proc.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
                proc.StartInfo.Arguments   = bcp;
                proc.Start();
                proc.WaitForExit();
            }
        }