using System;
using System.Data;
using System.Drawing;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Globalization;
using System.Windows.Forms.DataVisualization.Charting;
using Stimulsoft.Report;
using Stimulsoft.Report.Dictionary;
using System.Media;
using DevComponents.DotNetBar;
using System.Text;
namespace DaroKhaneh
{

    public partial class Form1 : Office2007Form
    {
        public string fname;
        public string codedaro1;
        public string franshiz1;
        public int i = 0;
        public static string date;
        public bool sound = true;
        public string engheza;
        public  DataTable dtListeEngheza=new DataTable();
        public Form1()
        {
            InitializeComponent();
        }

        private void GroupSearchDaroShowAndHide(bool State)
        {
            if (State)
            {
                groupBox7.Enabled = true;
                groupBox8.Enabled = true;
                groupBox9.Enabled = true;
                groupBox10.Enabled = true;
                groupBox11.Enabled = true;
                groupBox12.Enabled = true;
            }
            else
            {
                groupBox7.Enabled = false;
                groupBox8.Enabled = false;
                groupBox9.Enabled = false;
                groupBox10.Enabled = false;
                groupBox11.Enabled = false;
                groupBox12.Enabled = false;
            }
        }
        private void hideGroupBox()
        {
            grbsearching.Visible = false;
            grblistedaro.Visible = false;
            grbhome.Visible = false;
            grbchart.Visible = false;
            grbEshterak.Visible = false;
            grbAccount.Visible = false;
            grbReportMony.Visible = false;
        }

        public void ShowReportMony()
        {
            hideGroupBox();
            grbReportMony.Visible = true;
            grbReportMony.Width = 964;
            grbReportMony.Height = 490;
            grbReportMony.Top = 195;
            grbReportMony.Left = 3;
        }

        private void grbAccountShow()
        {
            hideGroupBox();
            grbAccount.Visible = true;
            grbAccount.Width = 964;
            grbAccount.Height = 490;
            grbAccount.Top = 195;
            grbAccount.Left = 3;
        }

        public void showcharting()
        {
            hideGroupBox();
            grbchart.Visible = true;
            grbchart.Width = 964;
            grbchart.Height = 490;
            grbchart.Top = 195;
            grbchart.Left = 3;
        }

        public void showeshterak()
        {
            hideGroupBox();
            grbEshterak.Visible = true;
            grbEshterak.Width = 964;
            grbEshterak.Height = 490;
            grbEshterak.Top = 195;
            grbEshterak.Left = 3;
        }

        public void showhome()
        {
            hideGroupBox();
            grbhome.Visible = true;
            grbhome.Width = 964;
            grbhome.Height = 490;
            grbhome.Top = 195;
            grbhome.Left = 3;
        }

        public void showgrbsearch()
        {
            hideGroupBox();
            grbsearching.Visible = true;
            grbsearching.Width = 964;
            grbsearching.Height = 490;
            grbsearching.Top = 195;
            grbsearching.Left = 3;
        }

        public void showlisetdaro()
        {
            hideGroupBox();
            grblistedaro.Visible = true;
            grblistedaro.Width = 964;
            grblistedaro.Height = 490;
            grblistedaro.Top = 195;
            grblistedaro.Left = 3;
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            txteshterak.Focus();
            addDaro.Enabled = login.cadddaro;
            charting.Enabled = login.chart;
            ribpedit.Enabled = login.caddpezeshk;
            addEshterak.Enabled = login.caddeshterak;
            addAccont.Enabled = login.cadduser;
            Bank.Enabled = login.cnezarat;
            if (login.caddpezeshk == false)
                SearchNoskhe.Select();
            if (login.voice) swsound.Value = true;

            datefull();
            elanmessage.ColorScheme = DevComponents.DotNetBar.Controls.eWarningBoxColorScheme.Green;
            Width = 970;
            Height = 712;

            rating.SetRating(login.rating, DevComponents.DotNetBar.eEventSource.Mouse);

            PersianCalendar PerCal = new PersianCalendar();
            string Year, Day, Month;
            Year = PerCal.GetYear(DateTime.Now).ToString();
            Month = PerCal.GetMonth(DateTime.Now).ToString("D2");
            Day = PerCal.GetDayOfMonth(DateTime.Now).ToString("D2");
            date = Year + "/" + Month + "/" + Day;

            txtdatenow.Text = date;
            lbldatehead.Text = date;
            countmessage();

            showhome();
            styleManager1.ManagerStyle = Properties.Settings.Default.Theme;
            txtBackUpAndRestorAddress.Text = Properties.Settings.Default.Address;
            System.Collections.ArrayList items = ribbonControl1.RibbonStrip.GetItems("", typeof (SystemCaptionItem));
            foreach (SystemCaptionItem sci in items)
            {
                if (!sci.IsSystemIcon)
                {
                    sci.MinimizeVisible = true;
                    sci.MinimizeEnabled = true;
                    sci.RestoreMaximizeVisible = false;
                    sci.CloseVisible = true;
                    sci.Visible = true;
                    break;
                }
            }
        }

        

        public void Searcheshterak(string query)
        {
            SqlConnection con = new SqlConnection();
            con.ConnectionString = "server=(local);database=darokhane;trusted_connection=yes";

            SqlCommand com = new SqlCommand();
            com.Connection = con;
            com.CommandText = query;

            SqlDataAdapter da = new SqlDataAdapter();
            da.SelectCommand = com;

            DataSet dt = new DataSet();
            da.Fill(dt);
            if (dt.Tables.Count > 0)
            {
                txtnbimar.Text = dt.Tables[0].Rows[0][0] + " " + dt.Tables[0].Rows[0][1];
                txtetebar.Text = dt.Tables[0].Rows[0][2].ToString();
                txtbimeh.Text = dt.Tables[0].Rows[0][4].ToString();
                string[] datenow = lbldatehead.Text.ToString().Split('/');
                string[] sen = dt.Tables[0].Rows[0][2].ToString().Split('/');
                lblsen.Text = (int.Parse(datenow[0].ToString()) - int.Parse(sen[0].ToString())).ToString() + " سال";
                lblcheckvalueseshterak.Text = "1";
                btn_addEshterak.Enabled = false;
                txtserial.Enabled = true;
                txtserial.BackColor = Color.Yellow;
            }
        }

        public void search(string query)
        {
            SqlConnection con = new SqlConnection();
            con.ConnectionString = "server=(local);database=darokhane;trusted_connection=yes";

            SqlCommand com = new SqlCommand();
            com.Connection = con;
            com.CommandText = query;

            SqlDataAdapter da = new SqlDataAdapter();
            da.SelectCommand = com;

            DataSet dt = new DataSet();
            da.Fill(dt);
            if (dt.Tables.Count > 0)
            {
                txtpname.Text = dt.Tables[0].Rows[0][0].ToString();
                cmbsearch.Enabled = true;
                txtsearchdaro.Enabled = true;
                txttedad.Enabled = true;
                btninsert.Enabled = true;
                btnsabtenoskhe.Enabled = true;
                btn_addPezeshk.Enabled = false;
            }
        }

        private void txtpcode_TextChanged_1(object sender, EventArgs e)
        {
            if (txtpcode.Text != "")
            {
                lblstarpcode.Visible = false;
                try
                {
                    search("select pname from pezeshk where State='True' and pid='" + txtpcode.Text + "'");
                }
                catch
                {
                    btn_addPezeshk.Enabled = true;
                    cmbsearch.Enabled = true;
                    txtsearchdaro.Enabled = true;
                    txttedad.Enabled = true;
                    btninsert.Enabled = true;
                    btnsabtenoskhe.Enabled = true;
                    txtpname.Text = @"پیدانشد";
                }
            }
            else
            {
                btn_addPezeshk.Enabled = false;
                lblstarpcode.Visible = true;
                txtpname.Clear();
                cmbsearch.Enabled = false;
                txtsearchdaro.Enabled = false;
                txttedad.Enabled = false;
                btninsert.Enabled = false;
                btnsabtenoskhe.Enabled = false;
            }
        }

        public void Falsetext()
        {
            txtnewptakhasos.Enabled = false;
            txtnewpname.Enabled = false;
            txtnewpid.Enabled = false;
            btneditpezeshk.Enabled = false;
            txtnewptakhasos.Text = "";
            txtnewpname.Text = "";
            txtnewpid.Text = "";
        }

        private void txteshterak_TextChanged_1(object sender, EventArgs e)
        {
            if (txteshterak.Text != "")
            {
                lblstareshterak.Visible = false;
                try
                {
                    Searcheshterak("select bname,bfamily,birthday,etebardate,nbimeh from eshterak where State='True' and codemeli='" +
                                   txteshterak.Text + "'");
                }
                catch
                {
                    btn_addPezeshk.Enabled = false;
                    txtserial.Enabled = false;
                    txtserial.BackColor = grbEditDaro.BackColor;
                    txtpcode.Enabled = false;
                    txtpcode.BackColor = grbEditDaro.BackColor;
                    btn_addEshterak.Enabled = true;
                    txtnbimar.Text = @"پیدانشد";
                    lblcheckvalueseshterak.Text = "0";
                    return;
                }
            }
            else lblstareshterak.Visible = true;
        }

        private void btnadduser_Click_1(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(txtuser.Text) && !string.IsNullOrEmpty(txtpassword.Text) && !string.IsNullOrEmpty(txtkname.Text))
            {
                try
                {
                    SqlConnection con = new SqlConnection("server=.;database=darokhane;trusted_connection=yes");
                    SqlCommand com = new SqlCommand();
                    com.CommandText =
                        "insert into accont (uname,upass,rating,cadddaro,chart,cadduser,caddpezeshk,cnezarat,caddeshterak,NameFamily) values (@uname,@upass,@rating,@cadddaro,@chart,@cadduser,@caddpezeshk,@cnezarat,@caddeshterak,@NameFamily)";
                    com.Parameters.AddWithValue("@uname", txtuser.Text);
                    com.Parameters.AddWithValue("@upass", txtpassword.Text);
                    com.Parameters.AddWithValue("@rating", ratinguser.RatingValue);
                    com.Parameters.AddWithValue("@cadddaro", Convert.ToBoolean(sw1.Value).ToString());
                    com.Parameters.AddWithValue("@chart", Convert.ToBoolean(sw2.Value).ToString());
                    com.Parameters.AddWithValue("@cadduser", Convert.ToBoolean(sw3.Value).ToString());
                    com.Parameters.AddWithValue("@caddpezeshk", Convert.ToBoolean(sw4.Value).ToString());
                    com.Parameters.AddWithValue("@cnezarat", Convert.ToBoolean(sw5.Value).ToString());
                    com.Parameters.AddWithValue("@caddeshterak", Convert.ToBoolean(sw6.Value).ToString());
                    com.Parameters.AddWithValue("@NameFamily", txtkname.Text);
                    com.Connection = con;
                    con.Open();
                    com.ExecuteNonQuery();
                    con.Close();
                    ribbonTabItem4_Click(sender, e);
                    playsoundclick("\\sound\\login.wav");
                }
                catch (Exception)
                {

                    /////////////////////////
                    showElanatNoOptionButton(
                        "   شما اجازه ثبت این کاربر را ندارید زیرا قبلا در سیستم ثبت شده است", "red");
                    /////////////////////////

                } 
            }
            else
            {
                /////////////////////////
                showElanatNoOptionButton(
                    "   لطفا تمام فیلدهای مربوطه را  با دقت کامل نمایید", "red");
                /////////////////////////
            }
        }
 

        private void buttonItem8_Click(object sender, EventArgs e)
        {
            try
            {
                sendFastMessage(txtusendmessage.Text, txtsmessage.Text, txtsubject.Text,login.uname);
                playsoundclick("\\sound\\mouse.wav");
            }
            catch
            {
                showElanatNoOptionButton("در حین انجام عملیات خطایی رخ داده است. لطفا مجددا تلاش کنید", "red");
            }
        }

        private void sendFastMessage(string SendTo, string message, string subject,string Sender)
        {
            try
            {
                SqlConnection con = new SqlConnection("server=.;database=darokhane;trusted_connection=yes");
                SqlCommand com = new SqlCommand();
                com.CommandText =
                    "insert into message (uname,suname,message,date,time,readmessage,subject) values (@uname,@suname,@message,@date,@time,@readmessage,@subject)";
                com.Parameters.AddWithValue("@uname", SendTo);
                com.Parameters.AddWithValue("@suname", Sender);
                com.Parameters.AddWithValue("@message", message);
                com.Parameters.AddWithValue("@date", lbldatehead.Text);
                com.Parameters.AddWithValue("@time", DateTime.Now.ToLongTimeString());
                com.Parameters.AddWithValue("@readmessage", 0);
                com.Parameters.AddWithValue("@subject", subject);
                com.Connection = con;
                con.Open();
                com.ExecuteNonQuery();
                con.Close();
            }
            catch
            {
                SqlCommand com = new SqlCommand();
                com.CommandText =
                    "update message set uname=@uname,suname=@suname,message=@message,date=@date,time=@time,readmessage=@readmessage,subject=@subject where Subject=@SubjectWhere and suname=@sunameWhere";
                com.Parameters.AddWithValue("@uname", SendTo);
                com.Parameters.AddWithValue("@suname", Sender);
                com.Parameters.AddWithValue("@message", message);
                com.Parameters.AddWithValue("@date", lbldatehead.Text);
                com.Parameters.AddWithValue("@time", DateTime.Now.ToLongTimeString());
                com.Parameters.AddWithValue("@readmessage", 0);
                com.Parameters.AddWithValue("@subject", subject);
                com.Parameters.AddWithValue("@subjectWhere", subject);
                com.Parameters.AddWithValue("@sunameWhere", Sender);
                UpdateAndInsert(com);
            }
        }
        private void buttonItem6_Click(object sender, EventArgs e)
        {
            playsoundclick("\\sound\\click.wav");
            message frm = new message();
            frm.ShowDialog();
        }

        private void ribbonTabItem2_Click(object sender, EventArgs e)
        {
            try
            {
                showbimeh("select bimeh.id as [کدبیمه],bimeh.bname as [نام بیمه],State from bimeh");
            }
            
            catch (Exception)
            {
                
                throw;
            }
            finally
            {
                //dgvEshterak.a
                showeshterak();
                showeshterakList("select codemeli as [کد ملی],eshterak.bname+' '+eshterak.bfamily as [نام بیمار],eshterak.birthday as [تاریخ تولد],eshterak.datesabt as [تاریخ ثبت],eshterak.etebardate as [اعتبار بیمه],bimeh.bname as [نام بیمه],eshterak.State,eshterak.bname as [نام],eshterak.bfamily as [نام خانوادگی] from eshterak inner join bimeh on bimeh.id=eshterak.nbimeh");
            }
            ChangColorDataGridDelete(dgvBimeh);
        }

        private void showeshterakList(string query)
        {
            try
            {
                SqlConnection con = new SqlConnection("server=(local);database=darokhane;trusted_connection=yes");
                SqlDataAdapter da =
                    new SqlDataAdapter(query, con);
                DataTable dt = new DataTable();
                da.Fill(dt);
                dgvEshterak.DataSource = dt;
                
                dgvEshterak.Columns[0].Width = 85;
                dgvEshterak.Columns[1].Width = 145;
                dgvEshterak.Columns[2].Width = 86;
                dgvEshterak.Columns[3].Width = 86;
                dgvEshterak.Columns[4].Width = 86;
                dgvEshterak.Columns[5].Width = 140;
                dgvEshterak.Columns[6].Visible = false;
                dgvEshterak.Columns[7].Visible = false;
                dgvEshterak.Columns[8].Visible = false;
                
                ChangColorDataGridDelete(dgvEshterak);
            }
            catch
            {
                showElanatNoOptionButton("   خطایی در ارتباط با بانک رخ داده است","red");
            }
        }
        private void btnaddbimeh_Click(object sender, EventArgs e)
        {
            try
            {
                SqlConnection con = new SqlConnection();
                con.ConnectionString = "server=(local);database=darokhane;trusted_connection=yes";
                SqlCommand com = new SqlCommand();
                com.Connection = con;
                com.CommandText = "insert into bimeh (id,bname) values (@id,@bname)";
                com.Parameters.AddWithValue("@id", txtbimehcode.Text);
                com.Parameters.AddWithValue("@bname", txtbimehname.Text);

                con.Open();
                com.ExecuteNonQuery();
                con.Close();
                ribbonTabItem2_Click(sender, e);
                lblbimehmessage.Text = "بیمه جدید اضافه شد";
                lblbimehmessage.ForeColor = Color.Black;

                string message = "بیمه ای با نام \"{0}\" به بیمه های طرف قراداد داروخانه اضافه شد.";
                message = string.Format(message, txtbimehname.Text);
                showElanatNoOptionButton(message, "green");

            }
            catch
            {
                showElanatNoOptionButton(
                    "این شرکت بیمه در سیستم ثبت شده است. به کد بیمه گر توجه کنید که اشتباها وارد نشده باشد", "red");

                lblbimehmessage.Text = "کد بیمه تکراری است";
                lblbimehmessage.ForeColor = Color.Red;
            }
        }

