Example #1
0
        private void btnTestDatabaseConnection_Click(object sender, EventArgs e)
        {
            SaveValues();
            RegistrySettings.writeValues();
            CoreFeature.getInstance().resetConnection();
            if (CoreFeature.getInstance().getDataConnection() == null)
            {
                MessageBox.Show("Can not connect to the database");
            }
            else
            {
                MessageBox.Show("Connection established");
            }

            /*
             * try
             * {
             *  SqlConnection con = new SqlConnection("Server=" + RegistrySettings.SqlHost + ";Database=" + RegistrySettings.SqlDatabase + ";Uid=" + RegistrySettings.SqlUsername + ";Pwd=" + RegistrySettings.SqlPassword);
             *  con.Open();
             *  if (con.State == ConnectionState.Open)
             *  {
             *      MessageBox.Show("Connection success!");
             *      con.Close();
             *      con.Dispose();
             *  }
             * }
             * catch (Exception ex)
             * {
             *  MessageBox.Show("Connection error : " + ex.Message);
             * }*/
        }
Example #2
0
        private void btnOk_Click(object sender, EventArgs e)
        {
            string     sql = "select * from [users] where [userid]=@userid and [password]=@password";
            SqlCommand cmd = new SqlCommand(sql, CoreFeature.getInstance().getDataConnection());

            cmd.Parameters.AddWithValue("userid", ((StaffModel)cboUsername.SelectedValue).Value);
            cmd.Parameters.AddWithValue("password", txtPassword.Text);
            SqlDataReader rdr = cmd.ExecuteReader();

            if (rdr.Read())
            {
                if (rdr.GetByte(rdr.GetOrdinal("isactive")) == 0)
                {
                    MessageBox.Show("Your account has been deactivated. Please consult your administration regarding this");
                    rdr.Close();
                    cmd.Dispose();
                    return;
                }
                Program.loginUser = new StaffModel(rdr.GetInt32(rdr.GetOrdinal("userid")), rdr.GetString(rdr.GetOrdinal("username")), "");
                rdr.Close();
                cmd.Dispose();
                graceClose = true;
                Close();
            }
            else
            {
                MessageBox.Show("You have supply a wrong credential", Application.ProductName);
                rdr.Close();
                cmd.Dispose();
                return;
            }
        }
Example #3
0
        private void timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
        {
            timer.Stop();
            string sql;

            CoreFeature.getInstance().LogActivity(LogLevel.Debug, "Begin timed activity : Logging to email account and processing the rules", EventLogEntryType.Information);
            try
            {
                //1. LOOP ALL EMAIL ACCOUNTS
                sql = "select name, server,port,use_ssl,username,password,active from account where active=1";
                SqlCommand     cmdAccount  = new SqlCommand(sql, CoreFeature.getInstance().getDataConnection());
                SqlDataReader  rdrAccount  = cmdAccount.ExecuteReader();
                List <Account> listAccount = new List <Account>();
                while (rdrAccount.Read())
                {
                    Account emailAccount = new Account(rdrAccount.GetString(rdrAccount.GetOrdinal("name")), rdrAccount.GetString(rdrAccount.GetOrdinal("server")), rdrAccount.GetInt32(rdrAccount.GetOrdinal("port")), rdrAccount.GetString(rdrAccount.GetOrdinal("username")), Cryptho.Decrypt(rdrAccount.GetString(rdrAccount.GetOrdinal("password"))), rdrAccount.GetByte(rdrAccount.GetOrdinal("use_ssl")) == 1, rdrAccount.GetByte(rdrAccount.GetOrdinal("active")) == 1);
                    listAccount.Add(emailAccount);
                    CoreFeature.getInstance().LogActivity(LogLevel.Debug, "Will use active email " + emailAccount.name, EventLogEntryType.Information);
                }
                rdrAccount.Close();

                //2. LOOP ALL NEW MESSAGES
                foreach (Account emailAccount in listAccount)
                {
                    CoreFeature.getInstance().LogActivity(LogLevel.Debug, "Logging in to email account " + emailAccount.name, EventLogEntryType.Information);
                    SqlDataReader rdrInbox = null;
                    sql = "SELECT count(*) FROM inbox i, account a where i.account_name = a.name and a.name=@name";
                    SqlCommand cmdInbox = new SqlCommand(sql, CoreFeature.getInstance().getDataConnection());
                    cmdInbox.Parameters.AddWithValue("name", emailAccount.name);
                    rdrInbox = cmdInbox.ExecuteReader();

                    if (rdrInbox.Read())
                    {
                        if (rdrInbox.GetInt32(0) == 0)
                        {
                            CoreFeature.getInstance().LogActivity(LogLevel.Debug, "No messages in inbox, try to fetch all last 30 days message to test the rule", EventLogEntryType.Information);
                            rdrInbox.Dispose();
                            CoreFeature.getInstance().FetchRecentMessages(emailAccount, true);
                        }
                        else
                        {
                            CoreFeature.getInstance().LogActivity(LogLevel.Debug, "Inbox already consisted of previous fetched message, now only fetch new message", EventLogEntryType.Information);
                            rdrInbox.Dispose();
                            CoreFeature.getInstance().FetchRecentMessages(emailAccount, false);
                        }
                    }
                    rdrInbox.Close();
                    cmdInbox.Dispose();
                }
            }
            catch (Exception ex)
            {
                CoreFeature.getInstance().LogActivity(LogLevel.Debug, "[Internal Application Error] " + ex.Message, EventLogEntryType.Error);
                if (CoreFeature.getInstance().getDataConnection() != null)
                {
                    CoreFeature.getInstance().getDataConnection().Close();
                }
            }
            timer.Start();
        }
