コード例 #1
0
        void crtUserMenu_UserMenuClickEvent(object sender, EventArgs e, string menuItem)
        {

            //while (pnlPlaceHolder.Controls.Count > 0)
            //    pnlPlaceHolder.Controls.RemoveAt(0);

            pnlPlaceHolder.Controls.Clear();

            switch (menuItem)
            {
                case "Archive":
                    frmArchive = new frmArchiveForm();
                    frmArchive.Dock = DockStyle.Fill;
                    frmArchive.TopLevel = false;
                    //frmArchive.BackColor = Color.Transparent;
                    pnlPlaceHolder.Controls.Add(frmArchive);
                    frmArchive.Show();
                    //frmArchive.Width = pnlPlaceHolder.Width;
                    //frmArchive.WindowState = FormWindowState.Maximized;
                    //frmArchive.Refresh();
                    //frmArchive.PerformAutoScale();
                    //frmArchive.
                    //pnlPlaceHolder.Refresh();
                    break;
                case "Upload":
                    uploadForm = new frmUploadForm();
                    uploadForm.Dock = DockStyle.Fill;
                    uploadForm.ShowButtonForUpload += uploadForm_ShowButtonForUpload;
                    uploadForm.TopLevel = false;
                    //uploadForm.BackColor = Color.Transparent;
                    uploadForm.Width = pnlPlaceHolder.Width;
                    pnlPlaceHolder.Controls.Add(uploadForm);
                    //uploadForm.SearchForVideos();
                    //uploadForm.CheckForMediaOnGoProDevice();
                    if(!Context.CheckForGoProDevice())
                    {
                        MessageBox.Show(this, "GoPro camera not detected. Please connect your camera and try again.","Info",MessageBoxButtons.OK,MessageBoxIcon.Information);
                    }
                    uploadForm.Show();
                    break;
                case "Users":
                    Administration.frmUsers frmUsers = new Administration.frmUsers();
                    frmUsers.Dock = DockStyle.Fill;
                    frmUsers.TopLevel = false;                    
                    pnlPlaceHolder.Controls.Add(frmUsers);
                    frmUsers.Show();
                    break;
                case "Settings":
                    Administration.frmSettings frmSettings = new Administration.frmSettings();
                    frmSettings.Dock = DockStyle.Fill;
                    frmSettings.TopLevel = false;
                    pnlPlaceHolder.Controls.Add(frmSettings);
                    frmSettings.Show();
                    break;
                case "Audit":
                    Administration.frmAuditLog frmAudit = new Administration.frmAuditLog();
                    frmAudit.Dock = DockStyle.Fill;
                    frmAudit.TopLevel = false;
                    pnlPlaceHolder.Controls.Add(frmAudit);
                    frmAudit.Show();                    
                    break;
				case "StorageOption":
					Administration.StorageOption frmStorgeOption = new Administration.StorageOption();
					frmStorgeOption.Dock = DockStyle.Fill;
					frmStorgeOption.TopLevel = false;
					pnlPlaceHolder.Controls.Add(frmStorgeOption);
					frmStorgeOption.Show();
					break;
                default: // LOGOUT
                    isClosingFromLogout = true;
                    List<Form> openedForms = Application.OpenForms.Cast<Form>().ToList();
                    foreach (Form frmOpened in openedForms)
                    {
                        if (frmOpened.Name == "DetectorForm") continue;
                        if (frmOpened.Name == "frmLogIn")
                        {
                            frmOpened.Show();
                            ((frmLogIn)frmOpened).ContextMenuItems(false);
                            continue;
                        }
						if (frmOpened.Name == "frmProgressStatus")
						{
							if (((frmProgressStatus)frmOpened).hasUploadCompleted)
							{
								frmOpened.Close();
							}
							else
							{
								((frmProgressStatus)frmOpened).DisableCancelButtonsOnLogout(true);
							}
							continue;
						}
						else if (frmOpened.Name == this.Name)
						{
							frmOpened.Close();
							continue;
						}
                        //frmOpened.Close();
                    }

                    LoginAudit.WriteLoginAudit(CodeITConstants.LOGOUT_SUCCESSFULL);
                    
					//this.Close();
					//this.Dispose();
					//Environment.Exit(0);              
                    break;

            }
        }
