Ejemplo n.º 1
0
        private void DbGrid_CellContentDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            DbEntities db = new DbEntities();
            List <Log> list;

            switch (e.ColumnIndex)
            {
            case 0:
                list = db.Log.OrderBy(c => c.Id).ToList();
                break;

            case 1:
                list = db.Log.OrderBy(c => c.word).ToList();
                break;

            case 2:
                list = db.Log.OrderBy(c => c.key).ToList();
                break;

            case 3:
                list = db.Log.OrderBy(c => c.result).ToList();
                break;

            case 4:
                list = db.Log.OrderBy(c => c.emcoded).ToList();
                break;

            case 5:
                list = db.Log.OrderBy(c => c.datetime).ToList();

                break;

            default:
                list = db.Log.ToList();
                break;
            }
            list.Reverse();
            DbGrid.DataSource = list;
        }
Ejemplo n.º 2
0
        private void button1_Click_1(object sender, EventArgs e)
        {
            string word      = txt_textToEncode.Text;
            string encrypted = Encoder.encode(word, key);

            txt_encrypted.Text = encrypted;

            DbEntities db = new DbEntities();

            Log l = new Log();

            l.datetime = System.DateTime.Now;
            l.key      = key;
            l.word     = word;
            l.result   = encrypted;
            l.emcoded  = true;

            db.Log.Add(l);
            db.SaveChanges();

            DbGrid.DataSource = db.Log.ToList();
        }
Ejemplo n.º 3
0
        private void btn_search_Click(object sender, EventArgs e)
        {
            DbEntities db = new DbEntities();

            switch (cb_searchType.SelectedIndex)
            {
            case 0:
            {
                int id;
                if (int.TryParse(txt_fieldToSearch.Text, out id))
                {
                    switch (searchWay)
                    {
                    case 2:
                        DbGrid.DataSource = db.Log.Where(x => x.Id <= id).Select(x => x).ToList();
                        break;

                    case 1:
                        DbGrid.DataSource = db.Log.Where(x => x.Id == id).Select(x => x).ToList();
                        break;

                    case 0:
                        DbGrid.DataSource = db.Log.Where(x => x.Id >= id).Select(x => x).ToList();
                        break;
                    }
                }
            }
            break;

            case 1:
                DbGrid.DataSource = db.Log.Where(x => x.word.Contains(txt_fieldToSearch.Text)).Select(x => x).ToList();
                break;

            case 2:
                DbGrid.DataSource = db.Log.Where(x => x.key.Contains(txt_fieldToSearch.Text)).Select(x => x).ToList();
                break;

            case 3:
                DbGrid.DataSource = db.Log.Where(x => x.result.Contains(txt_fieldToSearch.Text)).Select(x => x).ToList();
                break;

            case 4:
            {
                DateTime time;
                System.Diagnostics.Debug.WriteLine("before");
                if (DateTime.TryParse(txt_fieldToSearch.Text, out time))
                {
                    System.Diagnostics.Debug.WriteLine("parsed");
                    System.Diagnostics.Debug.WriteLine(time.ToString());
                    switch (searchWay)
                    {
                    case 0:
                        DbGrid.DataSource = db.Log.Where(x => x.datetime <= time).Select(x => x).ToList();
                        break;

                    case 1:
                        DbGrid.DataSource = db.Log.Where(x => x.datetime == time).Select(x => x).ToList();
                        break;

                    case 2:
                        DbGrid.DataSource = db.Log.Where(x => x.datetime >= time).Select(x => x).ToList();
                        break;
                    }
                }
            }
            break;

            case 5:
                DbGrid.DataSource = db.Log.Where(x => x.emcoded == checkbox_encodeSerch.Checked).Select(x => x).ToList();
                break;
            }
            if (checkBox_Count.Checked)
            {
                textBox_Count.Text = DbGrid.RowCount + "";
            }
        }