Example #4
0
        public Settings()
        {
            InitializeComponent();

            RegistrySettings.loadValues();


            ReadValues();
            SqlConnection connection = CoreFeature.getInstance().getDataConnection();

            /*
             * lvAccount.Items.Clear();
             *
             * if (connection != null)
             * {
             *  //email accounts
             *  SqlCommand cmd;
             *  SqlDataReader rdr;
             *  cmd = connection.CreateCommand();
             *  cmd.CommandText = "select name from account order by name";
             *  cmd.CommandType = CommandType.Text;
             *  rdr = cmd.ExecuteReader();
             *
             *  while (rdr.Read())
             *  {
             *      lvAccount.Items.Add(rdr.GetString(0));
             *  }
             *  cmd.Dispose();
             *  rdr.Dispose();
             *
             *  connection.Close();
             * }
             */
            cboDatabaseType.SelectedIndex = 0;
        }
Example #5
0
        private bool saveConnection()
        {
            SqlConnection connection = CoreFeature.getInstance().getDataConnection();
            SqlCommand    cmd        = connection.CreateCommand();

            if (accountName == "")
            {
                cmd.CommandText = "insert into account(name,server,port,use_ssl,username,password,active) values ('" + txtName.Text + "','" + txtServer.Text + "'," + txtPort.Value + "," + Convert.ToInt32(chkUseSSL.Checked) + ",'" + txtUsername.Text + "','" + Cryptho.Encrypt(txtPassword.Text) + "'," + Convert.ToInt32(chkActive.Checked) + ")";
            }
            else
            {
                cmd.CommandText = "update account set name='" + txtName.Text + "', server='" + txtServer.Text + "',port=" + txtPort.Value + ",use_ssl=" + Convert.ToInt32(chkUseSSL.Checked) + ",username='******',password='******', active=" + Convert.ToInt32(chkActive.Checked) + " where name='" + accountName + "'";
            }
            cmd.CommandType = CommandType.Text;
            int rowAffected = cmd.ExecuteNonQuery();

            if (rowAffected != 1)
            {
                MessageBox.Show("Error occured in saving your connection info. Please correct them before testing connection");
                cmd.Dispose();
                connection.Close();
                return(false);
            }
            settings.updateListAccountName(txtName.Text);
            cmd.Dispose();
            connection.Close();

            return(true);
        }
Example #6
0
        public EmailAccount(string accountName, Settings settings)
        {
            InitializeComponent();
            this.accountName = accountName;
            this.settings    = settings;
            SqlConnection connection = CoreFeature.getInstance().getDataConnection();
            SqlCommand    cmd        = connection.CreateCommand();

            cmd.CommandText = "select * from account where name='" + accountName + "'";
            cmd.CommandType = CommandType.Text;
            SqlDataReader rdr = cmd.ExecuteReader();

            if (rdr.Read())
            {
                txtName.Text      = rdr.GetString(rdr.GetOrdinal("name"));
                txtServer.Text    = rdr.GetString(rdr.GetOrdinal("server"));
                txtPort.Value     = rdr.GetInt32(rdr.GetOrdinal("port"));
                chkUseSSL.Checked = rdr.GetByte(rdr.GetOrdinal("use_ssl")) == 1;
                txtUsername.Text  = rdr.GetString(rdr.GetOrdinal("username"));
                txtPassword.Text  = Cryptho.Decrypt(rdr.GetString(rdr.GetOrdinal("password")));
                chkActive.Checked = rdr.GetByte(rdr.GetOrdinal("active")) == 1;
            }

            cmd.Dispose();
            rdr.Close();
            connection.Close();
        }