コード例 #2
0
ファイル: LogIn.cs プロジェクト: petredimov/Intrensic
        private void PerformLogin()
        {
            DateTime started = DateTime.Now;

            btnLogin.Enabled = false;				

            System.Windows.Forms.Application.DoEvents();
            
            var loadingCancalationTokenSource = new CancellationTokenSource();
            var loadingCancalationToken = loadingCancalationTokenSource.Token;
            var loadingTask = new Task(() =>
            {
                var loadingForm = new frmLoading();
                loadingForm.TopMost = true;
                loadingForm.Show();
                while (!loadingCancalationToken.IsCancellationRequested)
                {
                    Thread.Sleep(50);
                    System.Windows.Forms.Application.DoEvents();
                }

                loadingForm.Close();

            }, loadingCancalationTokenSource.Token);
            loadingTask.Start();
            

            string userName = txtUserName.Text.Trim();
            string password = txtPassword.Text;

            bool hasUsers = false;

            CodeITDL.CodeITDbContext ctx = null;

            try
            {
                ctx = new CodeITDL.CodeITDbContext(0);
                
                if (ctx != null)
                {
					CodeITDL.License lic = null;
					string clientLicense = string.Empty;
					try
					{
						User user = ctx.Users.Where(d => d.UserName == userName && d.Password == password).FirstOrDefault();
						lic = ctx.Licenses.Where(s => s.Id == (ctx.UserLicenses.Where(c => c.UserId == (user.Id)).FirstOrDefault()).LicenseId).FirstOrDefault();
					}
					catch(Exception)
					{

					}
					if (lic != null)
						clientLicense = Encoding.UTF8.GetString(lic.LicenseBytes);

					if (!CodeITLicence.Licence.ValidateLicenceFromDB(clientLicense))
					{
						System.Windows.Forms.MessageBox.Show("You don't have license. Please contact administrator.", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
					}
					else
					{
						hasUsers = ctx.Users.Where(x => x.RoleId == (int)Role.Administrator && x.CustomerId == Context.CustomerId).Count() > 0;

						if (!hasUsers && userName.ToLower().Equals("administrator") && password.Equals("intrensic"))
						{
							loadingCancalationTokenSource.Cancel(true);

							System.Windows.MessageBox.Show("You are logged in as administrator, please add user with administrator role first", "Info", MessageBoxButton.OK, MessageBoxImage.Information);

							Administration.frmUsers frmUsers = new Administration.frmUsers();
							frmUsers.ControlBox = true;
							frmUsers.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Sizable;
							frmUsers.Icon = Intrensic.Properties.Resources.Intrensic;
							frmUsers.Name = "Initial User Creation Screen";
							frmUsers.isInitailUserFromLogin = true;
							frmUsers.ShowDialog();
						}
						else if (!hasUsers)
						{
							loadingCancalationTokenSource.Cancel(true);
							System.Windows.MessageBox.Show("There are no defined users and initial login information is not correct, please try again", "Info", MessageBoxButton.OK, MessageBoxImage.Information);
							txtUserName.Clear();
							txtPassword.Clear();

							txtUserName.Focus();

							LoginAudit.WriteLoginAudit(CodeITConstants.LOGIN_INCORECT_CREDENTIALS_NO_USERS);

						}
						else if (hasUsers)
						{
							User usr = new User();
							usr = ctx.Users.FirstOrDefault(x => x.UserName.ToLower().Equals(userName.ToLower()) && x.Password.ToLower().Equals(password.ToLower()) && x.CustomerId == Context.CustomerId);
							if (usr == null)
								usr = new User();

							if (usr.Id <= 0)
							{
								loadingCancalationTokenSource.Cancel(true);
								LoginAudit.WriteLoginAudit(CodeITConstants.LOGIN_INCORECT_CREDENTIALS_HAS_USERS);
								System.Windows.MessageBox.Show("Username and/or password are not correct. Please try again", "Info", MessageBoxButton.OK, MessageBoxImage.Information);
							}
							else
							{
								foreach (Form frm in System.Windows.Forms.Application.OpenForms)
								{
									if (frm.Name == "frmProgressStatus")
									{
										//check if user trying to login is user with current upload progress
										if (!((frmProgressStatus)frm).getOwnerOfUploadProcess.UserName.ToLower().Equals(userName.ToLower()))
										{
											loadingCancalationTokenSource.Cancel(true);
											LoginAudit.WriteLoginAudit(CodeITConstants.LOGIN_WHILE_UPLOAD_IN_PROGRESS_BY_DIFFERENT_USER, usr.Id);
											System.Windows.MessageBox.Show("There is an active upload process initiated by user: "******"Please wait for the upload process to complete before you are able to login", "Info", MessageBoxButton.OK, MessageBoxImage.Information);
											return;
										}
										else
										{
											((frmProgressStatus)frm).DisableCancelButtonsOnLogout(false);
										}
									}
								}

								Context.UserId = usr.Id;
							}

							if (Context.UserId > 0)
							{
								Context.UserId = usr.Id;

								LoginAudit.WriteLoginAudit(CodeITConstants.LOGIN_SUCCESSFULL);
								ContextMenuItems(true);

								txtUserName.Clear();
								txtPassword.Clear();

								frmUserMainScreen frmMain = new frmUserMainScreen();
								frmMain.InitialGoToUpload = loginStartedFromGoProDevice;
								frmMain.InitialUploadPath = uploadPath;
								frmMain.Show();
								Context.mainForm = frmMain;
								this.uploadPath = string.Empty;
								this.loginStartedFromGoProDevice = false;
								this.Hide();
								//Thread.Sleep(5000);
								loadingCancalationTokenSource.Cancel(true);

								Context.CheckForGoProDevice();
							}
						}
					}
                }
            }
            catch (Exception ex)
            {
                // 
            }
            finally
            {
                if (ctx != null)
                {
                    ctx.Dispose();
                }

                loadingCancalationTokenSource.Cancel(true);
                btnLogin.Enabled = true;
            }
        }