using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
using System.Globalization;

namespace TelBook
{
    public partial class fmnew : Form
    {
        public fmnew()
        {
            InitializeComponent();
        }
        OleDbConnection con = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|DATA.ACCDB;JET OLEDB:DATABASE PASSWORD=●●●●●●●●●●●●;");

        private void fmnew_Load(object sender, EventArgs e)
        {
            try
            {
                con.Open();
                string d;
                OleDbDataAdapter adap;
                DataSet ds = new DataSet();
                d = "select * from groups";
                adap = new OleDbDataAdapter(d, con);
                adap.Fill(ds, "groups");
                comboBox1.DataSource = ds.Tables["groups"];
                comboBox1.DisplayMember = "groupname";

                if (button1.Text == "ویرایش")
                {
                    comboBox1.Text = label13.Text;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "System Error", MessageBoxButtons.OK, MessageBoxIcon.Error);

            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                if (button1.Text == "ذخیره")
                {
                    string cmdstr;
                    OleDbCommand cmdoledb = new OleDbCommand();
                    cmdstr = "INSERT into contact(fil1,fil2,fil3,fil4,fil5,fil6,fil7,fil8,fil9,fil10,fil11,fil12,fil13) values('" + comboBox1.Text + "','" + fil2.Text + "','" + fil3.Text + "','" + fil4.Text + "','" + fil5.Text + "','" + fil6.Text + "','" + fil7.Text + "','" + fil8.Text + "','" + fil9.Text + "','" + fil10.Text + "','" + fil11.Text + "','" + fil12.Text + "','" + fil13.Text + "')";
                    cmdoledb.Connection = con;
                    cmdoledb.CommandText = cmdstr;
                    cmdoledb.ExecuteReader();
                    MessageBox.Show("مخاطب جدید به ثبت رسید", "System Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                    if (button1.Text == "ویرایش")
                    {
                        string updateq = "update contact set fil1='" + comboBox1.Text + "',fil2='" + fil2.Text + "',fil3='" + fil3.Text + "',fil4='" + fil4.Text + "',fil5='" + fil5.Text + "',fil6='" + fil6.Text + "',fil7='" + fil7.Text + "',fil8='" + fil8.Text + "',fil9='" + fil9.Text + "',fil10='" + fil10.Text + "',fil11='" + fil11.Text + "',fil12='" + fil12.Text + "',fil13='" + fil13.Text + "'where id=" + textBox1.Text + "";
                        OleDbCommand uq = new OleDbCommand(updateq, con);
                        uq.ExecuteNonQuery();
                        MessageBox.Show("عملیات ویرایش انجام شد", "System Info", MessageBoxButtons.OK, MessageBoxIcon.Information);

                    }
                this.Close();
            }
            catch (Exception ex)
            {

                MessageBox.Show(ex.Message, "System Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        private void fil10_Enter(object sender, EventArgs e)
        {
            InputLanguage.CurrentInputLanguage = InputLanguage.FromCulture(new CultureInfo("en"));
        }

        private void fil11_Enter(object sender, EventArgs e)
        {
            InputLanguage.CurrentInputLanguage = InputLanguage.FromCulture(new CultureInfo("fa"));

        }

        private void fil2_Enter(object sender, EventArgs e)
        {
            InputLanguage.CurrentInputLanguage = InputLanguage.FromCulture(new CultureInfo("fa"));

        }

        private void fil3_Enter(object sender, EventArgs e)
        {
            InputLanguage.CurrentInputLanguage = InputLanguage.FromCulture(new CultureInfo("fa"));

        }

        private void fil4_Enter(object sender, EventArgs e)
        {
            InputLanguage.CurrentInputLanguage = InputLanguage.FromCulture(new CultureInfo("fa"));

        }

        private void fil5_Enter(object sender, EventArgs e)
        {
            InputLanguage.CurrentInputLanguage = InputLanguage.FromCulture(new CultureInfo("fa"));

        }

        private void fil6_Enter(object sender, EventArgs e)
        {
            InputLanguage.CurrentInputLanguage = InputLanguage.FromCulture(new CultureInfo("fa"));

        }

        private void fil7_Enter(object sender, EventArgs e)
        {
            InputLanguage.CurrentInputLanguage = InputLanguage.FromCulture(new CultureInfo("fa"));

        }

        private void fil8_Enter(object sender, EventArgs e)
        {
            InputLanguage.CurrentInputLanguage = InputLanguage.FromCulture(new CultureInfo("fa"));

        }

        private void fil9_Enter(object sender, EventArgs e)
        {
            InputLanguage.CurrentInputLanguage = InputLanguage.FromCulture(new CultureInfo("fa"));

        }

        private void fil12_Enter(object sender, EventArgs e)
        {
            InputLanguage.CurrentInputLanguage = InputLanguage.FromCulture(new CultureInfo("fa"));

        }

        private void fil13_Enter(object sender, EventArgs e)
        {
            InputLanguage.CurrentInputLanguage = InputLanguage.FromCulture(new CultureInfo("fa"));

        }
    }
}