Example #7
0
 private void btnOK_Click(object sender, EventArgs e)
 {
     SaveValues();
     RegistrySettings.writeValues();
     RegistrySettings.loadValues();
     CoreFeature.getInstance().resetConnection();
     Close();
 }
Example #8
0
 protected override void OnStart(string[] args)
 {
     RegistrySettings.loadValues();
     CoreFeature.getInstance().LogActivity(LogLevel.Normal, "The service was started successfully. Will checking email every " + RegistrySettings.emailCheckInterval + " second(s)", EventLogEntryType.Information);
     timer          = new Timer(RegistrySettings.emailCheckInterval * 1000); // in seconds
     timer.Elapsed += new System.Timers.ElapsedEventHandler(timer_Elapsed);
     timer.Start();                                                          // <- important
 }
Example #9
0
 private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
 {
     if (e.ColumnIndex == 6)
     {
         String     sql = "select body from inbox where idinbox=@idinbox";
         SqlCommand cmd = new SqlCommand(sql, CoreFeature.getInstance().getDataConnection());
         cmd.Parameters.Add(new SqlParameter("idinbox", dataGridView1.Rows[e.RowIndex].Cells[7].Value));
         SqlDataReader rdr = cmd.ExecuteReader();
         if (rdr.Read())
         {
             MessageBox.Show(rdr.GetString(rdr.GetOrdinal("body")));
         }
         rdr.Close();
         cmd.Dispose();
     }
 }
Example #10
0
 private void btnRemoveAccount_Click(object sender, EventArgs e)
 {
     if (lvAccount.SelectedIndex >= 0)
     {
         if (MessageBox.Show("Are you sure you want to delete this account?", Application.ProductName, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
         {
             SqlConnection connection = CoreFeature.getInstance().getDataConnection();
             SqlCommand    cmd        = connection.CreateCommand();
             cmd.CommandText = "delete from account where name='" + lvAccount.Text + "'";
             cmd.CommandType = CommandType.Text;
             cmd.ExecuteNonQuery();
             lvAccount.Items.RemoveAt(lvAccount.SelectedIndex);
             cmd.Dispose();
             connection.Close();
         }
     }
 }
Example #11
0
        private void btnShow_Click(object sender, EventArgs e)
        {
            String        sql = "select * from inbox_plain";
            SqlCommand    cmd = new SqlCommand(sql, CoreFeature.getInstance().getDataConnection());
            SqlDataReader rdr = cmd.ExecuteReader();

            dataGridView1.Rows.Clear();
            int i = 0;

            while (rdr.Read())
            {
                DataGridViewButtonColumn buttonBody = new DataGridViewButtonColumn();
                buttonBody.Text = "View";
                dataGridView1.Rows.Add(new object[] { ++i, rdr.GetString(rdr.GetOrdinal("date")), rdr.GetString(rdr.GetOrdinal("sender")), rdr.GetString(rdr.GetOrdinal("sender_ip")), rdr.GetString(rdr.GetOrdinal("to")), rdr.GetString(rdr.GetOrdinal("subject")), "View", rdr.GetInt32(rdr.GetOrdinal("idinbox")) });
            }
            rdr.Close();
            cmd.Dispose();
        }
Example #12
0
        public LoginDialog()
        {
            InitializeComponent();
            SqlCommand    cmd = new SqlCommand("select userid, username from users where [isactive]=1 order by username", CoreFeature.getInstance().getDataConnection());
            SqlDataReader rdr = cmd.ExecuteReader();

            listStaff = new List <StaffModel>();
            AutoCompleteStringCollection autoCompleteUser = new AutoCompleteStringCollection();

            while (rdr.Read())
            {
                listStaff.Add(new StaffModel(rdr.GetInt32(rdr.GetOrdinal("userid")), rdr.GetString(rdr.GetOrdinal("username")), ""));
                autoCompleteUser.Add(rdr.GetString(rdr.GetOrdinal("username")));
            }

            cboUsername.AutoCompleteCustomSource = autoCompleteUser;
            cboUsername.Items.Clear();
            cboUsername.DisplayMember = "Name";
            cboUsername.DataSource    = listStaff;
            rdr.Close();
            cmd.Dispose();
        }
Example #13
0
 protected override void OnStop()
 {
     CoreFeature.getInstance().LogActivity(LogLevel.Normal, "The service was stopped successfully.", EventLogEntryType.Information);
 }