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.SqlClient;
using System.Globalization;
using Stimulsoft.Report.Dictionary;
using Stimulsoft.Report;
using DevComponents.DotNetBar;
using DevComponents.DotNetBar.Rendering;

namespace Library_Red_Diamonds
{
    public partial class frmInfo : Form
    {
        static SqlConnection con = new SqlConnection(Connection.con);
        public frmInfo()
        {
            InitializeComponent();
        }

        SqlCommand cmd = new SqlCommand();

        private void save()
        {
            cmd = new SqlCommand("EditInfo", con);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Connection = con;
            cmd.Parameters.AddWithValue("@code", txt_code.Text);
            cmd.Parameters.AddWithValue("@libraryname", txt_libraryname.Text);
            cmd.Parameters.AddWithValue("@ownername", txt_owner.Text);
            cmd.Parameters.AddWithValue("@tel", txt_tel.Text);
            cmd.Parameters.AddWithValue("@addres", txt_address.Text);
            con.Open();
            cmd.ExecuteNonQuery();
            con.Close();
            MessageBox.Show("ثبت شد");
            main main = (main)Application.OpenForms["main"];
            main.loadinfo();
            this.Close();
        }

        private void loadinfo()
        {
            cmd.CommandType = CommandType.Text;
            cmd.Connection = con;
            SqlDataReader Myreader;
            cmd.CommandText = "select * from info";
            con.Open();
            Myreader = cmd.ExecuteReader();
            if (Myreader.Read())
            {
                txt_code.Text = Myreader["code"].ToString();
                txt_libraryname.Text = Myreader["libraryname"].ToString();
                txt_owner.Text = Myreader["ownername"].ToString();
                txt_tel.Text = Myreader["tel"].ToString();
                txt_address.Text = Myreader["addres"].ToString();
            }
            Myreader.Close();
            con.Close();
        }

        private void btnsave_Click(object sender, EventArgs e)
        {
            save();  
        }

        private void frmInfo_Load(object sender, EventArgs e)
        {
            InputLanguage.CurrentInputLanguage = InputLanguage.FromCulture(System.Globalization.CultureInfo.CreateSpecificCulture("fa-IR"));
            loadinfo();
        }
    }
}