        private void btnpsearch_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(txtpidedit.Text))
            {
                try
                {
                    SqlConnection con = new SqlConnection();
                    con.ConnectionString = "server=(local);database=darokhane;trusted_connection=yes";

                    SqlCommand com = new SqlCommand();
                    com.Connection = con;
                    com.CommandText = "select * from pezeshk where pid=" + txtpidedit.Text;

                    SqlDataAdapter da = new SqlDataAdapter();
                    da.SelectCommand = com;
                    DataSet ds = new DataSet();
                    da.Fill(ds);
                    lbleditp.Text = "مشخصات را ویرایش کنید";
                    lbleditp.ForeColor = Color.Black;
                    txtnewptakhasos.Enabled = true;
                    txtnewpname.Enabled = true;
                    btneditpezeshk.Enabled = true;
                    txtnewpid.Text = ds.Tables[0].Rows[0][0].ToString();
                    txtnewpname.Text = ds.Tables[0].Rows[0][1].ToString();
                    txtnewptakhasos.Text = ds.Tables[0].Rows[0][2].ToString();
                    playsoundclick("\\sound\\click.wav");
                }
                catch
                {
                    lbleditp.Text = @"پزشکی یافت نشد";
                    lbleditp.ForeColor = Color.Red;
                    Falsetext();
                }
            }
        }

        private void btneshterakadd_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(txtcodemeli.Text) && !string.IsNullOrEmpty(txtname.Text) && !string.IsNullOrEmpty(txtfamily.Text) && !string.IsNullOrEmpty(txtdatebirth.Text) && !string.IsNullOrEmpty(txtdateetebar.Text) && !string.IsNullOrEmpty(txtdatesabt.Text))
            {
                try
                {
                    SqlConnection con = new SqlConnection("server=.;database=darokhane;trusted_connection=yes");
                    SqlCommand com = new SqlCommand();
                    com.Connection = con;
                    com.CommandText = "insert into eshterak (codemeli,bname,bfamily,birthday,nbimeh,etebardate,datesabt) ";
                    com.CommandText += "values (@codemeli,@bname,@bfamily,@birthday,@nbimeh,@etebardate,@datesabt)";
                    com.Parameters.AddWithValue("@codemeli", txtcodemeli.Text);
                    com.Parameters.AddWithValue("@bname", txtname.Text);
                    com.Parameters.AddWithValue("@bfamily", txtfamily.Text);
                    com.Parameters.AddWithValue("@birthday", txtdatebirth.Text.ToString());
                    com.Parameters.AddWithValue("@nbimeh", lblcodebimeh.Text);
                    com.Parameters.AddWithValue("@etebardate", txtdateetebar.Text.ToString());
                    com.Parameters.AddWithValue("@datesabt", txtdatesabt.Text.ToString());
                    con.Open();
                    com.ExecuteNonQuery();
                    con.Close();
                    /////////////////////////
                    showElanatNoOptionButton(
                        "مشترک جدید در سیستم ثبت شد. دقت کنید که کد ملی مشترک شماره ی اشتراک آن می باشد", "green");
                    /////////////////////////
                    lblbimehmessage.Text = "مشترک جدید ثبت شد";
                    lblbimehmessage.ForeColor = Color.Black;
                    playsoundclick("\\sound\\login.wav");
                    if (lblsendEshterak.Text == "1")
                    {
                        txteshterak.Text = txtcodemeli.Text;
                        lblsendEshterak.Text = "0";
                        txteshterak.Focus();
                        showhome();
                    }
                }
                catch
                {
                    /////////////////////////
                    showElanatNoOptionButton(
                        "فردی با این کد ملی قلا در سیستم ثبت شده است. لطفا با دقت بیشتر مشخصات را وارد کنید", "red");
                    /////////////////////////

                    lblbimehmessage.Text = @"کد ملی تکراری است";
                    lblbimehmessage.ForeColor = Color.Red;
                    txtcodemeli.Focus();
                } 
            }
            else
            {
                /////////////////////////
                showElanatNoOptionButton(
                    "   لطفا تمام فیلدهای مربوطه را  با دقت کامل نمایید", "red");
                /////////////////////////
            }
        }

        private void btnadddaro_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(txtcodedaro.Text) && !string.IsNullOrEmpty(txtlname.Text) && 
                !string.IsNullOrEmpty(txtfname.Text) && !string.IsNullOrEmpty(txttolid.Text) && 
                !string.IsNullOrEmpty(txtengheza.Text) && !string.IsNullOrEmpty(txtgheymat.Text) && 
                !string.IsNullOrEmpty(txtanbar.Text) && !string.IsNullOrEmpty(txtghafase.Text) && 
                !string.IsNullOrEmpty(txttarkibat.Text) && !string.IsNullOrEmpty(txttedadeavalie.Text))
            {
                try
                {
                    SqlConnection con = new SqlConnection("server=.;database=darokhane;trusted_connection=yes");
                    SqlCommand com = new SqlCommand();
                    com.Connection = con;
                    com.CommandText =
                        "insert into home (id,lname,fname,tolid,engheza,gheymat,anbar,ghafase,tarkibat,compony,tedad,State) values (@id,@lname,@fname,@tolid,@engheza,@gheymat,@anbar,@ghafase,@tarkibat,@compony,@tedad,@State)";
                    com.Parameters.AddWithValue("@id", txtcodedaro.Text);
                    com.Parameters.AddWithValue("@lname", txtlname.Text);
                    com.Parameters.AddWithValue("@fname", txtfname.Text);
                    com.Parameters.AddWithValue("@tolid", txttolid.Text);
                    com.Parameters.AddWithValue("@engheza", txtengheza.Text);
                    com.Parameters.AddWithValue("@gheymat", txtgheymat.Text);
                    com.Parameters.AddWithValue("@anbar", txtanbar.Text);
                    com.Parameters.AddWithValue("@ghafase", txtghafase.Text);
                    com.Parameters.AddWithValue("@tarkibat", txttarkibat.Text);
                    com.Parameters.AddWithValue("@compony", txtcompony.Text);
                    com.Parameters.AddWithValue("@tedad", txttedadeavalie.Text);
                    com.Parameters.AddWithValue("@State", true);
                    con.Open();
                    com.ExecuteNonQuery();
                    con.Close();
                    lblsabtedaromessage.Visible = true;
                    playsoundclick("\\sound\\login.wav");
                    btnLoadAllDaro_Click(sender, e);
                    /////////////////////////
                    showElanatNoOptionButton(
                        "داروی مورد نظر با موفقیت در سیستم ثبت شد", "green");
                    /////////////////////////
                }
                catch
                {
                    /////////////////////////
                    showElanatNoOptionButton(
                        "این دارو قبلا در سیستم ثبت شده است. در قسمت پایین میتوانید دارو را بروز کنید", "red");
                    /////////////////////////
                } 
            }
            else
            {
                /////////////////////////
                showElanatNoOptionButton(
                    "   لطفا تمام فیلدهای مربوطه را  با دقت کامل نمایید", "red");
                /////////////////////////
            }
        }

        private void btnaddpezeshk_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(txtcode.Text) && !string.IsNullOrEmpty(txtspname.Text) && !string.IsNullOrEmpty(txttakhasos.Text))
            {
                try
                {
                    SqlConnection con = new SqlConnection("server=.;database=darokhane;trusted_connection=yes");
                    SqlCommand com = new SqlCommand();
                    com.CommandText = "insert into pezeshk (pid,pname,takhasos,State) values (@pid,@pname,@takhasos,@State)";
                    com.Parameters.AddWithValue("@pid", txtcode.Text);
                    com.Parameters.AddWithValue("@pname", txtspname.Text);
                    com.Parameters.AddWithValue("@takhasos", txttakhasos.Text);
                    com.Parameters.AddWithValue("@State", true);
                    com.Connection = con;
                    con.Open();
                    com.ExecuteNonQuery();
                    con.Close();
                    /////////////////////////
                    string message = "پزشکی با نام \"{0}\" و با کد نظام پزشکی \"{1}\" در سیستم با موفقیت ثبت شد.";
                    message = string.Format(message, txtspname.Text, txtcode.Text);
                    showElanatNoOptionButton(message, "green");
                    /////////////////////////
                    lbladdpezeshk.Text = "پزشک مورد نظر با موفقیت اضافه شد";
                    playsoundclick("\\sound\\login.wav");
                    if (lblsendAddPezeshk.Text == "1")
                    {
                        txtpcode.Text = "";
                        txtpcode.Text = txtcode.Text;
                        lblsendAddPezeshk.Text = "0";
                        txtpcode.Focus();
                    }
                }
                catch
                {
                    /////////////////////////
                    showElanatNoOptionButton(
                        "این پزشک قبلا در سیستم ثبت شده است. لطفا کد نظام پزشکی را با دقت بیشتر وارد کنید", "red");
                    /////////////////////////
                }
            }
            else
            {
                /////////////////////////
                showElanatNoOptionButton(
                    "   لطفا تمام فیلدهای مربوطه را  با دقت کامل نمایید", "red");
                /////////////////////////
            }
        }

        private void btnpdelete_Click(object sender, EventArgs e)
        {
            if (txtcodepd.Text != "")
            {
                try
                {
                    SqlConnection con = new SqlConnection();
                    con.ConnectionString = "server=(local);database=darokhane;trusted_connection=yes";

                    SqlCommand com = new SqlCommand();
                    com.Connection = con;
                    com.CommandText = "select * from pezeshk where pid=" + txtcodepd.Text;
                    SqlDataAdapter da = new SqlDataAdapter();
                    da.SelectCommand = com;
                    DataTable dt = new DataTable();
                    da.Fill(dt);

                    if (dt.Rows.Count == 1)
                    {
                        SqlCommand com1 = new SqlCommand();
                        com1.Connection = con;
                        com1.CommandText = "update pezeshk set State=@State where pid=@pid";
                        com1.Parameters.AddWithValue("@State", false);
                        com1.Parameters.AddWithValue("@pid", txtcodepd.Text);
                        UpdateAndInsert(com1);
                        /////////////////////////
                        showElanatNoOptionButton(
                            "پزشک انتخاب شده از سیستم حذف شد. دقت کنید که تمام مشخصات این پزشک در سیستم وجود دارد ولی دیگر قابل انتخاب نیست",
                            "yellow");
                        /////////////////////////
                        lblpdelete.ForeColor = Color.Black;
                    }
                    else
                    {
                        lblpdelete.Text = "پزشکی یافت نشد";
                        lblpdelete.ForeColor = Color.Red;
                    }
                }
                catch
                {
                    /////////////////////////
                    showElanatNoOptionButton(
                        "متاسفانه در واکشی درخواست شما فردی با مشخصات وارد شده پیدا نشد. امکان دارد این پزشک در سیستم ثبت نشده باشد",
                        "yellow");
                    /////////////////////////
                    lblpdelete.Text = "پزشکی یافت نشد";
                    lblpdelete.ForeColor = Color.Red;
                }
            }
        }

        private void cbbimeh_TextChanged(object sender, EventArgs e)
        {
            try
            {
                SqlConnection con = new SqlConnection();
                con.ConnectionString = "server=(local);database=darokhane;trusted_connection=yes";

                SqlCommand com = new SqlCommand();
                com.Connection = con;
                com.CommandText = "select * from bimeh where bname=N'" + cbbimeh.Text + "'";
                SqlDataAdapter da = new SqlDataAdapter();
                da.SelectCommand = com;
                DataSet ds = new DataSet();
                da.Fill(ds);
                lblcodebimeh.Text = ds.Tables[0].Rows[0][0].ToString();
            }
            catch
            {
            }
            ;
        }

        private void ratinguser_RatingChanged(object sender, EventArgs e)
        {
            if (ratinguser.Rating == 5)
            {
                sw1.Value = true;
                sw2.Value = true;
                sw3.Value = true;
                sw4.Value = true;
                sw5.Value = true;
                sw6.Value = true;
            }
        }

        private void txtmojodi_TextChanged(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(txtmojodi.Text))
            {
                if (int.Parse(txtmojodi.Text) < 100)
                {
                    string message =
                        "مدیریت محترم دارویی با کد {0} در حال اتمام می باشد. موجودی کل این دارو برابر با {1} عدد می باشد. لطفا نسبت به خرید آن اقدام کنید";
                    message = string.Format(message, txtiddarosearch.Text, txtmojodi.Text);
                    sendmessageforadmin(message, "در حال اتمام دارو");
                    string subject = "دارویی با کد {0} در حال اتمام است";
                    subject = string.Format(subject, txtiddarosearch.Text);
                    sendFastMessage("admin", message, subject, "Robot_Smart");
                }
                if (int.Parse(txtmojodi.Text.ToString()) <= 0)
                {
                    /////////////////////////
                    showElanatNoOptionButton(
                        "متاسفانه داروی مورد نظر به اتمام رسیده است. درخواست خرید برای مدیریت بطور هوشمند ارسال شد", "red");
                    /////////////////////////

                    btninsert.Enabled = false;
                    string message =
                        "مدیریت محترم دارویی با کد {0} در داروخانه موجود نمی باشد. لطفا نسبت به خرید آن اقدام کنید";
                    message = string.Format(message, txtiddarosearch.Text);
                    sendmessageforadmin(message, "اتمام دارو");
                    string subject = "دارویی با کد {0} به اتمام رسیده است";
                    subject = string.Format(subject, txtiddarosearch.Text);
                    sendFastMessage("admin", message, subject, "Robot_Smart");
                } 
            }
        }

        private void sendmessageforadmin(string message, string subject)
        {
            try
            {
                SqlConnection con = new SqlConnection("server=.;database=darokhane;trusted_connection=yes");
                txtusendmessage.Text = "admin";
                txtsmessage.Text = message;
                txtsubject.Text = subject;
                SqlCommand com = new SqlCommand();
                com.CommandText =
                    "insert into ListeBuy (iddaro,uname,suname,message,date,time,subject) values (@iddaro,@uname,@suname,@message,@date,@time,@subject)";
                com.Parameters.AddWithValue("@iddaro", txtiddarosearch.Text);
                com.Parameters.AddWithValue("@uname", txtusendmessage.Text);
                com.Parameters.AddWithValue("@suname", login.uname);
                com.Parameters.AddWithValue("@message", txtsmessage.Text);
                com.Parameters.AddWithValue("@date", lbldatehead.Text);
                com.Parameters.AddWithValue("@time", DateTime.Now.ToLongTimeString());
                com.Parameters.AddWithValue("@subject", txtsubject.Text);
                com.Connection = con;
                con.Open();
                com.ExecuteNonQuery();
                con.Close();
            }
            catch
            {
            }

        }

        private void txtkolepardakht_TextChanged(object sender, EventArgs e)
        {
            if (txtkolepardakht.Text == "" || txtkolepardakht.Text == @"0") return;
            decimal price;
            price = decimal.Parse(txtkolepardakht.Text, System.Globalization.NumberStyles.Currency);
            txtkolepardakht.Text = price.ToString("#,#");
            txtkolepardakht.SelectionStart = txtkolepardakht.Text.Length;

            tabdilbehorof convert = new tabdilbehorof();
            txtkolbehorof.Text=convert.Tabdilbehorof(txtkolepardakht.Text.ToString())+"ریال";
            //string a = tabdilbehorof(txtkolepardakht.Text.ToString());
            //txtkolbehorof.Text = a + "ریال";
        }

        private void txtsahmebimar_TextChanged(object sender, EventArgs e)
        {
            if (txtsahmebimar.Text == "" || txtsahmebimar.Text == "0") return;
            decimal price;
            price = decimal.Parse(txtsahmebimar.Text, System.Globalization.NumberStyles.Currency);
            txtsahmebimar.Text = price.ToString("#,#");
            txtsahmebimar.SelectionStart = txtsahmebimar.Text.Length;
        }

        private void txtjamebime_TextChanged(object sender, EventArgs e)
        {
            if (txtjamebime.Text == "" || txtjamebime.Text == "0") return;
            decimal price;
            price = decimal.Parse(txtjamebime.Text, System.Globalization.NumberStyles.Currency);
            txtjamebime.Text = price.ToString("#,#");
            txtjamebime.SelectionStart = txtjamebime.Text.Length;
        }

        public string createcodenoskhe()
        {
            string[] time = DateTime.Now.ToLongTimeString().Split(':');
            string[] time1 = time[2].Split(' ');
            string[] date = lbldatehead.Text.Split('/');
            return (date[0] + date[1] + date[2] + time[0] + time[1] + time1[0] + txtserial.Text.ToString());
        }

        public void insertcodenoskhe()
        {
            try
            {
                SqlConnection con = new SqlConnection("server=.;database=darokhane;trusted_connection=yes");
                string code = createcodenoskhe();
                SqlCommand com = new SqlCommand();
                com.CommandText =
                    "insert into listecodenoskhe (codenoskhe,datesabt,idbimar,datefull,mablaghekol,franshizekol,mablaghepardakhti) values (@codenoskhe,@datesabt,@idbimar,@datefull,@mablaghekol,@franshizekol,@mablaghepardakhti)";
                com.Parameters.AddWithValue("@codenoskhe", code);
                com.Parameters.AddWithValue("@datesabt", txtdatenow.Text);
                com.Parameters.AddWithValue("@idbimar", txteshterak.Text.Trim());
                com.Parameters.AddWithValue("@datefull", txtsabt.Text);
                com.Parameters.AddWithValue("@mablaghekol", txtjamebime.Text);
                com.Parameters.AddWithValue("@franshizekol", txtsahmebimar.Text);
                com.Parameters.AddWithValue("@mablaghepardakhti", txtkolepardakht.Text);
                com.Connection = con;
                con.Open();
                com.ExecuteNonQuery();
                con.Close();

                txtnoskhe.Text = code;
                string message = "نسخه ای با کد \" {0} \" با موفقیت در سیستم ثبت شد   ";
                message = string.Format(message, code);
                /////////////////////////
                showElanatNoOptionButton(message, "green");
                /////////////////////////
            }
            catch
            {
                /////////////////////////
                showElanatNoOptionButton("این نسخه قبلا در سیستم به ثبت رسیده است. لطفا دوباره تلاش کنید   ", "red");
                /////////////////////////
            }
        }

        public void insertnoskhe(int i)
        {
            SqlConnection con = new SqlConnection();
            con.ConnectionString = "server=(local);database=darokhane;trusted_connection=yes";
            SqlCommand com = new SqlCommand();
            com.Connection = con;
            com.CommandText =
                "insert into noskhe (codenoskhebimar,idbimar,iddaro,tedadedaro,gheymat,franshiz,gheymatepardakhti) values (@codenoskhebimar,@idbimar,@iddaro,@tedadedaro,@gheymat,@franshiz,@gheymatepardakhti)";
            com.Parameters.AddWithValue("@codenoskhebimar", txtnoskhe.Text.ToString().Trim());
            com.Parameters.AddWithValue("@idbimar", txteshterak.Text);
            com.Parameters.AddWithValue("@iddaro", dataGridView11.Rows[i].Cells[1].Value);
            com.Parameters.AddWithValue("@tedadedaro", dataGridView11.Rows[i].Cells[3].Value);
            com.Parameters.AddWithValue("@gheymat", dataGridView11.Rows[i].Cells[4].Value);
            com.Parameters.AddWithValue("@franshiz", dataGridView11.Rows[i].Cells[5].Value);
            com.Parameters.AddWithValue("@gheymatepardakhti", dataGridView11.Rows[i].Cells[6].Value);
            con.Open();
            com.ExecuteNonQuery();
            con.Close();
        }

        private void cmbsearch_SelectedIndexChanged(object sender, EventArgs e)
        {

            if (cmbsearch.SelectedIndex == 0)
            {
                txtsearchdaro.Items.Clear();
                txtdatesabt.Text = date;
                SqlConnection con = new SqlConnection();
                con.ConnectionString = "server=(local);database=darokhane;trusted_connection=yes";
                SqlCommand com = new SqlCommand();
                com.Connection = con;
                com.CommandText = "select * from home where State='True' order by lname";

                SqlDataAdapter da = new SqlDataAdapter();
                da.SelectCommand = com;

                DataSet ds = new DataSet();
                da.Fill(ds);

                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    txtsearchdaro.Items.Add(ds.Tables[0].Rows[i][1].ToString());
                }
            }
            if (cmbsearch.SelectedIndex == 1)
            {
                txtsearchdaro.Items.Clear();
                txtdatesabt.Text = date;
                SqlConnection con = new SqlConnection();
                con.ConnectionString = "server=(local);database=darokhane;trusted_connection=yes";
                SqlCommand com = new SqlCommand();
                com.Connection = con;
                com.CommandText = "select * from home where State='True' order by fname";

                SqlDataAdapter da = new SqlDataAdapter();
                da.SelectCommand = com;

                DataSet ds = new DataSet();
                da.Fill(ds);

                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    txtsearchdaro.Items.Add(ds.Tables[0].Rows[i][2].ToString());
                }
            }
            if (cmbsearch.SelectedIndex == 2)
            {
                txtsearchdaro.Items.Clear();
                txtdatesabt.Text = date;
                SqlConnection con = new SqlConnection();
                con.ConnectionString = "server=(local);database=darokhane;trusted_connection=yes";
                SqlCommand com = new SqlCommand();
                com.Connection = con;
                com.CommandText = "select * from home where State='True' order by id";

                SqlDataAdapter da = new SqlDataAdapter();
                da.SelectCommand = com;

                DataSet ds = new DataSet();
                da.Fill(ds);

                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    txtsearchdaro.Items.Add(ds.Tables[0].Rows[i][0].ToString());
                }
            }
        }

        private void txtsearchdaro_TextChanged(object sender, EventArgs e)
        {
            txtfranshiz.Text = "";
            if (btninsert.Enabled == false) btninsert.Enabled = true;
            try
            {
                if (txtsearchdaro.Text != "")
                {
                    SqlCommand com = new SqlCommand();
                    SqlDataAdapter da = new SqlDataAdapter();
                    DataSet dt = new DataSet();
                    SqlConnection con = new SqlConnection();
                    con.ConnectionString = "server=(local);database=darokhane;trusted_connection=yes";
                    com.Connection = con;

                    if (cmbsearch.SelectedIndex == 0)
                    {
                        com.CommandText = "select * from home where lname='" + txtsearchdaro.Text + "'";
                        da.SelectCommand = com;
                        da.Fill(dt);
                        lblcheckdaro.Text = "1";
                        txtiddarosearch.Text = dt.Tables[0].Rows[0][0].ToString();
                        txtmojodi.Text = dt.Tables[0].Rows[0][9].ToString();
                        txtdarogheymat.Text = dt.Tables[0].Rows[0][5].ToString();
                        txtdaroengheza.Text = dt.Tables[0].Rows[0][4].ToString();
                        fname = dt.Tables[0].Rows[0][2].ToString();
                        txttarkibatdaro.Text = dt.Tables[0].Rows[0][8].ToString();
                        if (dt.Tables[0].Rows[0][10].ToString() == string.Empty)
                            txtdarocompony.Text = " ";
                        else
                            txtdarocompony.Text = dt.Tables[0].Rows[0][10].ToString();
                        codedaro1 = dt.Tables[0].Rows[0][0].ToString();
                        txtdaroaddress.Text = "این دارو در انبار شماره  " + dt.Tables[0].Rows[0][6].ToString() +
                                              " و در قفسه ی شماره " + dt.Tables[0].Rows[0][9].ToString() + " قرار دارد";
                        try
                        {
                            SqlCommand com1 = new SqlCommand();
                            SqlDataAdapter da1 = new SqlDataAdapter();
                            DataSet dt1 = new DataSet();
                            SqlConnection con1 = new SqlConnection();
                            con1.ConnectionString = "server=(local);database=darokhane;trusted_connection=yes";
                            com1.Connection = con1;
                            com1.CommandText = "select * from franshiz where idbimeh=" + txtbimeh.Text + " and iddaro=" +
                                               codedaro1;
                            da1.SelectCommand = com1;
                            da1.Fill(dt1);
                            if (dt1.Tables[0].Rows.Count == 0)
                                txtfranshiz.Text = "0";
                            else
                            {
                                float darsad = float.Parse(txtdarogheymat.Text)/100;
                                txtfranshiz.Text = (int.Parse(dt1.Tables[0].Rows[0][2].ToString())*darsad).ToString();
                            }
                            txttedad.Focus();
                            this.AcceptButton = btninsert;
                        }
                        catch
                        {
                            return;
                        }
                    }
                    if (cmbsearch.SelectedIndex == 1)
                    {
                        com.CommandText = "select * from home where fname=N'" + txtsearchdaro.Text + "'";
                        da.SelectCommand = com;
                        da.Fill(dt);
                        lblcheckdaro.Text = "1";
                        txtiddarosearch.Text = dt.Tables[0].Rows[0][0].ToString();
                        txtmojodi.Text = dt.Tables[0].Rows[0][9].ToString();
                        txtdarogheymat.Text = dt.Tables[0].Rows[0][5].ToString();
                        txtdaroengheza.Text = dt.Tables[0].Rows[0][4].ToString();
                        fname = dt.Tables[0].Rows[0][2].ToString();
                        txttarkibatdaro.Text = dt.Tables[0].Rows[0][8].ToString();
                        if (dt.Tables[0].Rows[0][10].ToString() == string.Empty)
                            txtdarocompony.Text = " ";
                        else
                            txtdarocompony.Text = dt.Tables[0].Rows[0][10].ToString();
                        codedaro1 = dt.Tables[0].Rows[0][0].ToString();
                        txtdaroaddress.Text = "این دارو در انبار شماره  " + dt.Tables[0].Rows[0][6].ToString() +
                                              " و در قفسه ی شماره " + dt.Tables[0].Rows[0][9].ToString() + " قرار دارد";
                        try
                        {
                            SqlCommand com1 = new SqlCommand();
                            SqlDataAdapter da1 = new SqlDataAdapter();
                            DataSet dt1 = new DataSet();
                            SqlConnection con1 = new SqlConnection();
                            con1.ConnectionString = "server=(local);database=darokhane;trusted_connection=yes";
                            com1.Connection = con1;
                            com1.CommandText = "select * from franshiz where idbimeh=" + txtbimeh.Text + " and iddaro=" +
                                               codedaro1;
                            da1.SelectCommand = com1;
                            da1.Fill(dt1);
                            if (dt1.Tables[0].Rows.Count == 0)
                                txtfranshiz.Text = "0";
                            else
                            {
                                float darsad = float.Parse(txtdarogheymat.Text)/100;
                                txtfranshiz.Text = (int.Parse(dt1.Tables[0].Rows[0][2].ToString())*darsad).ToString();
                            }
                            txttedad.Focus();
                            this.AcceptButton = btninsert;
                        }
                        catch
                        {
                            return;
                        }
                    }
                    if (cmbsearch.SelectedIndex == 2)
                    {
                        SelectDaroAdd(txtsearchdaro.Text);
                    }
                }
            }
            catch
            {
                /////////////////////////
                showElanatNoOptionButton("متاسفانه در واکشی به درخواست شما موردی یافت نشد. لطفا دوباره تلاش نمایید",
                    "yellow");
                /////////////////////////
                txtdaroaddress.Text = "دارویی با مشخصات زیر در داروخانه وجود ندارد";
                lblcheckdaro.Text = "0";
            }
        }

        private void SelectDaroAdd(string Code)
        {
            SqlConnection con = new SqlConnection("server=(local);database=darokhane;trusted_connection=yes");
            SqlCommand com = new SqlCommand();
            SqlDataAdapter da = new SqlDataAdapter();
            DataSet dt = new DataSet();
            com.Connection = con;
            com.CommandText = "select * from home where id='" + Code + "'";
            da.SelectCommand = com;
            da.Fill(dt);
            lblcheckdaro.Text = "1";
            txtiddarosearch.Text = dt.Tables[0].Rows[0][0].ToString();
            txtmojodi.Text = dt.Tables[0].Rows[0][9].ToString();
            txtdarogheymat.Text = dt.Tables[0].Rows[0][5].ToString();
            txtdaroengheza.Text = dt.Tables[0].Rows[0][4].ToString();
            fname = dt.Tables[0].Rows[0][2].ToString();
            txttarkibatdaro.Text = dt.Tables[0].Rows[0][8].ToString();
            if (dt.Tables[0].Rows[0][10].ToString() == string.Empty)
                txtdarocompony.Text = " ";
            else
                txtdarocompony.Text = dt.Tables[0].Rows[0][10].ToString();
            codedaro1 = dt.Tables[0].Rows[0][0].ToString();

            txtdaroaddress.Text = "این دارو در انبار شماره  " + dt.Tables[0].Rows[0][6].ToString() +
                                  " و در قفسه ی شماره " + dt.Tables[0].Rows[0][9].ToString() + " قرار دارد";
            try
            {
                SqlCommand com1 = new SqlCommand();
                SqlDataAdapter da1 = new SqlDataAdapter();
                DataSet dt1 = new DataSet();
                SqlConnection con1 = new SqlConnection();
                con1.ConnectionString = "server=(local);database=darokhane;trusted_connection=yes";
                com1.Connection = con1;
                com1.CommandText = "select * from franshiz where idbimeh=" + txtbimeh.Text + " and iddaro=" +
                                   codedaro1;
                da1.SelectCommand = com1;
                da1.Fill(dt1);
                if (dt1.Tables[0].Rows.Count == 0)
                    txtfranshiz.Text = "0";
                else
                {
                    float darsad = float.Parse(txtdarogheymat.Text)/100;
                    txtfranshiz.Text = (int.Parse(dt1.Tables[0].Rows[0][2].ToString())*darsad).ToString();
                }
                txttedad.Focus();
                this.AcceptButton = btninsert;
            }
            catch
            {
                return;
            }
        }

        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            Application.Exit();
        }

        private void SearchByNameBimar(int codemeli)
        {
            SqlConnection con = new SqlConnection();
            con.ConnectionString = "server=(local);database=darokhane;trusted_connection=yes";

            SqlCommand com = new SqlCommand();
            com.Connection = con;
            com.CommandText =
                "select distinct codenoskhe as [کد نسخه],idbimar as [ش.ش بیمار],datefull as [تاریخ ثبت],mablaghekol as [مبلغ کل],franshizekol as [فرانشیز کل],mablaghepardakhti as [مبلغ پرداختی] from listecodenoskhe where idbimar=" +
                codemeli;
            SqlDataAdapter da = new SqlDataAdapter();
            da.SelectCommand = com;

            DataTable dt = new DataTable();
            da.Fill(dt);
            dataGridViewX3.DataSource = dt;
            dataGridViewX3.Columns[5].Width = 120;
        }


        private void SearchAsCodeNoskhe(string serial)
        {
            SqlConnection con = new SqlConnection();
            con.ConnectionString = "server=(local);database=darokhane;trusted_connection=yes";

            SqlCommand com = new SqlCommand();
            com.Connection = con;
            com.CommandText =
                "Select noskhe.iddaro as [کد دارو],noskhe.tedadedaro as [تعداد دارو],noskhe.gheymat as [قیمت کل],noskhe.franshiz as [فرانشیز],noskhe.gheymatepardakhti as [مبلغ پرداختی] from noskhe,listecodenoskhe where listecodenoskhe.codenoskhe=noskhe.codenoskhebimar and listecodenoskhe.codenoskhe='" +
                serial + "'";

            SqlDataAdapter da = new SqlDataAdapter();
            da.SelectCommand = com;

            DataTable dt = new DataTable();
            da.Fill(dt);
            dtglistenoskhe.DataSource = dt;
            dtglistenoskhe.Columns[0].HeaderText = "آی دی دارو";
            dtglistenoskhe.Columns[1].HeaderText = "تعداد دارو";
            dtglistenoskhe.Columns[2].HeaderText = "قیمت دارو";
            dtglistenoskhe.Columns[3].HeaderText = "فرانشیز";
            dtglistenoskhe.Columns[4].HeaderText = "قیمت پرداخت شده";
            dtglistenoskhe.Columns[4].Width = 130;
        }

        private void SearchByDate(string query)
        {
            EmptyGrideSearch();

            SqlConnection con = new SqlConnection();
            con.ConnectionString = "server=(local);database=darokhane;trusted_connection=yes";

            SqlCommand com = new SqlCommand();
            com.Connection = con;
            com.CommandText = query;

            SqlDataAdapter da = new SqlDataAdapter();
            da.SelectCommand = com;

            DataTable dt = new DataTable();
            da.Fill(dt);
            dataGridViewX3.DataSource = dt;
            if (dt.Rows.Count == 0)
            {
                /////////////////////////
                showElanatNoOptionButton(
                    "   متاسفانه اطلاعات درخواستی شما یافت نشد. لطفا دوباره تلاش کنید یا از روش های دیگر استفاده کنید",
                    "red");
                /////////////////////////
            }
            dataGridViewX3.Columns[0].HeaderText = "کد نسخه";
            dataGridViewX3.Columns[1].HeaderText = "کد اشتراک";
            dataGridViewX3.Columns[2].HeaderText = "تاریخ ثبت";
            dataGridViewX3.Columns[3].HeaderText = "مبلغ کل";
            dataGridViewX3.Columns[4].HeaderText = "فرانشیز کل";
            dataGridViewX3.Columns[5].HeaderText = "مبلغ پرداختی";
            dataGridViewX3.Columns[5].Width = 120;
        }


        private void btnsearchbynamebimar_Click(object sender, EventArgs e)
        {
            SqlConnection con = new SqlConnection();
            con.ConnectionString = "server=(local);database=darokhane;trusted_connection=yes";
            SqlCommand com = new SqlCommand();
            com.Connection = con;
            com.CommandText = "select codemeli,bname,bfamily,nbimeh from eshterak where bname like N'%" +
                              txtsearchname65.Text + "%'";
            if (txtsearchfamily.Text != string.Empty)
                com.CommandText += " and bfamily like N'%" + txtsearchfamily.Text + "%'";
            SqlDataAdapter da = new SqlDataAdapter();
            da.SelectCommand = com;
            DataTable dt = new DataTable();
            da.Fill(dt);
            dataGridViewX2.DataSource = dt;
            dataGridViewX2.Columns[0].HeaderText = "کد ملی";
            dataGridViewX2.Columns[1].HeaderText = "نام";
            dataGridViewX2.Columns[1].Width = 80;
            dataGridViewX2.Columns[2].HeaderText = "فامیلی";
            dataGridViewX2.Columns[2].Width = 80;
            dataGridViewX2.Columns[3].HeaderText = "کد بیمه";
            dataGridViewX2.Columns[3].Width = 50;
            playsoundclick("\\sound\\click.wav");
        }

        private void button2_Click_1(object sender, EventArgs e)
        {

        }

        private void buttonItem10_Click(object sender, EventArgs e)
        {
            MessageBox.Show(
                "برای امنیت بیشتر این قسمت ایجاد شده است\nبرای اینکه کاربری بعد و یا قبل از ساعت اداری\nبه سیستم برای اقدامات خلاف قوانین دسترسی نداشته\nباشد.این قسمت فقط برای کاربرانی که سطح\nمدیریتی آنها پنج ستاره باشد فعال است",
                "", MessageBoxButtons.OK, MessageBoxIcon.Question);
        }

        private void dataGridViewX2_SelectionChanged(object sender, EventArgs e)
        {
            DataTable dt = new DataTable();
            dt.Clear();
            dataGridViewX3.DataSource = dt;

            SearchByNameBimar(Int32.Parse(dataGridViewX2.CurrentRow.Cells[0].Value.ToString()));
        }


        private void txtsearchcode_TextChanged(object sender, EventArgs e)
        {
            if (txtsearchcode.Text != string.Empty)
                searchdaro("select * from home where id=" + txtsearchcode.Text);

        }

        public void searchdaro(string query)
        {
            SqlConnection con = new SqlConnection("server=(local);database=darokhane;trusted_connection=yes");
            SqlCommand com = new SqlCommand(query, con);
            SqlDataAdapter da = new SqlDataAdapter(com);
            DataTable dt = new DataTable();
            da.Fill(dt);
            dgsearchdaro.DataSource = dt;
        }

        private void txtsearchlatin_TextChanged(object sender, EventArgs e)
        {
            if (txtsearchlatin.Text != string.Empty)
                searchdaro("select * from home where lname like '%" + txtsearchlatin.Text + "%'");
        }

        private void txtsearchfarsi_TextChanged(object sender, EventArgs e)
        {
            if (txtsearchfarsi.Text != string.Empty)
                searchdaro("select * from home where fname like N'%" + txtsearchfarsi.Text + "%'");
        }

        private void txtsearchcompany_TextChanged(object sender, EventArgs e)
        {
            if (txtsearchcompany.Text != string.Empty)
                searchdaro("select * from home where compony like N'%" + txtsearchcompany.Text + "%'");
        }

        private void txtfranshizidbimeh_TextChanged_1(object sender, EventArgs e)
        {
            try
            {
                if (txtfranshizidbimeh.Text != "")
                {
                    SqlDataAdapter da = new SqlDataAdapter();
                    DataTable dt = new DataTable();
                    SqlConnection con = new SqlConnection();
                    con.ConnectionString = "server=(local);database=darokhane;trusted_connection=yes";

                    SqlCommand com = new SqlCommand();
                    com.Connection = con;

                    com.CommandText = "select * from bimeh where id='" + txtfranshizidbimeh.Text + "'";
                    da.SelectCommand = com;
                    da.Fill(dt);
                    if (dt.Rows.Count == 1)
                    {
                        lblfranshizidbimeh.Text = "بیمه ی " + dt.Rows[0][1].ToString();
                    }
                    else
                    {
                        lblfranshizidbimeh.Text = "";
                    }
                }
                else
                {
                    lblfranshizidbimeh.Text = "";
                }

            }
            catch
            {
                /////////////////////////
                showElanatNoOptionButton(
                    "   مشخصات بیمه گر مورد نظر شما در سیستم موجود نمی باشد. برای ثبت بیمه به قسمت ثبت اشتراک مراجعه کنید",
                    "red");
                /////////////////////////
                lblfranshizidbimeh.Text = "موجود نمی باشد";
            }
        }

        private void btninsertfranshiz_Click(object sender, EventArgs e)
        {
            try
            {
                if (lblfranshizdaro.Text != "" && lblfranshizidbimeh.Text != "")
                {
                    SqlConnection con = new SqlConnection("server=.;database=darokhane;trusted_connection=yes");
                    SqlCommand com = new SqlCommand();
                    com.CommandText = "insert into franshiz (idbimeh,iddaro,franshiz) values (@idbimeh,@iddaro,@franshiz)";
                    com.Parameters.AddWithValue("@idbimeh", txtfranshizidbimeh.Text);
                    com.Parameters.AddWithValue("@iddaro", txtfranshiziddaro.Text);
                    com.Parameters.AddWithValue("@franshiz", txtfranshizdarsad.Text);
                    com.Connection = con;
                    con.Open();
                    com.ExecuteNonQuery();
                    con.Close();
                    ////////////////
                    string message = "{0} در صد تخفبف برای دارویی با کد {1} در {2} به ثبت رسید";
                    message = string.Format(message, txtfranshizdarsad.Text, txtfranshiziddaro.Text, lblfranshizidbimeh.Text);
                    showElanatNoOptionButton(message, "green");
                    ///////////////
                    lblfranshizmessage.Text = "با موفقیت ثبت شد";
                }
                else
                {
                    showElanatNoOptionButton("   لطفا کد بیمه گر و آی دی دارو را وارد کنید", "red");
                }
                
            }
            catch
            {
                /////////////////////////
                showElanatNoOptionButton(
                    "   این دارو با کد بیمه گر قبلا در سیستم ثبت شده است. برای ویرایش درصد فرانشیز روی دکمه ویرایش کلیک کنید",
                    "red");
                /////////////////////////
                lblfranshizmessage.Text = "این دارو با کد بیمه گر قبلا در سیستم ثبت شده است";
            }
        }

        private void ribbonTabItem3_Click(object sender, EventArgs e)
        {
            PersianCalendar pc = new PersianCalendar();
            DateTime dtnext;
            dtnext = DateTime.Now;
            dtnext = dtnext.AddDays(30);
            engheza = pc.GetYear(dtnext).ToString("D2") + "/" + pc.GetMonth(dtnext).ToString("D2") + "/" +
                      pc.GetDayOfMonth(dtnext).ToString("D2");
            showlisetdaro();
            playsoundclick("\\sound\\click.wav");
            ListeEngheza();
            btnLoadAllDaro_Click(sender, e);
        }

        public void playsoundmouse(string path)
        {
            if (swsound.Value == true && sound == true)
            {
                SoundPlayer player = new SoundPlayer(Application.StartupPath + path);
                player.Play();
            }
            else return;

            sound = false;
        }

        public void playsoundclick(string path)
        {
            if (swsound.Value == true)
            {
                SoundPlayer player = new SoundPlayer(Application.StartupPath + path);
                player.Play();
            }
            else return;

            sound = false;
        }

        private void ribpedit_Click(object sender, EventArgs e)
        {
            playsoundclick("\\sound\\click.wav");
        }

        private void ribbonTabItem4_Click(object sender, EventArgs e)
        {
            grbAccountShow();
            buttonX10_Click(sender, e);
            playsoundclick("\\sound\\click.wav");
            ChangColorDataGridDelete(dgvAccount);
        }

        private void ShowAccountList(string query)
        {
            SqlConnection con = new SqlConnection("server=.;database=darokhane;trusted_connection=yes");
            SqlDataAdapter da = new SqlDataAdapter(query, con);
            DataTable dt = new DataTable();
            da.Fill(dt);
            dgvAccount.DataSource = dt;
            dgvAccount.Columns[10].Visible = false;
        }
        private void ribpedit_MouseMove(object sender, MouseEventArgs e)
        {
            playsoundmouse("\\sound\\mouse.wav");
        }

        private void ribpedit_MouseLeave(object sender, EventArgs e)
        {
            sound = true;
        }

        private void ribbonTabItem2_MouseMove(object sender, MouseEventArgs e)
        {
            playsoundmouse("\\sound\\mouse.wav");
        }

        private void ribbonTabItem3_MouseMove(object sender, MouseEventArgs e)
        {
            playsoundmouse("\\sound\\mouse.wav");
        }

        private void ribbonTabItem4_MouseMove(object sender, MouseEventArgs e)
        {
            playsoundmouse("\\sound\\mouse.wav");
        }

        private void buttonItem6_MouseMove(object sender, MouseEventArgs e)
        {
            playsoundmouse("\\sound\\mouse.wav");
        }

        private void buttonItem3_MouseMove(object sender, MouseEventArgs e)
        {
            playsoundmouse("\\sound\\mouse.wav");
        }

        private void buttonItem4_MouseMove(object sender, MouseEventArgs e)
        {
            playsoundmouse("\\sound\\mouse.wav");
        }

        private void ribbonTabItem2_MouseLeave(object sender, EventArgs e)
        {
            sound = true;
        }

        private void ribbonTabItem3_MouseLeave(object sender, EventArgs e)
        {
            sound = true;
        }

        private void ribbonTabItem4_MouseLeave(object sender, EventArgs e)
        {
            sound = true;
        }

        private void buttonItem6_MouseLeave(object sender, EventArgs e)
        {
            sound = true;
        }

        private void buttonItem3_MouseLeave(object sender, EventArgs e)
        {
            sound = true;
        }

        private void buttonItem4_MouseLeave(object sender, EventArgs e)
        {
            sound = true;
        }

        private void btnedituser_Click(object sender, EventArgs e)
        {
            SqlCommand com = new SqlCommand();
            com.CommandText =
                "update accont set upass=@upass where uname=@uname";
            com.Parameters.AddWithValue("@upass", txteditpassword.Text);
            com.Parameters.AddWithValue("@uname", txtedituser.Text);
            UpdateAndInsert(com);
            playsoundclick("\\sound\\login.wav");
            ribbonTabItem4_Click(sender, e);
        }

        private void buttonX5_Click(object sender, EventArgs e)
        {
            try
            {
                SqlCommand com = new SqlCommand();
                com.CommandText =
                    "update home set lname=@lname,fname=@fname,tolid=@tolid,engheza=@engheza,gheymat=@gheymat,anbar=@anbar,ghafase=@ghafase,tarkibat=@tarkibat,compony=@compony,tedad=@tedad,State=@State where id=@id";
                com.Parameters.AddWithValue("@lname", txteditlname.Text);
                com.Parameters.AddWithValue("@fname", txteditfname.Text);
                com.Parameters.AddWithValue("@tolid", txtedittolid.Text);
                com.Parameters.AddWithValue("@engheza", txteditengheza.Text);
                com.Parameters.AddWithValue("@gheymat", txteditgheymat.Text);
                com.Parameters.AddWithValue("@anbar", txteditanbar.Text);
                com.Parameters.AddWithValue("@ghafase", txteditghafase.Text);
                com.Parameters.AddWithValue("@tarkibat", txtedittarkibat.Text);
                com.Parameters.AddWithValue("@compony", txteditcompony.Text);
                com.Parameters.AddWithValue("@tedad", txtedittedad.Text);
                com.Parameters.AddWithValue("@State", true);
                com.Parameters.AddWithValue("@id", txteditid.Text);
                UpdateAndInsert(com);

                playsoundclick("\\sound\\click.wav");
                string message = "   داروی \" " + txteditfname.Text + " \" با موفقیت ویرایش شد";
                showElanatNoOptionButton(message, "green");
                btnLoadAllDaro_Click(sender, e);
            }
            catch
            {
                /////////////////////////
                showElanatNoOptionButton("   در استصال با بانک خطایی رخ داده است. لطفا دوباره تلاش کنید", "red");
                /////////////////////////
            }
        }

        private void txtfranshiziddaro_TextChanged(object sender, EventArgs e)
        {
            try
            {
                if (txtfranshiziddaro.Text != "")
                {
                    SqlDataAdapter da = new SqlDataAdapter();
                    DataTable dt = new DataTable();
                    SqlConnection con = new SqlConnection();
                    con.ConnectionString = "server=(local);database=darokhane;trusted_connection=yes";

                    SqlCommand com = new SqlCommand();
                    com.Connection = con;

                    com.CommandText = "select * from home where id='" + txtfranshiziddaro.Text + "'";
                    da.SelectCommand = com;
                    da.Fill(dt);
                    if(dt.Rows.Count==1)
                        lblfranshizdaro.Text = "نام دارو: " + dt.Rows[0][1].ToString();
                    else
                    {
                        lblfranshizdaro.Text = "";
                    }
                }
                else
                {
                    lblfranshizdaro.Text = "";
                }
            }
            catch
            {
                lblfranshizmessage.Text = "دارویی با کد وارد شده در داروخانه وجود ندارد";
            }
        }

        public void countmessage()
        {
            SqlConnection con = new SqlConnection("server=(local);database=darokhane;trusted_connection=yes");
            SqlCommand com = new SqlCommand(
                "select * from message where uname='" + login.uname + "' and readmessage=0", con);
            SqlDataAdapter da = new SqlDataAdapter();
            da.SelectCommand = com;
            DataTable dt = new DataTable();
            da.Fill(dt);
            if (dt.Rows.Count > 0)
            {
                string message =
                    "   کاربر محترم، شما {0} پیام خوانده نشده دارید. برای دیدن پیام ها بر روی باتن \" دیدن پیام ها \" کلیک کنید";
                message = string.Format(message, dt.Rows.Count.ToString());
                elanmessage.Text = message;
                showElanatOptionButton(message, "default", " دیدن پیام ها ", "message");
            }
            con.Close();
        }

        public void ListeEngheza()
        {
            dtListeEngheza.Clear();
            SqlConnection con = new SqlConnection("server=(local);database=darokhane;trusted_connection=yes");
            SqlCommand com =
                new SqlCommand(
                    "SELECT * FROM home Where engheza Between '" + txtdatenow.Text + "' And '" + engheza + "'", con);
            SqlDataAdapter da = new SqlDataAdapter();
            da.SelectCommand = com;
            da.Fill(dtListeEngheza);
            if (dtListeEngheza.Rows.Count > 0)
            {
                ////////////////////
                string message =
                    "   هشدار: تعداد {0} قلم دارو به تاریخ انقضایشان نزدیک شده اند. برای دیدن لیست داروها بر روی باتن \" دیدن لیست \" کلیک کنید.";
                message = string.Format(message, dtListeEngheza.Rows.Count);
                showElanatOptionButton(message, "red", " دیدن لیست ", "engheza");
                ///////////////////
            }
        }

        public void optionelanat()
        {
            if (lblelanat.Text == "message")
            {
                message frm = new message();
                frm.ShowDialog();
            }
            if (lblelanat.Text == "eshterak")
            {
                addEshterak.Select();
            }
            if (lblelanat.Text == "engheza")
            {
                dgsearchdaro.DataSource = dtListeEngheza;
            }
        }

        private void buttonItem16_Click(object sender, EventArgs e)
        {
            searchdaro("select * from ListeBuy");
            playsoundclick("\\sound\\click.wav");
        }

        private void txtcode_KeyPress(object sender, KeyPressEventArgs e)
        {
            TextboxesOnlyNumber_KeyPress(sender, e);
        }

        private void txtcodepd_KeyPress(object sender, KeyPressEventArgs e)
        {
            TextboxesOnlyNumber_KeyPress(sender, e);
        }

        private void txtcodemeli_KeyPress(object sender, KeyPressEventArgs e)
        {
            TextboxesOnlyNumber_KeyPress(sender, e);
        }

        private void txtbimehcode_KeyPress(object sender, KeyPressEventArgs e)
        {
            TextboxesOnlyNumber_KeyPress(sender, e);
        }

        private void txtcodedaro_KeyPress(object sender, KeyPressEventArgs e)
        {
            TextboxesOnlyNumber_KeyPress(sender, e);
        }

        private void txttedadeavalie_KeyPress(object sender, KeyPressEventArgs e)
        {
            TextboxesOnlyNumber_KeyPress(sender, e);
        }

        private void txtanbar_KeyPress(object sender, KeyPressEventArgs e)
        {
            TextboxesOnlyNumber_KeyPress(sender, e);
        }

        private void txtghafase_KeyPress(object sender, KeyPressEventArgs e)
        {
            TextboxesOnlyNumber_KeyPress(sender, e);
        }

        private void txtfranshizidbimeh_KeyPress(object sender, KeyPressEventArgs e)
        {
            TextboxesOnlyNumber_KeyPress(sender, e);
        }

        private void txtfranshiziddaro_KeyPress(object sender, KeyPressEventArgs e)
        {
            TextboxesOnlyNumber_KeyPress(sender, e);
        }

        private void txtfranshizdarsad_KeyPress(object sender, KeyPressEventArgs e)
        {
            TextboxesOnlyNumber_KeyPress(sender, e);
        }

        private void txtsearchcode_KeyPress(object sender, KeyPressEventArgs e)
        {
            TextboxesOnlyNumber_KeyPress(sender, e);
        }

        private void txtsearchanbar_KeyPress(object sender, KeyPressEventArgs e)
        {
            TextboxesOnlyNumber_KeyPress(sender, e);
        }

        private void txteditgheymat_KeyPress(object sender, KeyPressEventArgs e)
        {
            TextboxesOnlyNumber_KeyPress(sender, e);
        }

        private void txteditanbar_KeyPress(object sender, KeyPressEventArgs e)
        {
            TextboxesOnlyNumber_KeyPress(sender, e);
        }

        private void txteditghafase_KeyPress(object sender, KeyPressEventArgs e)
        {
            TextboxesOnlyNumber_KeyPress(sender, e);
        }

        private void txtedittedad_KeyPress(object sender, KeyPressEventArgs e)
        {
            TextboxesOnlyNumber_KeyPress(sender, e);
        }

        private void txtserial_KeyPress(object sender, KeyPressEventArgs e)
        {
            TextboxesOnlyNumber_KeyPress(sender, e);
        }

        private void txtpcode_KeyPress(object sender, KeyPressEventArgs e)
        {
            TextboxesOnlyNumber_KeyPress(sender, e);
        }

        private void txttedad_KeyPress(object sender, KeyPressEventArgs e)
        {
            TextboxesOnlyNumber_KeyPress(sender, e);
        }

        private void txtspname_KeyPress(object sender, KeyPressEventArgs e)
        {
            TextboxesOnlyString_KeyPress(sender,e);
        }

        private void txteshterak_KeyPress(object sender, KeyPressEventArgs e)
        {
            TextboxesOnlyNumber_KeyPress(sender, e);
        }

        private void txttakhasos_KeyPress(object sender, KeyPressEventArgs e)
        {
            TextboxesOnlyString_KeyPress(sender,e);
        }

        private void txtnewpname_KeyPress(object sender, KeyPressEventArgs e)
        {
            TextboxesOnlyString_KeyPress(sender,e);
        }

        private void txtnewptakhasos_KeyPress(object sender, KeyPressEventArgs e)
        {
            TextboxesOnlyString_KeyPress(sender,e);
        }

        private void txtname_KeyPress(object sender, KeyPressEventArgs e)
        {
            TextboxesOnlyString_KeyPress(sender,e);
        }

        private void txtfamily_KeyPress(object sender, KeyPressEventArgs e)
        {
            TextboxesOnlyString_KeyPress(sender,e);
        }

        private void txtkname_KeyPress(object sender, KeyPressEventArgs e)
        {
            TextboxesOnlyString_KeyPress(sender,e);
        }

        private void txtsearchname_KeyPress(object sender, KeyPressEventArgs e)
        {
            TextboxesOnlyString_KeyPress(sender,e);
        }

        private void txtsearchfamily_KeyPress(object sender, KeyPressEventArgs e)
        {
            TextboxesOnlyString_KeyPress(sender,e);
        }

        private void txtcodenoskhe_KeyPress(object sender, KeyPressEventArgs e)
        {
            TextboxesOnlyNumber_KeyPress(sender, e);
        }

        private void maskdatenow_KeyPress(object sender, KeyPressEventArgs e)
        {
            TextboxesOnlyNumber_KeyPress(sender, e);
        }

        private void maskdateta_KeyPress(object sender, KeyPressEventArgs e)
        {
            TextboxesOnlyNumber_KeyPress(sender, e);
        }

        private void txtpidedit_KeyPress(object sender, KeyPressEventArgs e)
        {
            TextboxesOnlyNumber_KeyPress(sender, e);
        }

        private void btninsert_Click(object sender, EventArgs e)
        {
            bool checktolist = true;
            if (dataGridView11.RowCount > 0)
            {
                for (int i = 0; i < dataGridView11.RowCount; i++)
                {
                    if (dataGridView11.Rows[i].Cells[1].Value.ToString() == txtiddarosearch.Text)
                    {
                        showElanatNoOptionButton(
                            "   این دارو در لیست ثبت شده است. برای کم یا زیاد کردن تعداد آن در لیست آن را ویرایش کنید",
                            "yellow");
                        checktolist = false;
                    }
                }
            }

            if (lblcheckvalueseshterak.Text == "1" && txttedad.Text != "" && lblcheckdaro.Text == "1" &&
                checktolist == true)
            {
                if (txtbimeh.Text == "0")
                {
                    txtfranshiz.Text = "0";
                    string[] row =
                    {
                        i.ToString(), codedaro1, fname, txttedad.Text,
                        (float.Parse(txttedad.Text.ToString())*float.Parse(txtdarogheymat.Text.ToString())).ToString(),
                        (float.Parse(txttedad.Text.ToString())*float.Parse(txtfranshiz.Text.ToString())).ToString(),
                        ((float.Parse(txttedad.Text.ToString())*float.Parse(txtdarogheymat.Text.ToString())) -
                         (float.Parse(txttedad.Text.ToString())*float.Parse(txtfranshiz.Text.ToString()))).ToString(),
                        txtdaroengheza.Text, txtdarocompony.Text
                    };
                    dataGridView11.Rows.Add(row);
                    i++;

                }
                else
                {
                    string[] row =
                    {
                        i.ToString(), codedaro1, fname, txttedad.Text,
                        (float.Parse(txttedad.Text.ToString())*float.Parse(txtdarogheymat.Text.ToString())).ToString(),
                        (float.Parse(txttedad.Text.ToString())*float.Parse(txtfranshiz.Text.ToString())).ToString(),
                        ((float.Parse(txttedad.Text.ToString())*float.Parse(txtdarogheymat.Text.ToString())) -
                         (float.Parse(txttedad.Text.ToString())*float.Parse(txtfranshiz.Text.ToString()))).ToString(),
                        txtdaroengheza.Text, txtdarocompony.Text
                    };
                    dataGridView11.Rows.Add(row);
                    ++i;

                }
                txttedadekol.Text =
                    (float.Parse(txttedadekol.Text.ToString()) + int.Parse(txttedad.Text.ToString())).ToString();
                txtjamebime.Text =
                    (float.Parse(txtjamebime.Text.ToString()) +
                     (float.Parse(txttedad.Text.ToString())*float.Parse(txtdarogheymat.Text.ToString()))).ToString();
                txtsahmebimar.Text =
                    ((float.Parse(txtsahmebimar.Text.ToString())) +
                     ((float.Parse(txttedad.Text.ToString())*float.Parse(txtfranshiz.Text.ToString())))).ToString();
                txtkolepardakht.Text =
                    (float.Parse(txtkolepardakht.Text.ToString()) +
                     ((float.Parse(txttedad.Text.ToString())*float.Parse(txtdarogheymat.Text.ToString())) -
                      (float.Parse(txttedad.Text.ToString())*float.Parse(txtfranshiz.Text.ToString())))).ToString();

                txteshterak.ReadOnly = true;
                txtmojodi.Text = (int.Parse(txtmojodi.Text.ToString()) - int.Parse(txttedad.Text.ToString())).ToString();

                if (txtpname.Text == "پیدانشد" || txtpname.Text == string.Empty)
                    txtpezeshkemoalej.Text = "بدون تجویز پزشک صادر شد";
                else
                    txtpezeshkemoalej.Text = txtpname.Text;

                if (txtsabt.Text == "")
                    txtsabt.Text = txtdatenow.Text + "در ساعت" + DateTime.Now.ToLongTimeString();

                txtsabtkonande.Text = login.fullName;
            }
            else
            {

                if (lblcheckvalueseshterak.Text != "1")
                {
                    showElanatOptionButton(
                        "   برای ثبت نسخه ابتدا باید مشخصات کامل بیمار در سیستم ثبت شود. لطفا اقدام به ثبت اشتراک کنید",
                        "red", " ثبت اشتراک ", "eshterak");
                }
                else if (lblcheckdaro.Text == "0")
                {
                    /////////////////////////
                    showElanatNoOptionButton(
                        "   متاسفانه این دارو در داروخانه به اتمام رسیده است. درخواست خرید این دارو برای مدیریت ارسال شد",
                        "red");
                    /////////////////////////
                    string message =
                        "مدیریت محترم دارویی با نام \"{0}\" در داروخانه موجود نمی باشد. لطفا نسبت به خرید آن سریعا اقدام کنید";
                    message = string.Format(message, txtsearchdaro.Text);
                    sendmessageforadmin(message, "اتمام دارو");
                    txtsearchdaro.Select();
                    return;
                }
                else if (txttedad.Text == "")
                {
                    /////////////////////////
                    showElanatNoOptionButton("   لطفا تعداد داروی مورد نیازی که پزشک تجویز کرده است را وارد کنید", "red");
                    /////////////////////////
                }
            }
            checktolist = true;
        }

        private void btnsabtenoskhe_Click(object sender, EventArgs e)
        {
            if (dataGridView11.Rows.Count>0)
            {
                insertcodenoskhe();
            for (int i = 0; i < dataGridView11.Rows.Count; i++)
            {
                SqlConnection con = new SqlConnection("server=(local);database=darokhane;trusted_connection=yes");
                SqlCommand com =
                    new SqlCommand("select tedad from home where id=" + dataGridView11.Rows[i].Cells[1].Value, con);
                SqlDataAdapter da = new SqlDataAdapter();
                da.SelectCommand = com;
                DataSet ds = new DataSet();
                da.Fill(ds);
                int count = Int32.Parse(ds.Tables[0].Rows[0][0].ToString());
                count -= Int32.Parse(dataGridView11.Rows[i].Cells[3].Value.ToString());
                SqlCommand  comupdate= new SqlCommand(
                        "update home set tedad=" + count + " where id=" + dataGridView11.Rows[i].Cells[1].Value);
                UpdateAndInsert(comupdate);

                insertnoskhe(i);
            }
            btnmarjoeekol.Enabled = true;
            }
        }

        public void datefull()
        {
            persianDate prsDate = new persianDate(DateTime.Now);
            lbldatefull.Text = "امروز " + prsDate.CompletePrsDate() + prsDate.taghvim();
            lbldatehead.Tooltip = " " + prsDate.shamsi();
        }

        private void btnmarjoeekol_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < dataGridView11.RowCount; i++)
            {

                SqlConnection con = new SqlConnection("server=(local);database=darokhane;trusted_connection=yes");
                SqlCommand com =
                    new SqlCommand("select tedad from home where id=" + dataGridView11.Rows[i].Cells[1].Value, con);
                SqlDataAdapter da = new SqlDataAdapter();
                da.SelectCommand = com;
                DataSet ds = new DataSet();
                da.Fill(ds);
                int count = Int32.Parse(ds.Tables[0].Rows[0][0].ToString());
                count += Int32.Parse(dataGridView11.Rows[i].Cells[3].Value.ToString());
                SqlCommand comupdate =
                    new SqlCommand(
                        "update home set tedad=" + count + " where id=" + dataGridView11.Rows[i].Cells[1].Value);
                UpdateAndInsert(comupdate);
            }
            SqlConnection condelete = new SqlConnection("server=(local);database=darokhane;trusted_connection=yes");
            SqlCommand comdelete =
                new SqlCommand("delete from listecodenoskhe where codenoskhe='" + txtnoskhe.Text + "'; delete from noskhe where codenoskhebimar='" + txtnoskhe.Text + "'", condelete);
            condelete.Open();
            comdelete.ExecuteNonQuery();
            condelete.Close();
            /////////////////////////
            string message = "تعداد {0} قلم دارو مرجوع داده شد";
            message = string.Format(message, dataGridView11.RowCount);
            showElanatNoOptionButton(message, "yellow");
            /////////////////////////
            //btn_New_Noskhe_Click(sender,e);
        }

        private void elanmessage_CloseClick(object sender, EventArgs e)
        {
            elanmessage.Visible = false;
        }

        private void txtserial_TextChanged(object sender, EventArgs e)
        {
            if (txtserial.Text == string.Empty)
            {
                lblstarserial.Visible = true;
                txtpcode.Enabled = false;
                txtpcode.BackColor = grbEditDaro.BackColor;
                btn_addPezeshk.Enabled = false;
            }
            else
            {
                btn_addPezeshk.Enabled = false;
                lblstarserial.Visible = false;
                txtpcode.Enabled = true;
                txtpcode.BackColor = Color.Yellow;
            }
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            elanmessage.Visible = false;
            timer1.Enabled = false;
        }


        public void SetBackPage(string BackPageName)
        {
            lblback.Text = lblsetback.Text;
            lblsetback.Text = BackPageName;
        }

        private void btnsearchdarodarhaleetmam_Click(object sender, EventArgs e)
        {
            GroupSearchDaroShowAndHide(false);
            lbl_ListeDaroAndListeBuyState.Text = "Buy1";
            searchdaro("select iddaro as [کد دارو],home.fname as [نام فارسی],home.lname as [نام لاتین],[subject] as [عنوان پیام],[message] as [متن پیام],uname as [دریافت کننده],suname as [ارسال کننده],[date] as [تاریخ ارسال],[time] as [زمان ارسال] from ListeBuy inner join home on home.id=ListeBuy.iddaro where [subject] =N'در حال اتمام دارو'");
            playsoundclick("\\sound\\click.wav");
            dgsearchdaro.RowHeadersWidth = 45;
            grbEditDaro.Visible = false;
            grbListBuy.Visible = true;
        }

        private void btnsearchdaroend_Click(object sender, EventArgs e)
        {
            GroupSearchDaroShowAndHide(false);
            lbl_ListeDaroAndListeBuyState.Text = "Buy2";
            searchdaro("select iddaro as [کد دارو],home.fname as [نام فارسی],home.lname as [نام لاتین],[subject] as [عنوان پیام],[message] as [متن پیام],uname as [دریافت کننده],suname as [ارسال کننده],[date] as [تاریخ ارسال],[time] as [زمان ارسال] from ListeBuy inner join home on home.id=ListeBuy.iddaro where [subject] =N'اتمام دارو'");
            playsoundclick("\\sound\\click.wav");
            dgsearchdaro.RowHeadersWidth = 45;
            grbEditDaro.Visible = false;
            grbListBuy.Visible = true;
        }

        private void dgsearchdaro_SelectionChanged(object sender, EventArgs e)
        {
            try
            {
                if (lbl_ListeDaroAndListeBuyState.Text == "Daro")
                {
                    txteditid.Text = dgsearchdaro.CurrentRow.Cells[0].Value.ToString();
                    txteditlname.Text = dgsearchdaro.CurrentRow.Cells[1].Value.ToString();
                    txteditfname.Text = dgsearchdaro.CurrentRow.Cells[2].Value.ToString();
                    txtedittarkibat.Text = dgsearchdaro.CurrentRow.Cells[8].Value.ToString();
                    txtedittolid.Text = dgsearchdaro.CurrentRow.Cells[3].Value.ToString();
                    txteditengheza.Text = dgsearchdaro.CurrentRow.Cells[4].Value.ToString();
                    txteditgheymat.Text = dgsearchdaro.CurrentRow.Cells[5].Value.ToString();
                    txteditanbar.Text = dgsearchdaro.CurrentRow.Cells[6].Value.ToString();
                    txteditghafase.Text = dgsearchdaro.CurrentRow.Cells[7].Value.ToString();
                    txtedittedad.Text = dgsearchdaro.CurrentRow.Cells[10].Value.ToString();
                    txteditcompony.Text = dgsearchdaro.CurrentRow.Cells[9].Value.ToString();
                }
                else
                {
                    txt_ListBuy_IdDaro.Text = dgsearchdaro.CurrentRow.Cells[0].Value.ToString();
                    txt_ListBuy_Sender.Text = dgsearchdaro.CurrentRow.Cells[6].Value.ToString();
                    txt_ListBuy_Date.Text = dgsearchdaro.CurrentRow.Cells[7].Value.ToString();
                    txt_ListBuy_Subject.Text = dgsearchdaro.CurrentRow.Cells[3].Value.ToString();
                    txt_ListBuy_Message.Text = dgsearchdaro.CurrentRow.Cells[4].Value.ToString();
                    txt_ListBuy_To.Text = dgsearchdaro.CurrentRow.Cells[5].Value.ToString();
                }
                
            }
            catch
            {
            }
            ;
        }

        private void ribbonTabItem1_Click(object sender, EventArgs e)
        {
            showgrbsearch();
            playsoundclick("\\sound\\click.wav");
            SetBackPage("search");
        }

        private void txtsearchcodeeshterak_GotFocus(object sender, EventArgs e)
        {
            txtsearchcodenoskhe.Text = "";
        }

        private void txtsearchcodenoskhe_GotFocus(object sender, EventArgs e)
        {
            txtsearchcodeeshterak.Text = "";
        }

        private void btnsearchbyname_Click(object sender, EventArgs e)
        {
            if (dataGridViewX2.RowCount>0)
            dataGridViewX2.Rows.Clear();
            SqlConnection con = new SqlConnection();
            con.ConnectionString = "server=(local);database=darokhane;trusted_connection=yes";
            SqlCommand com = new SqlCommand();
            com.Connection = con;
            com.CommandText = "select codemeli,bname,bfamily,nbimeh from eshterak where bname like N'%" +
                              txtsearchname65.Text + "%'";
            if (txtsearchfamily.Text != string.Empty)
                com.CommandText += " and bfamily like N'%" + txtsearchfamily.Text + "%'";
            SqlDataAdapter da = new SqlDataAdapter();
            da.SelectCommand = com;
            DataTable dt = new DataTable();
            da.Fill(dt);
            dataGridViewX2.DataSource = dt;
            dataGridViewX2.Columns[0].HeaderText = "کد ملی";
            dataGridViewX2.Columns[1].HeaderText = "نام";
            dataGridViewX2.Columns[1].Width = 80;
            dataGridViewX2.Columns[2].HeaderText = "فامیلی";
            dataGridViewX2.Columns[2].Width = 80;
            dataGridViewX2.Columns[3].HeaderText = "کد بیمه";
            dataGridViewX2.Columns[3].Width = 50;
            playsoundclick("\\sound\\click.wav");
        }

        private void btnsearchbycode_Click(object sender, EventArgs e)
        {
            if (txtsearchcodenoskhe.Text != string.Empty)
            {
                string serial = txtsearchcodenoskhe.Text;
                SearchAsCodeNoskhe(serial);
            }
            if (txtsearchcodeeshterak.Text != string.Empty)
            {
                SearchByNameBimar(int.Parse(txtsearchcodeeshterak.Text));
            }
            playsoundclick("\\sound\\click.wav");
        }

        private void btnsearchasdatetadate_Click(object sender, EventArgs e)
        {
            bool date1, date2 = false;
            date1 = DateTrust(maskdatenow.Text);
            date2 = DateTrust(maskdateta.Text);
            if (date1 == false)
            {
                maskdatenow.ForeColor = Color.Red;
                showElanatNoOptionButton(
                    "فرمت تاریخ درج شده توسط شما اشتباه است. مانند مثال روبه رو وارد کنید:  \"  1392/04/28  \"", "red");
            }
            if (date2 == false)
            {
                maskdateta.ForeColor = Color.Red;
                showElanatNoOptionButton(
                    "فرمت تاریخ درج شده توسط شما اشتباه است. مانند مثال روبه رو وارد کنید:  \"  1392/04/28  \"", "red");
            }
            if (date1 == true && date2 == true)
            {
                if (dcheck(maskdatenow.Text) == 1)
                {

                    showElanatNoOptionButton(
                        "   تعداد ماه های سال نباید از 0 کمتر و از 12 بیشتر باشد. لطفا داده های درست را وارد کنید",
                        "red");
                    maskdatenow.ForeColor = Color.Red;
                    maskdatenow.SelectionStart = 5;
                    maskdatenow.SelectionLength = 2;
                    maskdatenow.Focus();
                }
                if (dcheck(maskdatenow.Text) == 2)
                {
                    showElanatNoOptionButton(
                        "   تعداد روزهای ماه نباید از 0 کمتر و از 31 بیشتر باشد. لطفا داده های درست را وارد کنید", "red");
                    maskdatenow.ForeColor = Color.Red;
                    maskdatenow.SelectionStart = 7;
                    maskdatenow.SelectionLength = 2;
                    maskdatenow.Focus();
                }
                if (dcheck(maskdateta.Text) == 1)
                {
                    showElanatNoOptionButton(
                        "   تعداد ماه های سال نباید از 0 کمتر و از 12 بیشتر باشد. لطفا داده های درست را وارد کنید",
                        "red");
                    maskdateta.ForeColor = Color.Red;
                    maskdateta.SelectionStart = 5;
                    maskdateta.SelectionLength = 2;
                    maskdateta.Focus();
                }
                if (dcheck(maskdateta.Text) == 2)
                {
                    showElanatNoOptionButton(
                        "   تعداد روزهای ماه نباید از 0 کمتر و از 31 بیشتر باشد. لطفا داده های درست را وارد کنید", "red");
                    maskdateta.ForeColor = Color.Red;
                    maskdateta.SelectionStart = 7;
                    maskdateta.SelectionLength = 2;
                    maskdateta.Focus();
                }
                else if ((dcheck(maskdateta.Text) == 0) && (dcheck(maskdatenow.Text) == 0))
                {
                    maskdatenow.ForeColor = Color.Black;
                    maskdateta.ForeColor = Color.Black;
                    SearchByDate(
                        "SELECT codenoskhe,idbimar,datefull,mablaghekol,franshizekol,mablaghepardakhti FROM listecodenoskhe Where datesabt Between '" +
                        maskdatenow.Text + "' And '" + maskdateta.Text + "'");
                    playsoundclick("\\sound\\click.wav");
                }
            }
        }

        private void btnsearchasdatetabaed_Click(object sender, EventArgs e)
        {
            if (DateTrust(maskdatebaed.Text) == true)
            {
                if (dcheck(maskdatebaed.Text) == 1)
                {
                    showElanatNoOptionButton(
                        "   تعداد ماه های سال نباید از 0 کمتر و از 12 بیشتر باشد. لطفا داده های درست را وارد کنید",
                        "red");
                    maskdatebaed.ForeColor = Color.Red;
                    maskdatebaed.SelectionStart = 5;
                    maskdatebaed.SelectionLength = 2;
                    maskdatebaed.Focus();
                }
                if (dcheck(maskdatebaed.Text) == 2)
                {
                    showElanatNoOptionButton(
                        "   تعداد روزهای ماه نباید از 0 کمتر و از 31 بیشتر باشد. لطفا داده های درست را وارد کنید", "red");
                    maskdatebaed.ForeColor = Color.Red;
                    maskdatebaed.SelectionStart = 7;
                    maskdatebaed.SelectionLength = 2;
                    maskdatebaed.Focus();
                }
                else if (dcheck(maskdatebaed.Text) == 0)
                {
                    maskdatebaed.ForeColor = Color.Black;
                    SearchByDate(
                        "SELECT codenoskhe,idbimar,datefull,mablaghekol,franshizekol,mablaghepardakhti FROM listecodenoskhe Where datesabt > '" +
                        maskdatebaed.Text + "'");
                    playsoundclick("\\sound\\click.wav");
                }
            }
            else
            {
                showElanatNoOptionButton(
                    "فرمت تاریخ درج شده توسط شما اشتباه است. مانند مثال روبه رو وارد کنید:  \"  1392/04/28  \"", "red");
                maskdatebaed.ForeColor = Color.Red;
            }
        }

        private void btnsearchdateasghabl_Click(object sender, EventArgs e)
        {
            if (DateTrust(mastdateghabl.Text) == true)
            {
                if (dcheck(mastdateghabl.Text) == 1)
                {
                    showElanatNoOptionButton(
                        "   تعداد ماه های سال نباید از 0 کمتر و از 12 بیشتر باشد. لطفا داده های درست را وارد کنید",
                        "red");
                    mastdateghabl.ForeColor = Color.Red;
                    mastdateghabl.SelectionStart = 5;
                    mastdateghabl.SelectionLength = 2;
                    mastdateghabl.Focus();
                }
                if (dcheck(mastdateghabl.Text) == 2)
                {
                    showElanatNoOptionButton(
                        "   تعداد روزهای ماه نباید از 0 کمتر و از 31 بیشتر باشد. لطفا داده های درست را وارد کنید", "red");
                    mastdateghabl.ForeColor = Color.Red;
                    mastdateghabl.SelectionStart = 7;
                    mastdateghabl.SelectionLength = 2;
                    mastdateghabl.Focus();
                }
                else if (dcheck(mastdateghabl.Text) == 0)
                {
                    mastdateghabl.ForeColor = Color.Black;
                    SearchByDate(
                        "SELECT codenoskhe,idbimar,datefull,mablaghekol,franshizekol,mablaghepardakhti FROM listecodenoskhe Where datesabt < '" +
                        mastdateghabl.Text + "'");
                    playsoundclick("\\sound\\click.wav");
                }
            }
            else
            {
                showElanatNoOptionButton(
                    "فرمت تاریخ درج شده توسط شما اشتباه است. مانند مثال روبه رو وارد کنید:  \"  1392/04/28  \"", "red");
                maskdatebaed.ForeColor = Color.Red;
            }
        }

        private void EmptyGrideSearch()
        {
            DataTable dt = new DataTable();
            dt.Clear();
            dataGridViewX2.DataSource = dt;
            dataGridViewX3.DataSource = dt;
            dtglistenoskhe.DataSource = dt;
        }

        public bool DateTrust(string date)
        {
            string[] split = date.Split('/');
            if ((split[0].Length + split[1].Length + split[2].Length) == 8)
                return true;
            else return false;
        }

        public byte dcheck(string tarikh)
        {
            string[] split = tarikh.Split('/');
            if (byte.Parse(split[1]) > 12 || byte.Parse(split[1]) < 0)
            {
                return 1;
            }
            else if (byte.Parse(split[2]) > 31 || byte.Parse(split[2]) < 0)
            {
                return 2;
            }
            return 0;
        }

        public void ShowElanat(bool status)
        {
            if (status == false)
            {
                timer1.Enabled = false;
                elanmessage.OptionsButtonVisible = false;
                timer1.Enabled = true;
            }
            else if (status == true)
            {
                timer1.Enabled = false;
                timer1.Enabled = true;
            }
        }

        private void buttonX6_Click(object sender, EventArgs e)
        {
            SearchByDate(
                "SELECT codenoskhe as [کد نسخه],idbimar as [ش.ش بیمار],datefull as [تاریخ ثبت],mablaghekol as [مبلغ کل],franshizekol as [فرانشیز کل],mablaghepardakhti as [مبلغ پرداختی بیمار] FROM listecodenoskhe");
        }

        public void showElanatNoOptionButton(string message, string color)
        {
            switch (color)
            {
                case "red":
                    elanmessage.ColorScheme = DevComponents.DotNetBar.Controls.eWarningBoxColorScheme.Red;
                    break;
                case "green":
                    elanmessage.ColorScheme = DevComponents.DotNetBar.Controls.eWarningBoxColorScheme.Green;
                    break;
                case "yellow":
                    elanmessage.ColorScheme = DevComponents.DotNetBar.Controls.eWarningBoxColorScheme.Yellow;
                    break;
                case "default":
                    elanmessage.ColorScheme = DevComponents.DotNetBar.Controls.eWarningBoxColorScheme.Default;
                    break;
            }
            ShowElanat(false);
            elanmessage.Visible = true;
            elanmessage.Text = message;
        }

        public void showElanatOptionButton(string message, string color, string optionText, string lblElanatText)
        {
            showElanatNoOptionButton(message, color);
            elanmessage.OptionsText = optionText;
            elanmessage.OptionsButtonVisible = true;
            lblelanat.Text = lblElanatText;
            ShowElanat(true);
        }

        private void elanmessage_OptionsClick(object sender, EventArgs e)
        {
            optionelanat();
        }

        private void ribbonTabItem1_MouseMove(object sender, MouseEventArgs e)
        {
            playsoundmouse("\\sound\\mouse.wav");
        }

        private void ribbonTabItem1_MouseLeave(object sender, EventArgs e)
        {
            sound = true;
        }

        private void button3_Click(object sender, EventArgs e)
        {
            string s;
            s = dataGridViewX3.Rows[(dataGridViewX3.CurrentRow.Index) + 1].Cells[0].Value.ToString();
            MessageBox.Show(s);
        }

        private void button5_Click_1(object sender, EventArgs e)
        {
            int count = dataGridViewX3.Rows.Count;
        }

        private void saveStyle(string style)
        {
            switch (style)
            {
                case "Office2010Black":
                    Properties.Settings.Default.Theme = DevComponents.DotNetBar.eStyle.Office2010Black;
                    break;
                case "Office2010Blue":
                    Properties.Settings.Default.Theme = DevComponents.DotNetBar.eStyle.Office2010Blue;
                    break;
                case "Office2010Silver":
                    Properties.Settings.Default.Theme = DevComponents.DotNetBar.eStyle.Office2010Silver;
                    break;
                case "Metro":
                    Properties.Settings.Default.Theme = DevComponents.DotNetBar.eStyle.Metro;
                    break;
                case "VisualStudio2010Blue":
                    Properties.Settings.Default.Theme = DevComponents.DotNetBar.eStyle.VisualStudio2010Blue;
                    break;
                case "Windows7Blue":
                    Properties.Settings.Default.Theme = DevComponents.DotNetBar.eStyle.Windows7Blue;
                    break;
            }
            Properties.Settings.Default.Save();
        }

        private void btnStyleBlack_Click(object sender, EventArgs e)
        {
            styleManager1.ManagerStyle = DevComponents.DotNetBar.eStyle.Office2010Black;
            saveStyle("Office2010Black");
        }

        private void btnStyleSilver_Click(object sender, EventArgs e)
        {
            styleManager1.ManagerStyle = DevComponents.DotNetBar.eStyle.Office2010Silver;
            saveStyle("Office2010Silver");
        }

        private void btnStyleBlue_Click(object sender, EventArgs e)
        {
            styleManager1.ManagerStyle = DevComponents.DotNetBar.eStyle.Office2010Blue;
            saveStyle("Office2010Blue");
        }

        private void btnStyleMetro_Click(object sender, EventArgs e)
        {
            styleManager1.ManagerStyle = DevComponents.DotNetBar.eStyle.Metro;
            saveStyle("Metro");
        }

        private void btnStyleVisual2012_Click(object sender, EventArgs e)
        {
            styleManager1.ManagerStyle = DevComponents.DotNetBar.eStyle.VisualStudio2010Blue;
            saveStyle("VisualStudio2010Blue");
        }

        private void btnStyleWin7_Click(object sender, EventArgs e)
        {
            styleManager1.ManagerStyle = DevComponents.DotNetBar.eStyle.Windows7Blue;
            saveStyle("Windows7Blue");
        }

        private void buttonItem4_Click(object sender, EventArgs e)
        {


        }

        private void txttedad_Leave(object sender, EventArgs e)
        {
            this.AcceptButton = null;
        }

        private void txttedad_Click(object sender, EventArgs e)
        {
            this.AcceptButton = btninsert;
        }

        private void txtcode_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                txtspname.Focus();
            }
            if (e.KeyCode == Keys.Down)
            {
                txtspname.Focus();
            }
            if (e.KeyCode == Keys.Left)
            {
                txtcodepd.Focus();
            }
        }

        private void txtspname_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                txttakhasos.Focus();
            } //enter
            if (e.KeyCode == Keys.Down)
            {
                txttakhasos.Focus();
            } //paein
            if (e.KeyCode == Keys.Left)
            {
                txtcodepd.Focus();
            } //chap
            if (e.KeyCode == Keys.Up)
            {
                txtcode.Focus();
            } //bala
        }

        private void txttakhasos_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                btnaddpezeshk_Click(sender, e);
            } //enter
            if (e.KeyCode == Keys.Down)
            {
                txtcodepd.Focus();
            } //paein
            if (e.KeyCode == Keys.Left)
            {
                txtcodepd.Focus();
            } //chap
            if (e.KeyCode == Keys.Up)
            {
                txtspname.Focus();
            } //bala
        }

        private void txtcodepd_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                btnpdelete_Click(sender, e);
            } //enter
            if (e.KeyCode == Keys.Down)
            {
                txtcodepd.Focus();
            } //paein
            if (e.KeyCode == Keys.Left)
            {
                txtpidedit.Focus();
            } //chap
            if (e.KeyCode == Keys.Right)
            {
                txtcode.Focus();
            } //bala
        }

        private void txtpidedit_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                btnpsearch_Click(sender, e);
                txtnewpid.Focus();
            } //enter
            if (e.KeyCode == Keys.Down)
            {
                txtnewpid.Focus();
            } //paein
            if (e.KeyCode == Keys.Left)
            {
                txtnewpid.Focus();
            } //chap
            if (e.KeyCode == Keys.Right)
            {
                txtcodepd.Focus();
            } //bala
        }

        private void txtnewpid_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                txtnewpname.Focus();
            } //enter
            if (e.KeyCode == Keys.Down)
            {
                txtnewpname.Focus();
            } //paein
            if (e.KeyCode == Keys.Right)
            {
                txtpidedit.Focus();
            } //bala
        }

        private void txtnewptakhasos_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                btneditpezeshk_Click(sender, e);
                txtpidedit.Focus();
            } //enter
            if (e.KeyCode == Keys.Up)
            {
                txtnewpname.Focus();
            } //chap
            if (e.KeyCode == Keys.Right)
            {
                txtpidedit.Focus();
            } //bala
        }

        private void btneditpezeshk_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(txtnewpid.Text) && !string.IsNullOrEmpty(txtnewpname.Text) && !string.IsNullOrEmpty(txtnewptakhasos.Text))
            {
                try
                {
                    SqlCommand com = new SqlCommand();
                    com.CommandText = "update pezeshk set pid=@pid,pname=@pname,takhasos=@takhasos,State=@State where pid=@pidWhere";
                    com.Parameters.AddWithValue("@pid", txtnewpid.Text);
                    com.Parameters.AddWithValue("@pname", txtnewpname.Text);
                    com.Parameters.AddWithValue("@takhasos", txtnewptakhasos.Text);
                    com.Parameters.AddWithValue("@State", true);
                    com.Parameters.AddWithValue("@pidWhere", txtpidedit.Text);
                    UpdateAndInsert(com);
                    showElanatNoOptionButton("مشخصات فردی پزشک مورد نظر با موفقیت بروز شد", "green");
                    Falsetext();
                    txtpidedit.Text = "";
                    playsoundclick("\\sound\\login.wav");
                }
                catch
                {
                    showElanatNoOptionButton("کد نظام پزشکی وارد شده مربوط به پزشک دیگری است", "red");
                } 
            }
            else
            {
                /////////////////////////
                showElanatNoOptionButton(
                    "   لطفا تمام فیلدهای مربوطه را  با دقت کامل نمایید", "red");
                /////////////////////////
            }
        }

        private void txtsearchcodenoskhe_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                btnsearchbycode_Click(sender, e);
                txtsearchcodeeshterak.Focus();
            }
            if (e.KeyCode == Keys.Down)
            {
                txtsearchcodeeshterak.Focus();
            }
            if (e.KeyCode == Keys.Left)
            {
                txtsearchname.Focus();
            }
        }

        private void txtsearchcodeeshterak_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                btnsearchbycode_Click(sender, e);
            }
            if (e.KeyCode == Keys.Up)
            {
                txtsearchcodenoskhe.Focus();
            }
            if (e.KeyCode == Keys.Left)
            {
                txtsearchfamily.Focus();
            }
            if (e.KeyCode == Keys.Down)
            {
                txtsearchname.Focus();
            }
        }

        private void txtsearchname_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                txtsearchfamily.Focus();
            }
            if (e.KeyCode == Keys.Left)
            {
                maskdatenow.Focus();
            }
            if (e.KeyCode == Keys.Right)
            {
                txtsearchcodenoskhe.Focus();
            }
            if (e.KeyCode == Keys.Down)
            {
                txtsearchfamily.Focus();
            }
        }

        private void txtsearchfamily_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                btnsearchbyname_Click(sender, e);
                txtsearchname.Focus();
            }
            if (e.KeyCode == Keys.Left)
            {
                maskdatenow.Focus();
            }
            if (e.KeyCode == Keys.Right)
            {
                txtsearchcodeeshterak.Focus();
            }
            if (e.KeyCode == Keys.Down)
            {
                maskdateta.Focus();
            }
            if (e.KeyCode == Keys.Up)
            {
                txtsearchname.Focus();
            }
        }

        private void maskdatenow_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                maskdateta.Focus();
            }
            if (e.KeyCode == Keys.Tab)
            {
                maskdateta.Focus();
            }
        }

        private void maskdateta_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                btnsearchasdatetadate_Click(sender, e);
                maskdatenow.Focus();
            }
            if (e.KeyCode == Keys.Tab)
            {
                maskdatebaed.Focus();
            }
        }

        private void maskdatebaed_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                btnsearchasdatetabaed_Click(sender, e);
            }
            if (e.KeyCode == Keys.Tab)
            {
                mastdateghabl.Focus();
            }
        }

        private void mastdateghabl_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                btnsearchdateasghabl_Click(sender, e);
            }
            if (e.KeyCode == Keys.Tab)
            {
                maskdatenow.Focus();
            }
        }



        private void txtcodemeli_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                txtname.Focus();
            }
            if (e.KeyCode == Keys.Left)
            {
                txtdatebirth.Focus();
            }
            if (e.KeyCode == Keys.Down)
            {
                txtname.Focus();
            }
        }

        private void txtname_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                txtfamily.Focus();
            }
            if (e.KeyCode == Keys.Left)
            {
                txtdateetebar.Focus();
            }
            if (e.KeyCode == Keys.Down)
            {
                txtfamily.Focus();
            }
            if (e.KeyCode == Keys.Up)
            {
                txtcodemeli.Focus();
            }
        }

        private void txtfamily_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                txtdatebirth.Focus();
            }
            if (e.KeyCode == Keys.Left)
            {
                txtdatesabt.Focus();
            }
            if (e.KeyCode == Keys.Down)
            {
                txtdatebirth.Focus();
            }
            if (e.KeyCode == Keys.Up)
            {
                txtname.Focus();
            }
        }

        private void txtdatebirth_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                txtdateetebar.Focus();
            }
            if (e.KeyCode == Keys.Left)
            {
                cbbimeh.Focus();
            }
            if (e.KeyCode == Keys.Right)
            {
                txtcodemeli.Focus();
            }
            if (e.KeyCode == Keys.Down)
            {
                txtdateetebar.Focus();
            }
            if (e.KeyCode == Keys.Up)
            {
                txtfamily.Focus();
            }
        }

        private void txtdateetebar_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                txtdatesabt.Focus();
            }
            if (e.KeyCode == Keys.Left)
            {
                cbbimeh.Focus();
            }
            if (e.KeyCode == Keys.Right)
            {
                txtname.Focus();
            }
            if (e.KeyCode == Keys.Down)
            {
                txtdatesabt.Focus();
            }
            if (e.KeyCode == Keys.Up)
            {
                txtdatebirth.Focus();
            }
        }

        private void txtdatesabt_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                cbbimeh.Focus();
            }
            if (e.KeyCode == Keys.Left)
            {
                cbbimeh.Focus();
            }
            if (e.KeyCode == Keys.Right)
            {
                txtfamily.Focus();
            }
            if (e.KeyCode == Keys.Down)
            {
                cbbimeh.Focus();
            }
            if (e.KeyCode == Keys.Up)
            {
                txtdateetebar.Focus();
            }
        }


        private void btnLoadAllDaro_Click(object sender, EventArgs e)
        {
            GroupSearchDaroShowAndHide(true);
            lbl_ListeDaroAndListeBuyState.Text = "Daro";
            searchdaro(
                "select id as [کد دارو],lname as [نام لاتین],fname as [نام فارسی],tolid as [تاریخ تولید],engheza as [تاریخ انقضا],gheymat as [قیمت],anbar as [شماره انبار],ghafase as [شماره قفسه],tarkibat as [طریقه مصرف],compony as [تولید کننده],tedad as [تعداد], case  when State = 0 then N'نا موجود' when State = 1 then  N'موجود' End as وضعیت from home order by lname");
            playsoundclick("\\sound\\click.wav");
            dgsearchdaro.RowHeadersWidth = 58;
            changcolorlistedaro();
            grbEditDaro.Visible = true;
            grbListBuy.Visible = false;

        }

        private void changcolorlistedaro()
        {
            for (int i = 0; i < dgsearchdaro.Rows.Count; i++)
            {
                if (dgsearchdaro.Rows[i].Cells["وضعیت"].Value.ToString() == "نا موجود")
                {
                    dgsearchdaro.Rows[i].DefaultCellStyle.BackColor = Color.Pink;
                    dgsearchdaro.Rows[i].HeaderCell.Value = "حذف";
                }
                else
                {
                    dgsearchdaro.Rows[i].HeaderCell.Value = "فعال";
                }
            }
        }
        private void toolStripMenuItem1_Click(object sender, EventArgs e)
        {

            

        }

        private void dataGridView11_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Delete) DeleteDaro_Click(sender, e);
            
        }

        private void buttonX2_Click(object sender, EventArgs e)
        {
            if (addEshterak.Enabled)
            {
                txtcodemeli.Text = txteshterak.Text;
            addEshterak.Select();
            txtname.Focus();
            showbimeh("select bimeh.id as [کدبیمه],bimeh.bname as [نام بیمه],State from bimeh");
            lblsendEshterak.Text = "1";
            }
            else
            {
                showElanatNoOptionButton(@"   کاربر گرامی، متاسفانه دسترسی این بخش برای شما قابل دسترس نیست. پیامی برای مدیر ارسال شد که در صورت صلاحدید این امکان را برای شما فراهم میکند","red");
                string message =@"مدیریت محترم کاربر | {0} | تلاش در ثبت اشتراک داشته است اما این سطح دسترسی توسط شما برای ایشان غیر فعال شده است. در صورت صلاحدید این سطح دسترسی را فعال کنید";
                message=string.Format(message, login.fullName);
                sendFastMessage("admin", message, "در خواست امکان ثبت اشتراک", "Robot_" + login.uname);
            }
        }

        private void txteshterak_Leave(object sender, EventArgs e)
        {
            this.AcceptButton = null;
        }

        private void txtpcode_Leave(object sender, EventArgs e)
        {
            this.AcceptButton = null;
        }

        private void txtpcode_Enter(object sender, EventArgs e)
        {
            this.AcceptButton = btn_addPezeshk;
        }

        private void txteshterak_Enter(object sender, EventArgs e)
        {
            this.AcceptButton = btn_addEshterak;
        }

        private void btn_addPezeshk_Click(object sender, EventArgs e)
        {
            if (ribpedit.Enabled)
            {
                ribpedit.Select();
                txtspname.Focus();
                txtcode.Text = txtpcode.Text;
                lblsendAddPezeshk.Text = "1"; 
            }
            else
            {
                showElanatNoOptionButton(@"   کاربر گرامی، متاسفانه دسترسی این بخش برای شما قابل دسترس نیست. پیامی برای مدیر ارسال شد که در صورت صلاحدید این امکان را برای شما فراهم میکند", "red");
                string message = @"مدیریت محترم کاربر | {0} | تلاش در ثبت پزشک را داشته است اما این سطح دسترسی توسط شما برای ایشان غیر فعال شده است. در صورت صلاحدید این سطح دسترسی را فعال کنید";
                message = string.Format(message, login.fullName);
                sendFastMessage("admin", message, "در خواست امکان ثبت پزشک", "Robot_"+login.uname);
            }
        }

        private void txtsearchdaro_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void buttonItem9_Click(object sender, EventArgs e)
        {

            if (dtglistenoskhe.RowCount > 0)
            {
                DataTable dtfname = new DataTable();
                var ListeDaro = ((DataTable) dtglistenoskhe.DataSource).Copy();
                for (int i = 0; i < ListeDaro.Rows.Count; i++)
                {
                    string code = ListeDaro.Rows[i][0].ToString();
                    SqlDataAdapter da = new SqlDataAdapter("select fname from home where id=" + code,
                        "server=(local);database=darokhane;trusted_connection=yes");
                    da.Fill(dtfname);
                    ListeDaro.Rows[i][0] = dtfname.Rows[0][0].ToString();
                    dtfname.Clear();
                }
                stiReport1.Load("Report.mrt");
                StiVariable varBName = new StiVariable("customer", "BName", typeof (string), txtnoskhenamefull.Text,
                    false);
                StiVariable varcode = new StiVariable("customer", "codenoskhe", typeof (string), txtnoskhenamefull.Text,
                    false);
                StiVariable varDate = new StiVariable("customer", "shamsi", typeof (string), txtdatenow.Text, false);
                stiReport1.Dictionary.Variables.Add(varBName);
                stiReport1.Dictionary.Variables.Add(varcode);
                stiReport1.Dictionary.Variables.Add(varDate);
                stiReport1.RegData("ListeDaro", ListeDaro);
                stiReport1.Show();
            }
            else
            {
                showElanatNoOptionButton("   هیچ نسخه ای انتخاب نشده. لطفا با جستجوی مناسب نسخه خود را انتخاب کنید",
                    "red");
            }
        }

        private void btn_PrintListeDaro_Click(object sender, EventArgs e)
        {
            if (dgsearchdaro.RowCount > 0)
            {
                DataTable listeDaro;
                using (listeDaro = ((DataTable) dgsearchdaro.DataSource).Copy())
                {
                    stiReport1.Load("ListeDaro.mrt");
                    StiVariable varBName = new StiVariable("customer", "BName", typeof (string), txtnoskhenamefull.Text,
                        false);
                    StiVariable varcode = new StiVariable("customer", "codenoskhe", typeof (string),
                        txtnoskhenamefull.Text,
                        false);
                    StiVariable varDate = new StiVariable("customer", "shamsi", typeof (string), txtdatenow.Text, false);
                    stiReport1.Dictionary.Variables.Add(varBName);
                    stiReport1.Dictionary.Variables.Add(varcode);
                    stiReport1.Dictionary.Variables.Add(varDate);
                    stiReport1.RegData("ListeDaro", listeDaro);
                }
                stiReport1.Show();
            }
            else
            {
                showElanatNoOptionButton("   هیچ نسخه ای انتخاب نشده. لطفا با جستجوی مناسب نسخه خود را انتخاب کنید",
                    "red");
            }

        }

        private void btn_Delete_Daro_Click(object sender, EventArgs e)
        {
            playsoundclick("\\sound\\click.wav");
            SqlCommand com = new SqlCommand("update home set State=@State where id=@id");
            com.Parameters.AddWithValue("@State", false);
            com.Parameters.AddWithValue("@id", txteditid.Text);
            UpdateAndInsert(com);
            ChangColorDataGridDelete(dgsearchdaro);
        }

        private void buttonItem10_Click_1(object sender, EventArgs e)
        {
            GroupSearchDaroShowAndHide(true);
            lbl_ListeDaroAndListeBuyState.Text = "Daro";
            searchdaro(
                "select id as [کد دارو],lname as [نام لاتین],fname as [نام فارسی],tolid as [تاریخ تولید],engheza as [تاریخ انقضا],gheymat as [قیمت],anbar as [شماره انبار],ghafase as [شماره قفسه],tarkibat as [طریقه مصرف],compony as [تولید کننده],tedad as [تعداد], case  when State = 0 then N'نا موجود' when State = 1 then  N'موجود' End as Result from home where State='True' order by lname");
            playsoundclick("\\sound\\click.wav");
            dgsearchdaro.RowHeadersWidth = 40;
            grbEditDaro.Visible = true;
            grbListBuy.Visible = false;
        }

        private void buttonX2_Click_1(object sender, EventArgs e)
        {
            try
            {
                SqlCommand com = new SqlCommand();
                com.CommandText ="update home set tedad=@tedad,State=@State where id=@id";
                com.Parameters.AddWithValue("@tedad", (int.Parse(txtedittedad.Text) + int.Parse(txteditplus.Text)));
                com.Parameters.AddWithValue("@id", txteditid.Text);
                com.Parameters.AddWithValue("@State", true);
                UpdateAndInsert(com);
                playsoundclick("\\sound\\click.wav");
                string message = "تعداد \" " + txteditplus.Text + " \" عدد به موجودی داروی \" " + txteditfname.Text +
                                 " \" اضافه شد";
                showElanatNoOptionButton(message, "green");
                btnLoadAllDaro_Click(sender, e);
            }
            catch
            {
                /////////////////////////
                showElanatNoOptionButton("   در استصال با بانک خطایی رخ داده است. لطفا دوباره تلاش کنید", "red");
                /////////////////////////
            }
        }


        private void Backup(string strFileName)
        {
            try
            {
                if (strFileName != string.Empty)
                {
                    string command = @"BACKUP DATABASE darokhane TO DISK='" + strFileName + "'";
                    this.Cursor = Cursors.WaitCursor;
                    SqlCommand oCommand = null;
                    SqlConnection oConnection = null;
                    oConnection = new SqlConnection("server=(local);database=darokhane;trusted_connection=yes");
                    if (oConnection.State != ConnectionState.Open)
                        oConnection.Open();
                    oCommand = new SqlCommand(command, oConnection);
                    oCommand.ExecuteNonQuery();
                    this.Cursor = Cursors.Default;
                    /////////////////////////
                    showElanatNoOptionButton(
                        "   پشتیبان گیری از بانک با موفقیت انجام شد", "green");
                    /////////////////////////
                }
            }
            catch (Exception)
            {
                /////////////////////////
                showElanatNoOptionButton(
                    "   متاسفانه خطایی در پشتیبان گیری رخ داده است", "red");
                /////////////////////////
            }
        }

        private void buttonItem15_Click(object sender, EventArgs e)
        {
            showElanatNoOptionButton(
                "توجه کنید که از آدرسی که انتخاب میکنید برای پشتیبان گیری و بازیابی بانک اصلاعاتی استفاده میشود.توصیه میشود که درایوی بجز درایو C انتخاب شود",
                "Yellow");
        }

        private void btn_SetAddress_Click(object sender, EventArgs e)
        {

            txtBackUpAndRestorAddress.Text = setSave();
        }

        private string setSave()
        {
            var savedDialog1 = new SaveFileDialog();
            string strFileName = string.Empty;
            savedDialog1.DefaultExt = "BAK";
            savedDialog1.FileName = "BackupFile " + lbldatehead.Text.Replace("/","-");
            savedDialog1.Filter = @"SQL Backup files (*.BAK) |*.BAK|All files(*.*) |*.*";
            savedDialog1.FilterIndex = 1;
            savedDialog1.OverwritePrompt = true;
            savedDialog1.Title = "Backup SQL File";
            if (savedDialog1.ShowDialog() == DialogResult.OK)
            {
                strFileName = savedDialog1.FileName;
                Properties.Settings.Default.Address = savedDialog1.FileName;
                Properties.Settings.Default.Save();
            }
            else
            {
                return string.Empty;
            }
            return strFileName;
        }

        private void buttonItem14_Click(object sender, EventArgs e)
        {
            if (txtBackUpAndRestorAddress.Text == string.Empty)
            {
                Backup(setSave());
            }
            else
            {
                Backup(txtBackUpAndRestorAddress.Text);
            }
        }

        private void Restore(string strFileName)
        {
            try
            {
                if (strFileName != string.Empty)
                {
                    string command = "ALTER DATABASE darokhane SET OFFLINE with ROLLBACK IMMEDIATE RESTORE DATABASE darokhane FROM DISK = '" + strFileName + "'" +
                                     " WITH REPLACE alter database darokhane set online";
                    this.Cursor = Cursors.WaitCursor;
                    SqlCommand oCommand = null;
                    SqlConnection oConnection = null;
                    oConnection = new SqlConnection("Data Source=(local);database=darokhane;Integrated Security=SSPI");
                    if (oConnection.State != ConnectionState.Open)
                        oConnection.Open();
                    oCommand = new SqlCommand(command, oConnection);
                    oCommand.ExecuteNonQuery();
                    this.Cursor = Cursors.Default;
                    /////////////////////////
                    showElanatNoOptionButton(
                        "   عملیات بازیابی اطلاعات با موفقیت انجام شد", "green");
                    /////////////////////////
                }
            }
            catch (Exception)
            {
                /////////////////////////
                showElanatNoOptionButton(
                    "   در عملیات بازیابی بانک خطایی رخ داده است", "red");
                /////////////////////////
            }
        }
        private string loadAddress()
        {
            var openFileDialog1 = new OpenFileDialog();
            string strFileName;
            openFileDialog1.Filter = @"SQL Backup files (*.BAK) |*.BAK|All files(*.*) |*.*";
            openFileDialog1.FilterIndex = 1;
            openFileDialog1.Title = "Restore SQL File";
            switch (openFileDialog1.ShowDialog())
            {
                case DialogResult.OK:
                    strFileName = openFileDialog1.FileName;
                    break;
                default:
                    return string.Empty;
            }
            return strFileName;
        }

        private void buttonItem16_Click_1(object sender, EventArgs e)
        {
            Restore(txtBackUpAndRestorAddress.Text != string.Empty ? txtBackUpAndRestorAddress.Text : loadAddress());
        }

        private void txtsearchtarkibat_TextChanged(object sender, EventArgs e)
        {
            if (txtsearchtarkibat.Text != string.Empty)
                searchdaro("select * from home where tarkibat like N'%" + txtsearchtarkibat.Text + "%'");
        }

        private void txtsearchanbar_TextChanged(object sender, EventArgs e)
        {
            if (txtsearchanbar.Text != string.Empty)
                searchdaro("select * from home where anbar=" + txtsearchanbar.Text);
        }

        private void buttonItem17_Click(object sender, EventArgs e)
        {
            playsoundclick("\\sound\\click.wav");
            logon frm = new logon();
            frm.ShowDialog();
        }

        private void buttonItem3_Click(object sender, EventArgs e)
        {
           
            

            
        }

        private void charting_Click(object sender, EventArgs e)
        {
            showcharting();
        }

        private void btn_2D_Click(object sender, EventArgs e)
        {
            
        }

        private void chartminandmax()
        {
            // Find max
            DataPoint maxValuePoint = chart1.Series["Series1"].Points.FindMaxByValue();
            maxValuePoint.Color = Color.Lime;
            // Find min
            DataPoint minValuePoint = chart1.Series["Series1"].Points.FindMinByValue();
            minValuePoint.Color = Color.Red;
        }

        private void timer2_Tick(object sender, EventArgs e)
        {
            if (chart1.ChartAreas[0].Area3DStyle.Rotation <= 177)
                chart1.ChartAreas[0].Area3DStyle.Rotation += 3;
            else
                chart1.ChartAreas[0].Area3DStyle.Rotation = -180;
        }

        private void buttonItem43_Click(object sender, EventArgs e)
        {
            SqlConnection con = new SqlConnection("server=.;database=darokhane;trusted_connection=yes");
            SqlCommand com = new SqlCommand("select top " + txt_chart_Date.Text + " datesabt,count(datesabt) as sums from listecodenoskhe group by datesabt order by sums desc", con);
            SqlDataAdapter da = new SqlDataAdapter(com);
            DataTable dt = new DataTable();
            da.Fill(dt);
            chart1.DataSource = dt;
            chart1.Series["Series1"].XValueMember = "datesabt";
            chart1.Series["Series1"].YValueMembers = "sums";
            //neshan dadan tedade forosh balaye soton
            chart1.Series["Series1"].IsValueShownAsLabel = true;
            chart1.DataBind();
            chartminandmax();
        }

        private void buttonItem3_Click_1(object sender, EventArgs e)
        {
            SqlConnection con = new SqlConnection("server=.;database=darokhane;trusted_connection=yes");
            SqlCommand com = new SqlCommand("select top " + txt_chart_Daro .Text+ " iddaro,home.fname,sum(tedadedaro) as sums from noskhe INNer JOIN home ON noskhe.iddaro = home.id group by iddaro,home.fname order by sums desc", con);
            SqlDataAdapter da = new SqlDataAdapter(com);
            DataTable dt = new DataTable();
            da.Fill(dt);
            chart1.DataSource = dt;
            chart1.Series["Series1"].XValueMember = "fname";
            chart1.Series["Series1"].YValueMembers = "sums";
            //neshan dadan tedade forosh balaye soton
            chart1.Series["Series1"].IsValueShownAsLabel = true;
            chart1.DataBind();
            chartminandmax();
        }

        private void buttonItem41_Click(object sender, EventArgs e)
        {
            SqlConnection con = new SqlConnection("server=.;database=darokhane;trusted_connection=yes");
            SqlCommand com = new SqlCommand("select top " + txt_chart_Noskhe.Text + " idbimar,eshterak.bname+' ' +eshterak.bfamily as name,count(idbimar) as sums from listecodenoskhe INNer JOIN eshterak ON listecodenoskhe.idbimar = eshterak.codemeli group by idbimar,eshterak.bname,eshterak.bfamily order by sums desc", con);
            SqlDataAdapter da = new SqlDataAdapter(com);
            DataTable dt = new DataTable();
            da.Fill(dt);
            chart1.DataSource = dt;
            chart1.Series["Series1"].XValueMember = "name";
            chart1.Series["Series1"].YValueMembers = "sums";
            //neshan dadan tedade forosh balaye soton
            chart1.Series["Series1"].IsValueShownAsLabel = true;
            chart1.DataBind();
            chartminandmax();
        }

        private void btn_Ribon_3D_Click(object sender, EventArgs e)
        {
            buttonItem66.Checked = false;
            btn_Ribon_3D.Checked = true;
            btn_Ribon_2D.Checked = false;
            buttonItem65.Enabled = true;
            chart1.ChartAreas["Default"].Area3DStyle.Enable3D = true;
            chart1.ChartAreas["Default"].Area3DStyle.Rotation = 30;
            chart1.ChartAreas["Default"].Area3DStyle.Inclination = 40;
            chart1.ChartAreas["Default"].Area3DStyle.WallWidth = 7;
        }

        private void btn_Ribon_2D_Click(object sender, EventArgs e)
        {
            sliderItem1.Enabled = false;
            timer2.Enabled = false;
            chart1.ChartAreas["Default"].Area3DStyle.Enable3D = false;
            btn_Ribon_3D.Checked = false;
            btn_Ribon_2D.Checked = true;
        }

        private void sliderItem1_ValueChanged(object sender, EventArgs e)
        {
            timer2.Interval = 1000 - sliderItem1.Value;
        }

        private void buttonItem65_Click(object sender, EventArgs e)
        {
            switch (!buttonItem65.Checked)
            {
                case true:
                        buttonItem65.Checked = true;
                        buttonItem16.Text = "    توقف چرخش نمودار";
                        timer2.Enabled = true;
                        sliderItem1.Enabled = true;
                        break;
                case false:
                    buttonItem16.Text = "         چرخش نمودار";
                    buttonItem65.Checked = false;
                    timer2.Enabled = false;
                    sliderItem1.Enabled = false;
                    break;
            }
        }

        private void buttonItem66_Click(object sender, EventArgs e)
        {
            switch (!buttonItem66.Checked)
            {
                case true:
                    if (btn_Ribon_2D.Checked)
                    {
                        buttonItem66.Checked = true;
                        chart1.ChartAreas["Default"].CursorX.IsUserEnabled = true;
                        chart1.ChartAreas["Default"].CursorX.IsUserSelectionEnabled = true;
                        chart1.ChartAreas["Default"].AxisX.ScaleView.Zoomable = true;
                        chart1.ChartAreas["Default"].AxisX.ScrollBar.IsPositionedInside = true;
                    }
                    else
                    {
                        buttonItem66.Checked = false;
                        showElanatNoOptionButton("   این قابلیت فقط در حالت دو بعدی قابل استفاده می باشد","red");
                    }
                    break;
                case false:
                    buttonItem66.Checked = false;
                    chart1.ChartAreas["Default"].CursorX.IsUserEnabled = false;
                    chart1.ChartAreas["Default"].CursorX.IsUserSelectionEnabled = false;
                    chart1.ChartAreas["Default"].AxisX.ScaleView.Zoomable = false;
                    chart1.ChartAreas["Default"].AxisX.ScrollBar.IsPositionedInside = false;
                    chart1.ChartAreas["Default"].CursorX.AutoScroll = true;
                    break;
            }
        }

        private void btn_chart_Pic_Click(object sender, EventArgs e)
        {
            SaveFileDialog saveFileDialog1 = new SaveFileDialog();
            saveFileDialog1.Filter =
                "Bitmap (*.bmp)|*.bmp|JPEG (*.jpg)|*.jpg|EMF (*.emf)|*.emf|PNG (*.png)|*.png|SVG (*.svg)|*.svg|GIF (*.gif)|*.gif|TIFF (*.tif)|*.tif";
            saveFileDialog1.FilterIndex = 2;
            saveFileDialog1.RestoreDirectory = true;

            // Set image file format
            if (saveFileDialog1.ShowDialog() == DialogResult.OK)
            {
                ChartImageFormat format = ChartImageFormat.Bmp;

                if (saveFileDialog1.FileName.EndsWith("bmp"))
                {
                    format = ChartImageFormat.Bmp;
                }
                else if (saveFileDialog1.FileName.EndsWith("jpg"))
                {
                    format = ChartImageFormat.Jpeg;
                }
                else if (saveFileDialog1.FileName.EndsWith("emf"))
                {
                    format = ChartImageFormat.Emf;
                }
                else if (saveFileDialog1.FileName.EndsWith("gif"))
                {
                    format = ChartImageFormat.Gif;
                }
                else if (saveFileDialog1.FileName.EndsWith("png"))
                {
                    format = ChartImageFormat.Png;
                }
                else if (saveFileDialog1.FileName.EndsWith("tif"))
                {
                    format = ChartImageFormat.Tiff;
                }
                // Save image
                this.chart1.SaveImage(saveFileDialog1.FileName, format);
            }
        }

        private void btn_chart_Print_Click(object sender, EventArgs e)
        {
            chart1.Printing.PageSetup();
            chart1.Printing.PrintPreview();
            chart1.Printing.Print(false);
        }

        private void buttonItem42_Click(object sender, EventArgs e)
        {
            chart1.Series["Series1"].ChartType = SeriesChartType.Column;
        }

        private void buttonItem44_Click(object sender, EventArgs e)
        {
            chart1.Series["Series1"].ChartType = SeriesChartType.Bubble;
        }

        private void buttonItem45_Click(object sender, EventArgs e)
        {
            chart1.Series["Series1"].ChartType = SeriesChartType.Line;
        }

        private void buttonItem46_Click(object sender, EventArgs e)
        {
            chart1.Series["Series1"].ChartType = SeriesChartType.Area;
        }

        private void buttonItem47_Click(object sender, EventArgs e)
        {
            chart1.Series["Series1"].ChartType = SeriesChartType.Point;
        }

        private void buttonItem48_Click(object sender, EventArgs e)
        {
            chart1.Series["Series1"].ChartType = SeriesChartType.Polar;
        }

        private void buttonItem49_Click(object sender, EventArgs e)
        {
            chart1.Series["Series1"].ChartType = SeriesChartType.Pie;
        }

        private void buttonItem50_Click(object sender, EventArgs e)
        {
            chart1.Series["Series1"].ChartType = SeriesChartType.Radar;
        }

        private void buttonItem51_Click(object sender, EventArgs e)
        {
            chart1.Series["Series1"].ChartType = SeriesChartType.Range;
        }

        private void buttonItem52_Click(object sender, EventArgs e)
        {
            chart1.Palette = ChartColorPalette.Bright;
        }

        private void buttonItem53_Click(object sender, EventArgs e)
        {
            chart1.Palette = ChartColorPalette.Grayscale;
        }

        private void buttonItem54_Click(object sender, EventArgs e)
        {
            chart1.Palette = ChartColorPalette.Excel;
        }

        private void buttonItem57_Click(object sender, EventArgs e)
        {
            chart1.Palette = ChartColorPalette.EarthTones;
        }

        private void buttonItem56_Click(object sender, EventArgs e)
        {
            chart1.Palette = ChartColorPalette.Pastel;
        }

        private void buttonItem55_Click(object sender, EventArgs e)
        {
            chart1.Palette = ChartColorPalette.Light;
        }

        private void buttonItem58_Click(object sender, EventArgs e)
        {
            chart1.Palette = ChartColorPalette.SemiTransparent;
        }

        private void buttonItem59_Click(object sender, EventArgs e)
        {
            chart1.Palette = ChartColorPalette.Berry;
        }

        private void buttonItem60_Click(object sender, EventArgs e)
        {
            chart1.Palette = ChartColorPalette.Chocolate;
        }

        private void buttonItem61_Click(object sender, EventArgs e)
        {
            chart1.Palette = ChartColorPalette.Fire;
        }

        private void buttonItem62_Click(object sender, EventArgs e)
        {
            chart1.Palette = ChartColorPalette.SeaGreen;
        }

        private void buttonItem63_Click(object sender, EventArgs e)
        {
            chart1.Palette = ChartColorPalette.BrightPastel;
        }

        private void buttonItem64_Click(object sender, EventArgs e)
        {
            chart1.Palette = ChartColorPalette.None;
        }

        private void timer_Saat_Tick(object sender, EventArgs e)
        {
            lblsaat.Text = DateTime.Now.ToLongTimeString()+" :ساعت";
        }

        private void btn_language_Click(object sender, EventArgs e)
        {
            switch (btn_language.Text)
            {
                case "EN":
                    btn_language.Text = "FA";
                    btn_language.Tooltip = "فارسی | Persian";
                    CultureInfo languageFa = new CultureInfo("fa-ir");
                    InputLanguage.CurrentInputLanguage = InputLanguage.FromCulture(languageFa);  
                    break;
                case "FA":
                    btn_language.Text = "EN";
                    btn_language.Tooltip = "English (United State)";
                    CultureInfo languageEN = new CultureInfo("en-us");
                    InputLanguage.CurrentInputLanguage = InputLanguage.FromCulture(languageEN); 
                    break;

            }
        }

        private void dataGridView11_MouseDown(object sender, MouseEventArgs e)
        {
            if (MouseButtons == MouseButtons.Right)
            {
                    radialMenu1.Enabled = true;
                    radialMenu1.Visible = true;
                    radialMenu1.Location = new Point(e.X -5, e.Y + dataGridView11.Location.Y - 10);
                    radialopen(radialMenu1);
            }
        }

        private void radialopen(RadialMenu control)
        {
            control.IsOpen = true;
        }

        private void radialMenu1_MenuClosed(object sender, EventArgs e)
        {
            RadialVisible(radialMenu1);
        }

        private void RadialVisible(RadialMenu rad)
        {
            rad.IsOpen = false;
            rad.Visible = false;
            rad.Enabled = false;
        }
        private void DeleteDaro_Click(object sender, EventArgs e)
        {
            txtjamebime.Text =
                (float.Parse(dataGridView11.CurrentRow.Cells[4].Value.ToString()) -
                 float.Parse(txtjamebime.Text.Replace(",", ""))).ToString().Replace("-", "");
            txtsahmebimar.Text =
                (float.Parse(dataGridView11.CurrentRow.Cells[5].Value.ToString()) -
                 float.Parse(txtsahmebimar.Text.Replace(",", ""))).ToString().Replace("-", "");
            txtkolepardakht.Text =
                (float.Parse(dataGridView11.CurrentRow.Cells[6].Value.ToString()) -
                 float.Parse(txtkolepardakht.Text.Replace(",", ""))).ToString().Replace("-", "");

            dataGridView11.Rows.Remove(dataGridView11.CurrentRow);

            for (int j = 0; j < this.dataGridView11.Rows.Count; j++)
            {
                dataGridView11.Rows[j].Cells[0].Value = (j + 1).ToString();
            }
            i = dataGridView11.Rows.Count + 1;
        }

        private void dataGridView11_CellMouseDown(object sender, DataGridViewCellMouseEventArgs e)
        {
            if (e.Button == MouseButtons.Right)
            {
                dataGridView11.CurrentCell = dataGridView11.Rows[e.RowIndex].Cells[e.ColumnIndex];
            }
        }

        private void rad_AddDaro_Click(object sender, EventArgs e)
        {
            SelectDaroAdd(dataGridView11.CurrentRow.Cells[1].Value.ToString());
            DeleteDaro_Click(sender, e);
        }

        private void rad_DeleteNoskhe_Click(object sender, EventArgs e)
        {
            txtjamebime.Text = "0";
            txtsahmebimar.Text = "0";
            txtkolepardakht.Text = "0";
            dataGridView11.Rows.Clear();
        }

        private void showbimeh(string query)
        {
            try
            {
                txtdatesabt.Text = date;
                SqlConnection con = new SqlConnection();
                con.ConnectionString = "server=(local);database=darokhane;trusted_connection=yes";
                SqlDataAdapter da =
                    new SqlDataAdapter(query, con);
                DataTable dt = new DataTable();
                da.Fill(dt);
                dgvBimeh.DataSource = dt;
                dgvBimeh.Columns[0].Width = 67;
                dgvBimeh.Columns[2].Visible = false;
                cmb_EshterakEdit_Bimeh.DataSource = dt;
                cbbimeh.Items.Clear();
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    cbbimeh.Items.Add(dt.Rows[i][1].ToString());
                }
                cbbimeh.SelectedIndex = 0;
            }
            catch
            {
                showElanatNoOptionButton("   خطایی در ارتباط با بانک رخ داده است","red");
            }
            playsoundclick("\\sound\\click.wav");
        }
        private void dgvBimeh_SelectionChanged(object sender, EventArgs e)
        {
            txt_BimehEdit_ID.Text = dgvBimeh.CurrentRow.Cells[0].Value.ToString();
            txt_BimehEdit_Name.Text = dgvBimeh.CurrentRow.Cells[1].Value.ToString();
            if (dgvBimeh.CurrentRow.Cells[2].Value.ToString() == "False")
            {
                btn_BimehEdit_True.Enabled = true;
                btn_BimehEdit_Delete.Enabled = false;
            }
            else
            {
                btn_BimehEdit_True.Enabled = false;
                btn_BimehEdit_Delete.Enabled = true;
            }
        }

        private void ChangColorDataGridDelete(DataGridView control)
        {
            for (int i = 0; i < control.Rows.Count; i++)
            {
                if (control.Rows[i].Cells["State"].Value.ToString() == "False")
                {
                    control.Rows[i].DefaultCellStyle.BackColor = Color.Pink;
                    control.Rows[i].HeaderCell.Value = "حذف";
                }
                else
                {
                    control.Rows[i].HeaderCell.Value = "فعال";
                }  
            }
        }
        private void UpdateAndInsert(SqlCommand com)
        {
            try
            {
                SqlConnection con = new SqlConnection("server=.;database=darokhane;trusted_connection=yes");
                com.Connection = con;
                con.Open();
                com.ExecuteNonQuery();
                con.Close();
            }
            catch (Exception)
            {
                showElanatNoOptionButton("   خطایی در ارتباط با بانک رخ داده است", "red");
            }
        }

        private void btn_BimehEdit_Delete_Click(object sender, EventArgs e)
        {
            SqlCommand com = new SqlCommand();
            com.CommandText = "update bimeh set State=@State where id=@id";
            com.Parameters.AddWithValue("@id", txt_BimehEdit_ID.Text);
            com.Parameters.AddWithValue("@State", false);
            UpdateAndInsert(com);
            showbimeh("select bimeh.id as [کدبیمه],bimeh.bname as [نام بیمه],State from bimeh");
            ChangColorDataGridDelete(dgvBimeh);
        }

        private void btn_BimehEdit_True_Click(object sender, EventArgs e)
        {
            SqlCommand com = new SqlCommand();
            com.CommandText = "update bimeh set State=@State where id=@id";
            com.Parameters.AddWithValue("@id", txt_BimehEdit_ID.Text);
            com.Parameters.AddWithValue("@State", true);
            UpdateAndInsert(com);
            showbimeh("select bimeh.id as [کدبیمه],bimeh.bname as [نام بیمه],State from bimeh");
            ChangColorDataGridDelete(dgvBimeh);
        }

        private void btn_BimehEdit_Name_Click(object sender, EventArgs e)
        {
            SqlCommand com = new SqlCommand();
            com.CommandText = "update bimeh set bname=@bname where id=@id";
            com.Parameters.AddWithValue("@id", txt_BimehEdit_ID.Text);
            com.Parameters.AddWithValue("@bname", txt_BimehEdit_Name.Text);
            UpdateAndInsert(com);
            showeshterakList("select codemeli as [کد ملی],eshterak.bname+' '+eshterak.bfamily as [نام بیمار],eshterak.birthday as [تاریخ تولد],eshterak.datesabt as [تاریخ ثبت],eshterak.etebardate as [اعتبار بیمه],bimeh.bname as [نام بیمه],eshterak.State,eshterak.bname as [نام],eshterak.bfamily as [نام خانوادگی] from eshterak inner join bimeh on bimeh.id=eshterak.nbimeh");
            showbimeh("select bimeh.id as [کدبیمه],bimeh.bname as [نام بیمه],State from bimeh");
        }

        private void btn_EshterakEdit_Delete_Click(object sender, EventArgs e)
        {
            SqlCommand com = new SqlCommand();
            com.CommandText = "update eshterak set State=@State where codemeli=@codemeli";
            com.Parameters.AddWithValue("@codemeli", txt_EshterakEdit_ID.Text);
            com.Parameters.AddWithValue("@State", false);
            UpdateAndInsert(com);
            showeshterakList("select codemeli as [کد ملی],eshterak.bname+' '+eshterak.bfamily as [نام بیمار],eshterak.birthday as [تاریخ تولد],eshterak.datesabt as [تاریخ ثبت],eshterak.etebardate as [اعتبار بیمه],bimeh.bname as [نام بیمه],eshterak.State,eshterak.bname as [نام],eshterak.bfamily as [نام خانوادگی] from eshterak inner join bimeh on bimeh.id=eshterak.nbimeh");
            ChangColorDataGridDelete(dgvEshterak);
        }

        private void btn_EshterakEdit_Edit_Click(object sender, EventArgs e)
        {
            SqlCommand com = new SqlCommand();
            com.CommandText = "update eshterak set bname=@bname,bfamily=@bfamily,birthday=@birthday,nbimeh=@nbimeh,etebardate=@etebardate,datesabt=@datesabt";
            com.CommandText += " where codemeli=@codemeli";
            com.Parameters.AddWithValue("@bname", txt_EshterakEdit_Name.Text);
            com.Parameters.AddWithValue("@bfamily", txt_EshterakEdit_Family.Text);
            com.Parameters.AddWithValue("@birthday", txt_EshterakEdit_Birthday.Text);
            com.Parameters.AddWithValue("@nbimeh", cmb_EshterakEdit_Bimeh.SelectedValue);
            com.Parameters.AddWithValue("@etebardate", txt_EshterakEdit_Etebar.Text);
            com.Parameters.AddWithValue("@datesabt", txt_EshterakEdit_Sabt.Text);
            com.Parameters.AddWithValue("@codemeli", txt_EshterakEdit_ID.Text);
            UpdateAndInsert(com);
            showeshterakList("select codemeli as [کد ملی],eshterak.bname+' '+eshterak.bfamily as [نام بیمار],eshterak.birthday as [تاریخ تولد],eshterak.datesabt as [تاریخ ثبت],eshterak.etebardate as [اعتبار بیمه],bimeh.bname as [نام بیمه],eshterak.State,eshterak.bname as [نام],eshterak.bfamily as [نام خانوادگی] from eshterak inner join bimeh on bimeh.id=eshterak.nbimeh");
            ChangColorDataGridDelete(dgvEshterak);
        }

        private void dgvEshterak_SelectionChanged(object sender, EventArgs e)
        {
            txt_EshterakEdit_ID.Text = dgvEshterak.CurrentRow.Cells[0].Value.ToString();
            txt_EshterakEdit_Name.Text = dgvEshterak.CurrentRow.Cells[7].Value.ToString();
            txt_EshterakEdit_Family.Text = dgvEshterak.CurrentRow.Cells[8].Value.ToString();
            txt_EshterakEdit_Birthday.Text = dgvEshterak.CurrentRow.Cells[2].Value.ToString();
            txt_EshterakEdit_Etebar.Text = dgvEshterak.CurrentRow.Cells[4].Value.ToString();
            txt_EshterakEdit_Sabt.Text = dgvEshterak.CurrentRow.Cells[3].Value.ToString();
            int n = cmb_EshterakEdit_Bimeh.FindString(dgvEshterak.CurrentRow.Cells[5].Value.ToString());
            cmb_EshterakEdit_Bimeh.SelectedIndex = n;
            if (dgvEshterak.CurrentRow.Cells[6].Value.ToString() == "False")
            {
                btn_EshterakEdit_Delete.Enabled = false;
                btn_EshterakEdit_True.Enabled = true;
            }
            else
            {
                btn_EshterakEdit_Delete.Enabled = true;
                btn_EshterakEdit_True.Enabled = false;
            }
        }

        private void dgvEshterak_CellMouseDown(object sender, DataGridViewCellMouseEventArgs e)
        {
            if (e.Button == MouseButtons.Right)
            {
                dgvEshterak.CurrentCell = dgvEshterak.Rows[e.RowIndex].Cells[e.ColumnIndex];
            }
        }

        private void txt_BimehSearch_ID_TextChanged(object sender, EventArgs e)
        {
            if (txt_BimehSearch_ID.Text == string.Empty)
            {
                showbimeh("select bimeh.id as [کدبیمه],bimeh.bname as [نام بیمه],State from bimeh");
                ChangColorDataGridDelete(dgvBimeh);
            }
            else
            {
                showbimeh("select bimeh.id as [کدبیمه],bimeh.bname as [نام بیمه],State from bimeh where bimeh.id=" +
                          txt_BimehSearch_ID.Text);
                ChangColorDataGridDelete(dgvBimeh);
            }
        }

        private void txt_BimehSearch_Name_TextChanged(object sender, EventArgs e)
        {
            if (txt_BimehSearch_Name.Text == string.Empty)
            {
                showbimeh("select bimeh.id as [کدبیمه],bimeh.bname as [نام بیمه],State from bimeh");
                ChangColorDataGridDelete(dgvBimeh);
            }
            else
            {
                showbimeh("select bimeh.id as [کدبیمه],bimeh.bname as [نام بیمه],State from bimeh where bimeh.bname=N'" + txt_BimehSearch_Name.Text+"'");
                ChangColorDataGridDelete(dgvBimeh);
            }
        }

        private void buttonX3_Click(object sender, EventArgs e)
        {

            SqlConnection con = new SqlConnection("server=(local);database=darokhane;trusted_connection=yes");
            SqlCommand com = new SqlCommand();
            com.Connection = con;
            com.CommandText =
                "select codemeli as [کد ملی],eshterak.bname+' '+eshterak.bfamily as [نام بیمار],eshterak.birthday as [تاریخ تولد],eshterak.datesabt as [تاریخ ثبت],eshterak.etebardate as [اعتبار بیمه],bimeh.bname as [نام بیمه],eshterak.State,eshterak.bname as [نام],eshterak.bfamily as [نام خانوادگی] from eshterak inner join bimeh on bimeh.id=eshterak.nbimeh where eshterak.codemeli != '%'";
            if (txt_EshterakSearch_CodeMeli.Text != string.Empty)
                com.CommandText += " and eshterak.codemeli = N'" + txt_EshterakSearch_CodeMeli.Text + "'";

            if (txt_EshterakSearch_CodeBimeh.Text != string.Empty)
                com.CommandText += " and nbimeh = N'" + txt_EshterakSearch_CodeBimeh.Text + "'";

            if (txt_EshterakSearch_Name.Text != string.Empty)
                com.CommandText += " and eshterak.bname like N'%" + txt_EshterakSearch_Name.Text + "%'";

            if (txt_EshterakSearch_Family.Text != string.Empty)
                com.CommandText += " and eshterak.bfamily like N'%" + txt_EshterakSearch_Family.Text + "%'";

            if (DateTrust(txt_EshterakSearch_Birthday.Text) == true)
                com.CommandText += " and eshterak.birthday like N'%" + txt_EshterakSearch_Birthday.Text + "%'";
            else
            {
                string[] split = txt_EshterakSearch_Birthday.Text.Split(' ');
                if (split.Length > -1 && split.Length < 7)
                    showElanatNoOptionButton("   فرمت تاریخ تولد وارد شده صحیح نمی باشد و به همین دلیل در جستجو استفاده نشد. لصفا تاریخ را بصورت 1369/04/28 وارد کنید", "blue");
            }

            if (DateTrust(txt_EshterakSearch_Sabt.Text) == true)
                com.CommandText += " and eshterak.birthday like N'%" + txt_EshterakSearch_Sabt.Text + "%'";
            else
            {
                string[] split = txt_EshterakSearch_Sabt.Text.Split(' ');
                if (split.Length > -1 && split.Length < 7)
                    showElanatNoOptionButton("   فرمت تاریخ ثبت وارد شده صحیح نمی باشد و به همین دلیل در جستجو استفاده نشد. لصفا تاریخ را بصورت 1369/04/28 وارد کنید", "blue");
            }

                
            SqlDataAdapter da = new SqlDataAdapter(com);
            DataTable dt = new DataTable();
            da.Fill(dt);
            dgvEshterak.DataSource = dt;
            ChangColorDataGridDelete(dgvEshterak);
        }

        void TextboxesOnlyNumber_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == 8) { e.Handled = false; return; }
            if (e.KeyChar < 48 || e.KeyChar > 57 || e.KeyChar == 32) { e.Handled = true; }
        }

        void TextboxesOnlyString_KeyPress(object sender, KeyPressEventArgs e)
        {
            e.Handled = char.IsDigit(e.KeyChar);
        }

        private void txt_EshterakSearch_CodeMeli_KeyPress(object sender, KeyPressEventArgs e)
        {
            TextboxesOnlyNumber_KeyPress(sender, e);
        }

        private void txt_EshterakSearch_CodeBimeh_KeyPress(object sender, KeyPressEventArgs e)
        {
            TextboxesOnlyNumber_KeyPress(sender, e);
        }

        private void txt_EshterakSearch_Name_KeyPress(object sender, KeyPressEventArgs e)
        {
             TextboxesOnlyString_KeyPress(sender, e);
        }

        private void txt_EshterakSearch_Family_KeyPress(object sender, KeyPressEventArgs e)
        {
             TextboxesOnlyString_KeyPress(sender, e);
        }

        private void txt_EshterakEdit_Name_KeyPress(object sender, KeyPressEventArgs e)
        {
             TextboxesOnlyString_KeyPress(sender, e);
        }

        private void txt_EshterakEdit_Family_KeyPress(object sender, KeyPressEventArgs e)
        {
            TextboxesOnlyString_KeyPress(sender, e);
        }

        private void txt_BimehEdit_Name_KeyPress(object sender, KeyPressEventArgs e)
        {
            TextboxesOnlyString_KeyPress(sender, e);
        }

        private void txt_EshterakSearch_Birthday_KeyPress(object sender, KeyPressEventArgs e)
        {
            TextboxesOnlyNumber_KeyPress(sender, e);
        }

        private void txt_EshterakSearch_Sabt_KeyPress(object sender, KeyPressEventArgs e)
        {
            TextboxesOnlyNumber_KeyPress(sender, e);
        }

        private void txt_EshterakEdit_Birthday_KeyPress(object sender, KeyPressEventArgs e)
        {
            TextboxesOnlyNumber_KeyPress(sender, e);
        }

        private void txt_EshterakEdit_Etebar_KeyPress(object sender, KeyPressEventArgs e)
        {
            TextboxesOnlyNumber_KeyPress(sender, e);
        }

        private void txt_EshterakEdit_Sabt_KeyPress(object sender, KeyPressEventArgs e)
        {
            TextboxesOnlyNumber_KeyPress(sender, e);
        }

        private void txt_BimehSearch_ID_KeyPress(object sender, KeyPressEventArgs e)
        {
            TextboxesOnlyNumber_KeyPress(sender, e);
        }

        private void txt_BimehSearch_Name_KeyPress(object sender, KeyPressEventArgs e)
        {
            TextboxesOnlyString_KeyPress(sender, e);
        }

        private void txt_EshterakSearch_CodeMeli_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                buttonX3_Click(sender, e);
            }
        }

        private void txt_EshterakSearch_CodeBimeh_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                buttonX3_Click(sender, e);
            }
        }

        private void txt_EshterakSearch_Name_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                buttonX3_Click(sender, e);
            }
        }

        private void txt_EshterakSearch_Family_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                buttonX3_Click(sender, e);
            }
        }

        private void txt_EshterakSearch_Birthday_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                buttonX3_Click(sender, e);
            }
        }

        private void txt_EshterakSearch_Sabt_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                buttonX3_Click(sender, e);
            }
        }

        private void dgvEshterak_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Delete)
            {
                btn_EshterakEdit_Delete_Click(sender, e);
            }
        }

        private void dgvBimeh_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Delete)
            {
                btn_BimehEdit_Delete_Click(sender, e);
            }
        }

        private void btn_EshterakEdit_True_Click(object sender, EventArgs e)
        {
            SqlCommand com = new SqlCommand();
            com.CommandText = "update eshterak set State=@State where codemeli=@codemeli";
            com.Parameters.AddWithValue("@codemeli", txt_EshterakEdit_ID.Text);
            com.Parameters.AddWithValue("@State", true);
            UpdateAndInsert(com);
            showeshterakList("select codemeli as [کد ملی],eshterak.bname+' '+eshterak.bfamily as [نام بیمار],eshterak.birthday as [تاریخ تولد],eshterak.datesabt as [تاریخ ثبت],eshterak.etebardate as [اعتبار بیمه],bimeh.bname as [نام بیمه],eshterak.State,eshterak.bname as [نام],eshterak.bfamily as [نام خانوادگی] from eshterak inner join bimeh on bimeh.id=eshterak.nbimeh");
            ChangColorDataGridDelete(dgvEshterak);
        }

        private void txteditplus_TextChanged(object sender, EventArgs e)
        {
            if (txteditplus.Text == string.Empty)
                txteditplus.Text = "0";
        }

        private void txteditid_KeyPress(object sender, KeyPressEventArgs e)
        {
            TextboxesOnlyNumber_KeyPress(sender, e);
        }

        private void txteditplus_KeyPress(object sender, KeyPressEventArgs e)
        {
            TextboxesOnlyNumber_KeyPress(sender, e);
        }

        private void txtedittolid_KeyPress(object sender, KeyPressEventArgs e)
        {
            TextboxesOnlyNumber_KeyPress(sender, e);
        }

        private void txteditengheza_KeyPress(object sender, KeyPressEventArgs e)
        {
            TextboxesOnlyNumber_KeyPress(sender, e);
        }

        private void buttonX8_Click(object sender, EventArgs e)
        {
            SqlConnection con = new SqlConnection("server=.;database=darokhane;trusted_connection=yes");
            SqlCommand com = new SqlCommand("delete from ListeBuy where iddaro='"+txt_ListBuy_IdDaro.Text+"' and [Subject]='"+txt_ListBuy_Subject.Text+"'", con);
            con.Open();
            com.ExecuteNonQuery();
            con.Close();
            if (lbl_ListeDaroAndListeBuyState.Text == "Buy1")
                btnsearchdarodarhaleetmam_Click(sender, e);
            else
            {
                btnsearchdaroend_Click(sender, e);
            }
        }

        private void switchButton1_ValueChanged(object sender, EventArgs e)
        {

        }

        private void dgvAccount_SelectionChanged(object sender, EventArgs e)
        {
            txt_account_Edit_UserName.Text = dgvAccount.CurrentRow.Cells[1].Value.ToString();
            txt_account_Edit_NameAndFamily.Text = dgvAccount.CurrentRow.Cells[0].Value.ToString();
            txt_account_Edit_PasswordOld.Text = dgvAccount.CurrentRow.Cells[2].Value.ToString();
            account_Edit_Rating.Rating = Convert.ToInt16(dgvAccount.CurrentRow.Cells[3].Value.ToString());
            sw1_Edit.Value = Convert.ToBoolean(dgvAccount.CurrentRow.Cells[4].Value.ToString());
            sw2_Edit.Value = Convert.ToBoolean(dgvAccount.CurrentRow.Cells[5].Value.ToString());
            sw3_Edit.Value = Convert.ToBoolean(dgvAccount.CurrentRow.Cells[6].Value.ToString());
            sw4_Edit.Value = Convert.ToBoolean(dgvAccount.CurrentRow.Cells[7].Value.ToString());
            sw5_Edit.Value = Convert.ToBoolean(dgvAccount.CurrentRow.Cells[8].Value.ToString());
            sw6_Edit.Value = Convert.ToBoolean(dgvAccount.CurrentRow.Cells[9].Value.ToString());
            if (dgvAccount.CurrentRow.Cells[10].Value.ToString() == "False")
            {
                btn_Account_Delete.Enabled = false;
                btn_Account_True.Enabled = true;
            }
            else
            {
                btn_Account_Delete.Enabled = true;
                btn_Account_True.Enabled = false;
            }
        }

        private void btn_Account_Edit_Click(object sender, EventArgs e)
        {
            SqlCommand com = new SqlCommand();
            com.CommandText =
                "update accont set upass=@upass,rating=@rating,cadddaro=@cadddaro,chart=@chart,cadduser=@cadduser,caddpezeshk=@caddpezeshk,cnezarat=@cnezarat,caddeshterak=@caddeshterak,NameFamily=@NameFamily where uname=@uname";
            com.Parameters.AddWithValue("@uname", txt_account_Edit_UserName.Text);
            if(txt_account_Edit_PasswordNew.Text!=string.Empty)
                com.Parameters.AddWithValue("@upass", txt_account_Edit_PasswordNew.Text);
            else
            {
                com.Parameters.AddWithValue("@upass", txt_account_Edit_PasswordOld.Text);
            }
            com.Parameters.AddWithValue("@rating", account_Edit_Rating.RatingValue);
            com.Parameters.AddWithValue("@cadddaro", Convert.ToBoolean(sw1_Edit.Value).ToString());
            com.Parameters.AddWithValue("@chart", Convert.ToBoolean(sw2_Edit.Value).ToString());
            com.Parameters.AddWithValue("@cadduser", Convert.ToBoolean(sw3_Edit.Value).ToString());
            com.Parameters.AddWithValue("@caddpezeshk", Convert.ToBoolean(sw4_Edit.Value).ToString());
            com.Parameters.AddWithValue("@cnezarat", Convert.ToBoolean(sw5_Edit.Value).ToString());
            com.Parameters.AddWithValue("@caddeshterak", Convert.ToBoolean(sw6_Edit.Value).ToString());
            com.Parameters.AddWithValue("@NameFamily", txt_account_Edit_NameAndFamily.Text);
            UpdateAndInsert(com);
            buttonX10_Click(sender, e);
            playsoundclick("\\sound\\login.wav");
        }

        private void btn_Account_Search_Click(object sender, EventArgs e)
        {
            SqlConnection con = new SqlConnection("server=.;database=darokhane;trusted_connection=yes");
            SqlCommand com = new SqlCommand();
            com.CommandText = "select NameFamily as [نام حقیقی],uname as [نام کاربری],upass as [رمز عبور],rating as [دسترسی],cadddaro as [ویرایش دارو],chart as [نمودار],cadduser as [کاربر],caddpezeshk as [ثبت پزشک],cnezarat as [نظارت],caddeshterak as [مشترکین],State from accont where uname like '%%'";
            if (txt_account_Search_UserName.Text != string.Empty)
                com.CommandText += " and ''";

            if (txt_account_Search_UserName.Text != string.Empty)
                com.CommandText += " and uname like '%"+txt_account_Search_UserName.Text+"%'";

            if (txt_account_Search_NameAndFamily.Text != string.Empty)
                com.CommandText += " and NameFamily like '%"+txt_account_Search_NameAndFamily.Text+"%'";

            if (check_account_Search_AddAccount.Checked == true)
                com.CommandText += " and cadduser ='True'";
            if (check_account_Search_Chart.Checked == true)
                com.CommandText += " and chart ='True'";
            if (check_account_Search_Daro.Checked == true)
                com.CommandText += " and cadddaro ='True'";
            if (check_account_Search_Eshterak.Checked == true)
                com.CommandText += " and caddeshterak ='True'";
            if (check_account_Search_Nezarat.Checked == true)
                com.CommandText += " and cnezarat ='True'";
            if (check_account_Search_Pezeshk.Checked == true)
                com.CommandText += " and caddpezeshk ='True'";

            com.Connection = con;
            SqlDataAdapter da = new SqlDataAdapter();
            da.SelectCommand = com;
            DataTable dt = new DataTable();
            da.Fill(dt);
            dgvAccount.DataSource = dt;
            ChangColorDataGridDelete(dgvAccount);
        }

        private void buttonX10_Click(object sender, EventArgs e)
        {
            ShowAccountList("select NameFamily as [نام حقیقی],uname as [نام کاربری],upass as [رمز عبور],rating as [دسترسی],cadddaro as [ویرایش دارو],chart as [نمودار],cadduser as [کاربر],caddpezeshk as [ثبت پزشک],cnezarat as [نظارت],caddeshterak as [مشترکین],State from accont");
            ChangColorDataGridDelete(dgvAccount);
        }

        private void buttonItem5_Click(object sender, EventArgs e)
        {
            txtedituser.Text = login.uname;
        }

        private void labelItem40_Click(object sender, EventArgs e)
        {

        }

        private void btn_Account_Delete_Click(object sender, EventArgs e)
        {
            SqlCommand com = new SqlCommand();
            com.CommandText =
                "update accont set State=@State where uname=@uname";
            com.Parameters.AddWithValue("@State", false);
            com.Parameters.AddWithValue("@uname", txt_account_Edit_UserName.Text);
            UpdateAndInsert(com);
            playsoundclick("\\sound\\login.wav");
            buttonX10_Click(sender, e);
        }

        private void btn_Account_True_Click(object sender, EventArgs e)
        {
            SqlCommand com = new SqlCommand();
            com.CommandText =
                "update accont set State=@State where uname=@uname";
            com.Parameters.AddWithValue("@State", true);
            com.Parameters.AddWithValue("@uname", txt_account_Edit_UserName.Text);
            UpdateAndInsert(com);
            playsoundclick("\\sound\\login.wav");
            buttonX10_Click(sender, e);
        }

        private void btn_New_Noskhe_Click(object sender, EventArgs e)
        {
            if (dataGridView11.RowCount > 0)
            {
                DialogResult res = MessageBox.Show("یک نسخه ثبت نشده وجود دارد. آیا اطمینان به کنسل کردن نسخه دارید؟", "!!!هشدار", MessageBoxButtons.YesNo, MessageBoxIcon.Question,
                    MessageBoxDefaultButton.Button1);
                if (res == DialogResult.Yes)
                    New_Noskhe_Method();
            }
            else
            {
                New_Noskhe_Method();
            }
            
        }

        private void New_Noskhe_Method()
        {
            lblstareshterak.Visible = true;
            lblcheckvalueseshterak.Text = "0";
            cmbsearch.Text = "";
            txtsearchdaro.Items.Clear();
            foreach (Control control in grbhome.Controls)
                if (control is TextBox)
                {
                    control.Text = "";
                }
            foreach (Control control in panel2.Controls)
                if (control is TextBox)
                {
                    control.Text = "";
                }
            txtjamebime.Text = "0";
            txtsahmebimar.Text = "0";
            txtkolepardakht.Text = "0";
            txttedadekol.Text = "0";
            dataGridView11.Rows.Clear();
            btninsert.Enabled = false;
            btnsabtenoskhe.Enabled = false;
            btnmarjoeekol.Enabled = false;
            txteshterak.ReadOnly = false;
            txtserial.BackColor = grbEditDaro.BackColor;
        }
        private void txtnewpid_KeyPress(object sender, KeyPressEventArgs e)
        {
            TextboxesOnlyNumber_KeyPress(sender, e);
        }

        private void txtnewpname_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                txtnewptakhasos.Focus();
            } //enter
            if (e.KeyCode == Keys.Down)
            {
                txtnewptakhasos.Focus();
            } //paein
            if (e.KeyCode == Keys.Up)
            {
                txtnewpid.Focus();
            } //chap
            if (e.KeyCode == Keys.Right)
            {
                txtpidedit.Focus();
            } //bala
        }

        private void buttonItem13_Click(object sender, EventArgs e)
        {
            try
            {
                SqlConnection con = new SqlConnection("server=.;database=darokhane;trusted_connection=yes");
                SqlCommand com = new SqlCommand();
                com.CommandText = "update franshiz set franshiz=@franshiz where idbimeh=@idbimeh and iddaro=@iddaro";
                com.Parameters.AddWithValue("@idbimeh", txtfranshizidbimeh.Text);
                com.Parameters.AddWithValue("@iddaro", txtfranshiziddaro.Text);
                com.Parameters.AddWithValue("@franshiz", txtfranshizdarsad.Text);
                com.Connection = con;
                con.Open();
                com.ExecuteNonQuery();
                con.Close();
                string message = "{0} در صد تخفبف برای دارویی با کد {1} در {2} با موفقیت ویرایش شد";
                message = string.Format(message, txtfranshizdarsad.Text, txtfranshiziddaro.Text, lblfranshizidbimeh.Text);
                showElanatNoOptionButton(message, "green");
                ///////////////
                lblfranshizmessage.Text = "با موفقیت ویرایش شد";
            }
            catch (Exception)
            {
                /////////////////////////
                showElanatNoOptionButton(
                    "   این دارو با کد بیمه گر در سیستم ثبت نشده است. برای ثبت درصد فرانشیز روی دکمه ثبت کن کلیک کنید",
                    "red");
                /////////////////////////
                lblfranshizmessage.Text = "این دارو با کد بیمه گر قبلا در سیستم ثبت نشده است";
            }
        }

        private void New_Noskhe_Click(object sender, EventArgs e)
        {
            showhome();
            
                    btn_New_Noskhe_Click(sender, e);
            
        }

        private void txtcodedaro_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                txtlname.Focus();
            }
            if (e.KeyCode == Keys.Left)
            {
                txttarkibat.Focus();
            }
            if (e.KeyCode == Keys.Down)
            {
                txtlname.Focus();
            }
        }

        private void txtlname_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                txtfname.Focus();
            }
            if (e.KeyCode == Keys.Left)
            {
                txttolid.Focus();
            }
            if (e.KeyCode == Keys.Down)
            {
                txtfname.Focus();
            }
            if (e.KeyCode == Keys.Up)
            {
                txtcodedaro.Focus();
            }
        }

        private void txtfname_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                txttarkibat.Focus();
            }
            if (e.KeyCode == Keys.Left)
            {
                txtengheza.Focus();
            }
            if (e.KeyCode == Keys.Down)
            {
                txttarkibat.Focus();
            }
            if (e.KeyCode == Keys.Up)
            {
                txtlname.Focus();
            }
        }

        private void txttarkibat_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                txttolid.Focus();
            }
            if (e.KeyCode == Keys.Left)
            {
                txtgheymat.Focus();
            }
            if (e.KeyCode == Keys.Right)
            {
                txtcodedaro.Focus();
            }
            if (e.KeyCode == Keys.Down)
            {
                txttolid.Focus();
            }
            if (e.KeyCode == Keys.Up)
            {
                txtfname.Focus();
            }
        }

        private void txttolid_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                txtengheza.Focus();
            }
            if (e.KeyCode == Keys.Left)
            {
                txtanbar.Focus();
            }
            if (e.KeyCode == Keys.Right)
            {
                txtlname.Focus();
            }
            if (e.KeyCode == Keys.Down)
            {
                txtengheza.Focus();
            }
            if (e.KeyCode == Keys.Up)
            {
                txttarkibat.Focus();
            }
        }

        private void txtengheza_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                txtgheymat.Focus();
            }
            if (e.KeyCode == Keys.Left)
            {
                txtghafase.Focus();
            }
            if (e.KeyCode == Keys.Right)
            {
                txtfname.Focus();
            }
            if (e.KeyCode == Keys.Down)
            {
                txtgheymat.Focus();
            }
            if (e.KeyCode == Keys.Up)
            {
                txttolid.Focus();
            }
        }

        private void txtgheymat_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                txtanbar.Focus();
            }
            if (e.KeyCode == Keys.Left)
            {
                txtcompony.Focus();
            }
            if (e.KeyCode == Keys.Right)
            {
                txttarkibat.Focus();
            }
            if (e.KeyCode == Keys.Down)
            {
                txtanbar.Focus();
            }
            if (e.KeyCode == Keys.Up)
            {
                txtengheza.Focus();
            }
        }

        private void txtanbar_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                txtghafase.Focus();
            }
            if (e.KeyCode == Keys.Left)
            {
                txttedadeavalie.Focus();
            }
            if (e.KeyCode == Keys.Right)
            {
                txttolid.Focus();
            }
            if (e.KeyCode == Keys.Down)
            {
                txtghafase.Focus();
            }
            if (e.KeyCode == Keys.Up)
            {
                txtgheymat.Focus();
            }
        }

        private void txtghafase_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                txtcompony.Focus();
            }
            if (e.KeyCode == Keys.Left)
            {
                txtcompony.Focus();
            }
            if (e.KeyCode == Keys.Right)
            {
                txtengheza.Focus();
            }
            if (e.KeyCode == Keys.Down)
            {
                txtcompony.Focus();
            }
            if (e.KeyCode == Keys.Up)
            {
                txtanbar.Focus();
            }
        }

        private void txtcompony_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                txttedadeavalie.Focus();
            }
            if (e.KeyCode == Keys.Left)
            {
                txtfranshizidbimeh.Focus();
            }
            if (e.KeyCode == Keys.Right)
            {
                txtgheymat.Focus();
            }
            if (e.KeyCode == Keys.Down)
            {
                txttedadeavalie.Focus();
            }
            if (e.KeyCode == Keys.Up)
            {
                txtghafase.Focus();
            }
        }

        private void txttedadeavalie_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                btnadddaro_Click(sender, e);
            }
            if (e.KeyCode == Keys.Left)
            {
                txtfranshiziddaro.Focus();
            }
            if (e.KeyCode == Keys.Right)
            {
                txtanbar.Focus();
            }
            if (e.KeyCode == Keys.Down)
            {
                txtfranshizidbimeh.Focus();
            }
            if (e.KeyCode == Keys.Up)
            {
                txtcompony.Focus();
            }
        }

        private void txtfranshizidbimeh_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                txtfranshiziddaro.Focus();
            }
            if (e.KeyCode == Keys.Right)
            {
                txtcompony.Focus();
            }
            if (e.KeyCode == Keys.Down)
            {
                txtfranshiziddaro.Focus();
            }
            if (e.KeyCode == Keys.Up)
            {
                txttedadeavalie.Focus();
            }
        }

        private void txtfranshiziddaro_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                txtfranshizdarsad.Focus();
            }
            if (e.KeyCode == Keys.Right)
            {
                txttedadeavalie.Focus();
            }
            if (e.KeyCode == Keys.Down)
            {
                txtfranshizdarsad.Focus();
            }
            if (e.KeyCode == Keys.Up)
            {
                txtfranshizidbimeh.Focus();
            }
        }

        private void txtfranshizdarsad_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                btninsertfranshiz_Click(sender, e);
            }
            if (e.KeyCode == Keys.Right)
            {
                buttonItem13.Focus();
            }
            if (e.KeyCode == Keys.Down)
            {
                btninsertfranshiz.Focus();
            }
            if (e.KeyCode == Keys.Up)
            {
                buttonItem13.Focus();
            }
        }

        private void txtuser_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                txtpassword.Focus();
            }
            if (e.KeyCode == Keys.Down)
            {
                txtpassword.Focus();
            }
        }

        private void txtpassword_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                txtkname.Focus();
            }
            if (e.KeyCode == Keys.Up)
            {
                txtuser.Focus();
            }
            if (e.KeyCode == Keys.Down)
            {
                txtkname.Focus();
            }
        }

        private void txtkname_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Up)
            {
                txtpassword.Focus();
            }
        }

        private void dataGridViewX3_SelectionChanged(object sender, EventArgs e)
        {
            if (dataGridViewX3.Rows.Count > 0)
            {
                SqlDataAdapter da =
                    new SqlDataAdapter(
                        "select * from eshterak where codemeli='" + dataGridViewX3.CurrentRow.Cells[1].Value + "'",
                        "server=(local);database=darokhane;trusted_connection=yes");

                DataSet dt = new DataSet();
                da.Fill(dt);
                txtnoskhecode.Text = dataGridViewX3.CurrentRow.Cells[0].Value.ToString();
                txtnoskheidbimar.Text = dt.Tables[0].Rows[0][0].ToString();
                txtnoskhenamefull.Text = dt.Tables[0].Rows[0][1].ToString() + " " + dt.Tables[0].Rows[0][2].ToString();
                SearchAsCodeNoskhe(dataGridViewX3.CurrentRow.Cells[0].Value.ToString());
                txtfulldate.Text = dataGridViewX3.CurrentRow.Cells[2].Value.ToString();
                txtnoskhemablaghekol.Text = dataGridViewX3.CurrentRow.Cells[3].Value.ToString();
                txtnoskhefranshizkol.Text = dataGridViewX3.CurrentRow.Cells[4].Value.ToString();
                txtnoskhemablaghepardakhti.Text = dataGridViewX3.CurrentRow.Cells[5].Value.ToString();
                txtnoskhetedad.Text = dataGridViewX3.Rows.Count.ToString();
            }
        }

        private void txttedad_TextChanged(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(txttedad.Text) && (int.Parse(txttedad.Text) > int.Parse(txtmojodi.Text)))
                btninsert.Enabled = false;
            else
            {
                btninsert.Enabled = true;
            }
        }

        private void txtbimehcode_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                txtbimehname.Focus();
            }
            if (e.KeyCode == Keys.Down)
            {
                txtbimehname.Focus();
            }
        }

        private void txtbimehname_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                btnaddbimeh_Click(sender, e);
            }
            if (e.KeyCode == Keys.Up)
            {
                txtbimehcode.Focus();
            }
        }

        private void buttonItem18_Click(object sender, EventArgs e)
        {
            GroupSearchDaroShowAndHide(true);
            lbl_ListeDaroAndListeBuyState.Text = "Daro";
            searchdaro(
                "select id as [کد دارو],lname as [نام لاتین],fname as [نام فارسی],tolid as [تاریخ تولید],engheza as [تاریخ انقضا],gheymat as [قیمت],anbar as [شماره انبار],ghafase as [شماره قفسه],tarkibat as [طریقه مصرف],compony as [تولید کننده],tedad as [تعداد], case  when State = 0 then N'نا موجود' when State = 1 then  N'موجود' End as Result from home where State='False' order by lname");
            playsoundclick("\\sound\\click.wav");
            dgsearchdaro.RowHeadersWidth = 40;
            grbEditDaro.Visible = true;
            grbListBuy.Visible = false;
        }

        private void labelItem70_Click(object sender, EventArgs e)
        {

        }

        private void buttonItem21_Click(object sender, EventArgs e)
        {
            PersianCalendar pc = new PersianCalendar();
            DateTime dtnext;
            dtnext = DateTime.Now;
            dtnext = dtnext.AddDays(Convert.ToDouble(txt_Engheza_Day.Text));
            engheza = pc.GetYear(dtnext).ToString("D2") + "/" + pc.GetMonth(dtnext).ToString("D2") + "/" +
                      pc.GetDayOfMonth(dtnext).ToString("D2");
            ListeEngheza();
        }

        private void buttonItem22_Click(object sender, EventArgs e)
        {
            PersianCalendar pc = new PersianCalendar();
            DateTime dtnext;
            dtnext = DateTime.Now;
            dtnext = dtnext.AddMonths(Convert.ToInt32(txt_Engheza_Month.Text));
            engheza = pc.GetYear(dtnext).ToString("D2") + "/" + pc.GetMonth(dtnext).ToString("D2") + "/" +
                      pc.GetDayOfMonth(dtnext).ToString("D2");
            ListeEngheza();
        }

        private void buttonItem23_Click(object sender, EventArgs e)
        {
            PersianCalendar pc = new PersianCalendar();
            DateTime dtnext;
            dtnext = DateTime.Now;
            dtnext = dtnext.AddYears(Convert.ToInt32(txt_Engheza_Year.Text));
            engheza = pc.GetYear(dtnext).ToString("D2") + "/" + pc.GetMonth(dtnext).ToString("D2") + "/" +
                      pc.GetDayOfMonth(dtnext).ToString("D2");
            ListeEngheza();
        }

        private void buttonX4_Click(object sender, EventArgs e)
        {
            SelectReportMony("select codenoskhebimar as [codenoskhebimar],sum(gheymat) as [gheymatKol],sum(franshiz) as [franshiz],sum(gheymatepardakhti) as [gheymatePardakhti] from noskhe where DateSabteNoskhe like '"+txt_ReportMony_Years.Text+"%' group by codenoskhebimar");
            dgvReportMony.Columns[0].HeaderText = "کد نسخه بیمار";
            dgvReportMony.Columns[0].Width = 150;
            dgvReportMony.Columns[1].HeaderText = "قیمت کل نسخه";
            dgvReportMony.Columns[1].Width = 150;
            dgvReportMony.Columns[2].HeaderText = "درصد فرانشیز کل نسخه";
            dgvReportMony.Columns[2].Width = 160;

        }

        private void SelectReportMony(string query)
        {
            SqlConnection con = new SqlConnection("server=.;database=darokhane;trusted_connection=yes");
            SqlDataAdapter da = new SqlDataAdapter(query,con);
            DataTable dt = new DataTable();
            da.Fill(dt);
            dgvReportMony.DataSource = dt;
            SumReportMony();
        }

        private void buttonItem24_Click(object sender, EventArgs e)
        {
            if (rating.Rating == 5)
            {
                ShowReportMony();
                buttonX12_Click(sender, e);
            }
            else
            {
                showElanatNoOptionButton("   این قسمت برای کاربرانی که سطح دسترسی آنها پنج ستاره است قابل دسترس است","red");
            }
        }

        private void buttonX7_Click(object sender, EventArgs e)
        {
            SelectReportMony("select codenoskhebimar as [codenoskhebimar],sum(gheymat) as [gheymatKol],sum(franshiz) as [franshiz],sum(gheymatepardakhti) as [gheymatePardakhti] from noskhe where DateSabteNoskhe like '" + txt_ReportMony_Month.Text + "%' group by codenoskhebimar");
            dgvReportMony.Columns[0].HeaderText = "کد نسخه بیمار";
            dgvReportMony.Columns[0].Width = 150;
            dgvReportMony.Columns[1].HeaderText = "قیمت کل نسخه";
            dgvReportMony.Columns[1].Width = 150;
            dgvReportMony.Columns[2].HeaderText = "درصد فرانشیز کل نسخه";
            dgvReportMony.Columns[2].Width = 160;
        }

        private void buttonX9_Click(object sender, EventArgs e)
        {
            SelectReportMony("select codenoskhebimar as [codenoskhebimar],sum(gheymat) as [gheymatKol],sum(franshiz) as [franshiz],sum(gheymatepardakhti) as [gheymatePardakhti] from noskhe where DateSabteNoskhe like '" + txt_ReportMony_Day.Text + "' group by codenoskhebimar");
            dgvReportMony.Columns[0].HeaderText = "کد نسخه بیمار";
            dgvReportMony.Columns[0].Width = 150;
            dgvReportMony.Columns[1].HeaderText = "قیمت کل نسخه";
            dgvReportMony.Columns[1].Width = 150;
            dgvReportMony.Columns[2].HeaderText = "درصد فرانشیز کل نسخه";
            dgvReportMony.Columns[2].Width = 160;
        }

        private void buttonX11_Click(object sender, EventArgs e)
        {
            string text1 = txt_ReportMony_DaroID.Text;
            int num1;
            bool res = int.TryParse(text1, out num1);
            if (string.IsNullOrEmpty(text1))
            {
                showElanatNoOptionButton("   لطفا فیلد مورد نظر را پر کنید", "red");
            }
            else
            {
                if (res == false)
                {
                    string example = txt_ReportMony_DaroID.Text;

                    string[] array = { example };
                    StringBuilder sb = new StringBuilder();
                    foreach (string str in array)
                    {
                        if (System.Text.RegularExpressions.Regex.IsMatch(str, @"^[a-z-A-Z-0-9]+$"))
                            SelectReportMony("select home.lname,noskhe.gheymat,noskhe.franshiz,noskhe.gheymatepardakhti from noskhe inner join home on home.id=noskhe.iddaro where home.lname='" + txt_ReportMony_DaroID.Text + "'");
                        else
                            if (System.Text.RegularExpressions.Regex.IsMatch(str, @"^[\u0600-\u06FF-0-9]+$"))
                                SelectReportMony("select home.fname,noskhe.gheymat,noskhe.franshiz,noskhe.gheymatepardakhti from noskhe inner join home on home.id=noskhe.iddaro where home.fname=N'" + txt_ReportMony_DaroID.Text + "'");
                    }
                }
                else
                {
                    SelectReportMony("select home.fname,noskhe.gheymat,noskhe.franshiz,noskhe.gheymatepardakhti from noskhe inner join home on home.id=noskhe.iddaro where iddaro='" + txt_ReportMony_DaroID.Text + "'");
                }
                dgvReportMony.Columns[0].HeaderText = "نام دارو";
                dgvReportMony.Columns[0].Width = 150;
                dgvReportMony.Columns[1].HeaderText = "قیمت کل";
                dgvReportMony.Columns[1].Width = 150;
                dgvReportMony.Columns[2].HeaderText = "قیمت پرداختی";
                dgvReportMony.Columns[0].Width = 160;
            }
        }

        private void buttonX12_Click(object sender, EventArgs e)
        {
            SelectReportMony("select codenoskhebimar,sum(gheymat) as gheymatKol,sum(franshiz) as franshiz,sum(gheymatepardakhti) as gheymatePardakhti from noskhe where DateSabteNoskhe like '" + lbldatehead.Text + "' group by codenoskhebimar");
            dgvReportMony.Columns[0].HeaderText = "کد نسخه بیمار";
            dgvReportMony.Columns[0].Width = 150;
            dgvReportMony.Columns[1].HeaderText = "قیمت کل نسخه";
            dgvReportMony.Columns[1].Width = 150;
            dgvReportMony.Columns[2].HeaderText = "درصد فرانشیز کل نسخه";
            dgvReportMony.Columns[2].Width = 160;
        }
        private void SumReportMony()
        {
            double kol=0;
            double franshiz=0;
            double pardakhti=0;
            for (int i = 0; i < dgvReportMony.Rows.Count; i++)
            {
                kol += Convert.ToDouble(dgvReportMony.Rows[i].Cells[1].Value.ToString());
                franshiz += Convert.ToDouble(dgvReportMony.Rows[i].Cells[2].Value.ToString());
                pardakhti += Convert.ToDouble(dgvReportMony.Rows[i].Cells[3].Value.ToString());
            }
            txt_ReportMony_Sumkol.Text = kol.ToString();
            txt_ReportMony_Franshiz.Text = franshiz.ToString();
            txt_ReportMony_Pardakhti.Text = pardakhti.ToString();
        }
        private void txt_ReportMony_Sumkol_TextChanged(object sender, EventArgs e)
        {
            if (txt_ReportMony_Sumkol.Text == "" || txt_ReportMony_Sumkol.Text == @"0") return;
            decimal price;
            price = decimal.Parse(txt_ReportMony_Sumkol.Text, System.Globalization.NumberStyles.Currency);
            txt_ReportMony_Sumkol.Text = price.ToString("#,#");
            txt_ReportMony_Sumkol.SelectionStart = txt_ReportMony_Sumkol.Text.Length;

        }

        private void txt_ReportMony_Franshiz_TextChanged(object sender, EventArgs e)
        {
            if (txt_ReportMony_Franshiz.Text == "" || txt_ReportMony_Franshiz.Text == @"0") return;
            decimal price;
            price = decimal.Parse(txt_ReportMony_Franshiz.Text, System.Globalization.NumberStyles.Currency);
            txt_ReportMony_Franshiz.Text = price.ToString("#,#");
            txt_ReportMony_Franshiz.SelectionStart = txt_ReportMony_Franshiz.Text.Length;
        }

        private void txt_ReportMony_Pardakhti_TextChanged(object sender, EventArgs e)
        {
            if (txt_ReportMony_Pardakhti.Text == "" || txt_ReportMony_Pardakhti.Text == @"0") return;
            decimal price;
            price = decimal.Parse(txt_ReportMony_Pardakhti.Text, System.Globalization.NumberStyles.Currency);
            txt_ReportMony_Pardakhti.Text = price.ToString("#,#");
            txt_ReportMony_Pardakhti.SelectionStart = txt_ReportMony_Pardakhti.Text.Length;
        }

        private void buttonItem25_Click(object sender, EventArgs e)
        {
            MessageBox.Show("طراح و برنامه نویس: امیر بیاتانی \n وبلاگ: www.amir200h.blogfa.com \n شماره تماس: 09361327412 \n Yahoo! ID: Amir200hA");
        }
    }
}



