Пример #1
0
        private void btnOk_Click(object sender, EventArgs e)
        {
            if (id != -1)
            {
                using (var ctx = new UPdatabase())
                {
                    var result = ctx.UpData.SingleOrDefault(b => b.ID == id);
                    result.UserName = txtName.Text;
                    result.Password = Encryption.Encrypt(txtPassword.Text, true);
                    ctx.SaveChanges();
                }
            }
            else
            {
                var data = new DataVM();
                data.UserName = txtName.Text;
                data.Password = Encryption.Encrypt(txtPassword.Text, true);

                using (var dbCtx = new UPdatabase())
                {
                    //Add Student object into Students DBset
                    dbCtx.UpData.Add(data);

                    // call SaveChanges method to save student into database
                    dbCtx.SaveChanges();
                }
                //MessageBox.Show("Data stored in the database");
            }
            this.Close();
        }
Пример #2
0
 private void btnDelete_Click(object sender, EventArgs e)
 {
     UPdatabase ctx = new UPdatabase();
     var item = new DataVM() { ID = id };
     ctx.UpData.Attach(item);
     ctx.UpData.Remove(item);
     ctx.SaveChanges();
     GetAllDbItems.RefreshGrid(grdData);
 }
Пример #3
0
 internal static void GetAllDbData(ToolStripDropDownItem toolStripMenu)
 {
     using (UPdatabase ctx = new UPdatabase())
     {
         var allRows = ctx.UpData.ToList();
         if (toolStripMenu.DropDownItems.Count != 0)
         {
             toolStripMenu.DropDownItems.Clear();
         }
         foreach (var name in allRows)
         {
             toolStripMenu.DropDownItems.Add(name.ID + "-" + name.UserName, null, myClickHandler);
             item = ctx.UpData.FirstOrDefault(s => s.UserName == name.UserName);
         }
     }
 }