internal static void Main() { // ************************************************** System.Windows.Forms.Application.EnableVisualStyles(); System.Windows.Forms.Application.SetCompatibleTextRenderingDefault(false); // ************************************************** // ************************************************** Models.DatabaseContext databaseContext = null; try { databaseContext = new Models.DatabaseContext(); //int adminCount = // databaseContext.Users // .Where(current => current.IsAdmin) // .Count(); //int userCount = // databaseContext.Users // .Count(); bool hasAnyUser = databaseContext.Users .Any(); if (hasAnyUser == false) { Models.User adminUser = new Models.User(); adminUser.IsAdmin = true; adminUser.IsActive = true; adminUser.Username = "******"; adminUser.Password = "******"; adminUser.FullName = "Mr. Dariush Tasdighi"; databaseContext.Users.Add(adminUser); databaseContext.SaveChanges(); } } catch (System.Exception ex) { System.Windows.Forms.MessageBox.Show(ex.Message); return; } finally { if (databaseContext != null) { databaseContext.Dispose(); databaseContext = null; } } // ************************************************** // ************************************************** //System.Windows.Forms.Application.Run(new StartupForm()); //#region Runing Startup Form and then Disposing! //RegisterForm startupForm = new RegisterForm(); //System.Windows.Forms.Application.Run(startupForm); //if (startupForm != null) //{ // if (startupForm.IsDisposed == false) // { // startupForm.Dispose(); // } // startupForm = null; //} //#endregion /Runing Startup Form and then Disposing! //************************************************** //Infrastructure.BaseForm startupForm = new LoginForm(); //System.Windows.Forms.Application.Run(startupForm); //if (startupForm!=null) //{ // if (startupForm.IsDisposed == false) // { // startupForm.Dispose(); // } // startupForm = null; //} Infrastructure.BaseForm startupForm = new LoginForm(); System.Windows.Forms.Application.Run(startupForm); if (startupForm != null) { if (startupForm.IsDisposed == false) { startupForm.Dispose(); } startupForm = null; } //System.Windows.Forms.Application.Run(Infrastructure.Utility) }
internal static void Main() { // ************************************************** System.Windows.Forms.Application.EnableVisualStyles(); System.Windows.Forms.Application.SetCompatibleTextRenderingDefault(false); // ************************************************** #region createuserdatabase Models.DatabaseContext databaseContext = null; try { databaseContext = new Models.DatabaseContext(); bool hasAnyUser = databaseContext.Users .Any(); // ************************************************** if (hasAnyUser == false) { Models.User adminUser = new Models.User { Id = "1", IsAdmin = true, IsActive = true, Username = "******", Password = "******", FirstName = "hossein", LastName = "kalanaki", }; databaseContext.Users.Add(adminUser); databaseContext.SaveChanges(); } } catch (System.Data.Entity.Validation.DbEntityValidationException ex) { foreach (var eve in ex.EntityValidationErrors) { System.Windows.Forms.MessageBox.Show($"Entity of type \"{0}\" in state \"{1}\" has the following validation errors:", eve.Entry.Entity.GetType().Name); foreach (var ve in eve.ValidationErrors) { System.Windows.Forms.MessageBox.Show($"- Property: \"{0}\", Error: \"{1}\"", ve.PropertyName); } } return; } finally { if (databaseContext != null) { databaseContext.Dispose(); databaseContext = null; } } #endregion /createuserdatabase #region Comment code // ************************************************** // ************************************************** // ************************************************** // ************************************************** //System.Windows.Forms.Application.Run(new StartupForm()); //#region Runing Startup Form and then Disposing! //StartupForm startupForm = new StartupForm(); //System.Windows.Forms.Application.Run(startupForm); //if (startupForm != null) //{ // if (startupForm.IsDisposed == false) // { // startupForm.Dispose(); // } // startupForm = null; //} //#endregion /Runing Startup Form and then Disposing! // ************************************************** #endregion /Comment code #region Runing Login Form and then Disposing! LoginForm loginForm = new LoginForm(); System.Windows.Forms.Application.Run(loginForm); if (loginForm != null) { if (loginForm.IsDisposed == false) { loginForm.Dispose(); } loginForm = null; } #endregion /Runing Login Form and then Disposing! // ************************************************** System.Windows.Forms.Application.Run(Infrastructure.Utility.LoginForm); }
static void Main() { // ************************************************** System.Windows.Forms.Application.EnableVisualStyles(); System.Windows.Forms.Application.SetCompatibleTextRenderingDefault(false); // ************************************************** // ************************************************** //درseed جایگزین کدهای زیر تابع // میباشد Models.DatabaseContexInitializer // ************************************************** // Models.DatabaseContext oDatabaseContext = null; //try //{ // oDatabaseContext = // new Models.DatabaseContext(); // int intAdminCount = // oDatabaseContext.Users // .Where(current => current.IsAdmin) // .Count(); // if (intAdminCount == 0) // { // Models.User oAdminUser = new Models.User(); // oAdminUser.IsAdmin = true; // oAdminUser.IsActive = true; // oAdminUser.Username = "******"; // oAdminUser.Password = "******"; // oAdminUser.FullName = "Mr. Dariush Tasdighi"; // oDatabaseContext.Users.Add(oAdminUser); // oDatabaseContext.SaveChanges(); // } //} //catch (System.Exception ex) //{ // System.Windows.Forms.MessageBox.Show(ex.Message); // return; //} //finally //{ // if (oDatabaseContext != null) // { // oDatabaseContext.Dispose(); // oDatabaseContext = null; // } //} // ************************************************** //درseed جایگزین کدهای فوق تابع // میباشد Models.DatabaseContexInitializer // ************************************************** #region Runing Startup Form and then Disposing! LoginForm startupForm = new LoginForm(); //RegisterForm startupForm = new RegisterForm(); System.Windows.Forms.Application.Run(startupForm); if (startupForm != null) { if (startupForm.IsDisposed == false) { startupForm.Dispose(); } startupForm = null; } #endregion /Runing Startup Form and then Disposing! // ************************************************** }
internal static void Main() { // ************************************************** System.Windows.Forms.Application.EnableVisualStyles(); System.Windows.Forms.Application.SetCompatibleTextRenderingDefault(false); // ************************************************** // ************************************************** // ************************************************** // ************************************************** Models.DatabaseContext databaseContext = null; try { databaseContext = new Models.DatabaseContext(); // ************************************************** // ************************************************** // ************************************************** //var users = // databaseContext.Users // .ToList() // ; //int userCount = users.Count; // ************************************************** // ************************************************** //int userCount = // databaseContext.Users // .Count(); // ************************************************** // ************************************************** bool hasAnyUser = databaseContext.Users .Any(); // ************************************************** if (hasAnyUser == false) { Models.User adminUser = new Models.User { IsAdmin = true, IsActive = true, Username = "******", Password = "******", FullName = "Mr. Dariush Tasdighi" //Username = "******", //Password = "******", //FullName = "Mr. Behzad Shakeri" }; databaseContext.Users.Add(adminUser); databaseContext.SaveChanges(); } } catch (System.Exception ex) { System.Windows.Forms.MessageBox.Show(ex.Message); return; } finally { if (databaseContext != null) { databaseContext.Dispose(); databaseContext = null; } } // ************************************************** // ************************************************** // ************************************************** // ************************************************** //System.Windows.Forms.Application.Run(new StartupForm()); //#region Runing Startup Form and then Disposing! //StartupForm startupForm = new StartupForm(); //System.Windows.Forms.Application.Run(startupForm); //if (startupForm != null) //{ // if (startupForm.IsDisposed == false) // { // startupForm.Dispose(); // } // startupForm = null; //} //#endregion /Runing Startup Form and then Disposing! // ************************************************** #region Runing LoginForm and then Disposing! LoginForm loginForm = new LoginForm(); System.Windows.Forms.Application.Run(loginForm); if (loginForm != null) { if (loginForm.IsDisposed == false) { loginForm.Dispose(); } loginForm = null; } #endregion /Runing LoginForm and then Disposing! //#region Runing LoginForm and then Disposing! //MainForm MainForm = new MainForm(); //Application.Run(MainForm); //if (MainForm != null) //{ // if (MainForm.IsDisposed == false) // { // MainForm.Dispose(); // } // MainForm = null; //} //#endregion /Runing LoginForm and then Disposing! }