示例#1
0
        /// <summary>
        /// Test the connection to the database for the selected company.
        /// </summary>
        /// <param name="SessionCompany">The configuration entry for the company from which the connection string and connection timeout are retrieved.</param>
        /// <returns>Returns true if the connection could be established, otherwise returns false.</returns>
        /// <remarks>Created: Theo Crous 14/11/2011</remarks>
        //public static bool PingConnection(RegisteredCompany SessionCompany)
        public static string PingConnection(RegisteredCompany SessionCompany)
        {
            System.Data.SqlClient.SqlConnection con = null;
            try
            {
                con = new System.Data.SqlClient.SqlConnection(SessionCompany.ConnectionString);
                //con.ConnectionTimeout = Convert.ToInt32(SessionCompany.ConnectionTimeout);

                if (con.State != System.Data.ConnectionState.Open)
                {
                    con.Open();
                }

                System.Data.SqlClient.SqlCommand command = new System.Data.SqlClient.SqlCommand("select top 1 Version from [CDS_SYS].[SYS_Version] order by VersionPadded desc", con);
                string result = command.ExecuteScalar().ToString();

                //return true;
                return(result);
            }
            catch (Exception)
            {
                // Do not handle this exception
                //return false;
                return("");
            }
            finally
            {
                if (con.State != System.Data.ConnectionState.Closed)
                {
                    con.Close();
                    System.Data.SqlClient.SqlConnection.ClearPool(con);
                }
            }
        }
示例#2
0
        public ActionResult DeleteConfirmed(string id)
        {
            RegisteredCompany registeredCompany = db.RegisteredCompanies.Find(id);

            db.RegisteredCompanies.Remove(registeredCompany);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
示例#3
0
 public ActionResult Edit([Bind(Include = "id,CompanyName")] RegisteredCompany registeredCompany)
 {
     if (ModelState.IsValid)
     {
         db.Entry(registeredCompany).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(registeredCompany));
 }
示例#4
0
        public ActionResult Create([Bind(Include = "id,CompanyName")] RegisteredCompany registeredCompany)
        {
            if (ModelState.IsValid)
            {
                db.RegisteredCompanies.Add(registeredCompany);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(registeredCompany));
        }
示例#5
0
        // GET: RegisteredCompanies/Delete/5
        public ActionResult Delete(string id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            RegisteredCompany registeredCompany = db.RegisteredCompanies.Find(id);

            if (registeredCompany == null)
            {
                return(HttpNotFound());
            }
            return(View(registeredCompany));
        }
示例#6
0
        /// <summary>
        /// Set the database connection and connection timeout for the application. These values are retrieved from the config file custom section.
        /// </summary>
        /// <param name="SessionCompany">The configuration entry for the company from which the connection string and connection timeout are retrieved.</param>
        /// <returns>Returns true if connection was succesful, otherwise returns false.</returns>
        /// <remarks>Created: Theo Crous 14/11/2011</remarks>
        public static bool SetConnection(RegisteredCompany SessionCompany)
        {
            try
            {
                ApplicationDataContext.Instance.SetConnections(SessionCompany.ConnectionString, true);
                //CDS.Client.BusinessLayer.ApplicationContext.Instance.SetConnections(SessionCompany.ConnectionString, true);
                ApplicationDataContext.Instance.SqlCommandTimeOut = Convert.ToInt32(SessionCompany.ConnectionTimeout);


                return(true);
            }
            catch (Exception ex)
            {
                if (CDS.Shared.Exception.BusinessLogicExceptionHandler.HandleException(ref ex))
                {
                    throw ex;
                }
                return(false);
            }
        }
示例#7
0
        public List <RegisteredCompany> GetRegisteredCompanies()
        {
            var Regcompanies = new List <RegisteredCompany>();
            var query        = db.tbl_Companies.ToList();

            if (query != null)
            {
                foreach (var rc in query)
                {
                    var comp = new RegisteredCompany
                    {
                        Id          = rc.Id,
                        RegNo       = rc.RegNo,
                        CompanyName = rc.CompanyName,
                        Status      = rc.Status,
                        DateAdded   = rc.DateAdded
                    };
                    Regcompanies.Add(comp);
                }
            }
            return(Regcompanies);
        }