public void save()
 {
     using (MarwariContext db = new MarwariContext())
     {
         user_record.UPass = textBox2.Text;
         db.UserInfos.AddOrUpdate(user_record);
         db.SaveChanges();
         this.Close();
         this.Dispose();
         System.Drawing.Icon appIcon = System.Drawing.Icon.ExtractAssociatedIcon(Application.StartupPath + "\\DHospital.exe");
         notifyIcon.Icon            = appIcon;
         notifyIcon.Visible         = true;
         notifyIcon.BalloonTipIcon  = System.Windows.Forms.ToolTipIcon.Info;
         notifyIcon.BalloonTipTitle = "Saved";
         notifyIcon.BalloonTipText  = "Saved Successfully";
         notifyIcon.ShowBalloonTip(1000);
     }
 }
        private void save()
        {
            using (MarwariContext db = new MarwariContext())
            {
                using (TransactionScope s = new TransactionScope())
                {
                    if (rdate == "" || rdate == null)
                    {
                        rdate = System.DateTime.Now.ToString("dd-MMM-yyyy");
                        rtime = System.DateTime.Now.ToString("HH:mm:ss");
                    }

                    rtime = label9.Text;

                    int ID = int.Parse(gStr);

                    Exists = db.Accounts.Any(p => p.Ac_id == ID);

                    if (Exists)
                    {
                        Record = db.Accounts.Where(p1 => p1.Ac_id == ID).First();

                        rtime = DateTime.Parse(Record.RTime.ToString()).ToString("HH:mm:ss");
                    }
                    else
                    {
                    }


                    Record.Name   = TextBox1.Text;
                    Record.Age    = textBox2.Text;
                    Record.Number = textBox3.Text;

                    if (radioButton1.Checked == true)
                    {
                        Record.Sex = "Male";
                    }
                    else if (radioButton2.Checked == true)
                    {
                        Record.Sex = "Female";
                    }
                    else if (radioButton3.Checked == true)
                    {
                        Record.Sex = "Third Gender";
                    }

                    Record.RDate = DateTime.Now;

                    if (radioButton4.Checked == true)
                    {
                        Record.Pay = "Paid";
                    }
                    else if (radioButton5.Checked == true)
                    {
                        Record.Pay = "U.T. Free";
                    }
                    else if (radioButton6.Checked == true)
                    {
                        Record.Pay = "Free (Other)";
                    }

                    Record.Other = "";
                    Record.RDate = DateTime.Parse(rdate.ToString());
                    Record.RTime = rtime;

                    if (!Exists) //add
                    {
                        Record.Pat_id = db.Accounts.Max(p => p.Pat_id) + 1;
                        db.Accounts.Add(Record);
                    }
                    else
                    {
                        // Record.rtime = textBox4.Text;

                        // acid = Record.Ac_id;
                    }

                    //   db.SaveChanges();

                    rdate = System.DateTime.Now.ToString("dd-MMM-yyyy");
                    rtime = System.DateTime.Now.ToString("HH:mm:ss");


                    if (alter == true)
                    {
                        logrecord.RegNo   = Record.Pat_id;
                        logrecord.RDate   = DateTime.Now.Date;
                        logrecord.RTime   = DateTime.Now.ToString("HH:mm:ss");
                        logrecord.OldName = CryptoEngine.Encrypt(oldname, "Marwari-Software");
                        logrecord.NewName = CryptoEngine.Encrypt(Record.Name, "Marwari-Software");
                        //db.Logs.Add(logrecord);
                        db.Logs.AddOrUpdate(logrecord);
                    }
                    db.SaveChanges();
                    s.Complete();
                }
            }

            GC.Collect();
            System.Drawing.Icon appIcon = System.Drawing.Icon.ExtractAssociatedIcon(Application.StartupPath + "\\DHospital.exe");
            notifyIcon.Icon            = appIcon;
            notifyIcon.Visible         = true;
            notifyIcon.BalloonTipIcon  = System.Windows.Forms.ToolTipIcon.Info;
            notifyIcon.BalloonTipTitle = "Saved";
            notifyIcon.BalloonTipText  = "Saved Successfully";
            notifyIcon.ShowBalloonTip(1000);
        }