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.IO;
using BehComponents;
namespace Stone
{
    public partial class EditPropertiesFactor : Form
    {
        string XmlDataFileName = System.Environment.GetFolderPath(System.Environment.SpecialFolder.ApplicationData) + "\\ParsZSDB" + "\\PropertiesFactor.xml";
        string XmlSchemaFileName = System.Environment.GetFolderPath(System.Environment.SpecialFolder.ApplicationData) + "\\ParsZSDB" + "\\PropertiesFactor.xsd";

        DataGridViewRow GridRow = null;
        public EditPropertiesFactor()
        {
            InitializeComponent();
         
        }


        public EditPropertiesFactor(DataGridViewRow GridRowEdit)
        {
            InitializeComponent();
            GridRow = GridRowEdit;

        }

        private void button3_Click(object sender, EventArgs e)
        {
            this.Close();
           
        }

        private void ADD_EditProducts_Load(object sender, EventArgs e)
        {

            if (GridRow != null)
            {

                txtid.Text = GridRow.Cells[0].Value.ToString();
                txtname.Text = GridRow.Cells[1].Value.ToString();
                txttel.Text = GridRow.Cells[2].Value.ToString();
                txtprice.Text = GridRow.Cells[3].Value.ToString();
                txtmod.Text = GridRow.Cells[4].Value.ToString();
                txtstring.Text = GridRow.Cells[5].Value.ToString();
                dateper.Text = GridRow.Cells[6].Value.ToString();
                txtaddress.Text = GridRow.Cells[7].Value.ToString();

                return;
            }

            
                    txtid.Text = Program.MGF.GridViewProperties.CurrentRow.Cells[0].Value.ToString();
                    txtname.Text = Program.MGF.GridViewProperties.CurrentRow.Cells[1].Value.ToString();
                    txttel.Text = Program.MGF.GridViewProperties.CurrentRow.Cells[2].Value.ToString();
                    txtprice.Text = Program.MGF.GridViewProperties.CurrentRow.Cells[3].Value.ToString();
                    txtmod.Text = Program.MGF.GridViewProperties.CurrentRow.Cells[4].Value.ToString();
                    txtstring.Text = Program.MGF.GridViewProperties.CurrentRow.Cells[5].Value.ToString();
                    dateper.Text = Program.MGF.GridViewProperties.CurrentRow.Cells[6].Value.ToString();
                    txtaddress.Text = Program.MGF.GridViewProperties.CurrentRow.Cells[7].Value.ToString(); 

        }
        private void btnreg_Click(object sender, EventArgs e)
        {
            if (dateper.Text == "    /  /")
            {
                MessageBox.Show("فیلد تاریخ را بررسی کنید ، نباید مقدار خالی داشته باشند", "زمرد", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }


            if (GridRow != null)
            {

                DataRow[] DrArray = Program.FC.DSFactor.Tables["TPropertiesFactor"].Select("IdFactorProperties = " + txtid.Text);

                DrArray[0]["Name"] = txtname.Text;
                DrArray[0]["Tel"] = Int64.Parse(txttel.Text);
                DrArray[0]["PriceFactor"] = Int64.Parse(txtprice.Text);
                DrArray[0]["Mod"] = Int64.Parse(txtmod.Text);
                DrArray[0]["StringMoney"] = txtstring.Text;
                DrArray[0]["Date"] = dateper.Text;
                DrArray[0]["Address"] = txtaddress.Text;
                Program.FC.DSFactor.Tables["TPropertiesFactor"].AcceptChanges();
                Program.FC.DSFactor.Tables["TPropertiesFactor"].WriteXml(XmlDataFileName);

                DataRow[] DrArray1 = Program.SF.DSForPrint.Tables["TPropertiesFactor"].Select("IdFactorProperties = " + txtid.Text);

                DrArray1[0]["Name"] = txtname.Text;
                DrArray1[0]["Tel"] = Int64.Parse(txttel.Text);
                DrArray1[0]["PriceFactor"] = Int64.Parse(txtprice.Text);
                DrArray1[0]["Mod"] = Int64.Parse(txtmod.Text);
                DrArray1[0]["StringMoney"] = txtstring.Text;
                DrArray1[0]["Date"] = dateper.Text;
                DrArray1[0]["Address"] = txtaddress.Text;
                Program.SF.DSForPrint.Tables["TPropertiesFactor"].AcceptChanges();




                MessageBox.Show("داده ها با موفقیت ثبت شد", "", MessageBoxButtons.OK, MessageBoxIcon.Information);

                return;
            }



            DataRow[] DrArray2 = Program.FC.DSFactor.Tables["TPropertiesFactor"].Select("IdFactorProperties = " + txtid.Text);

                   DrArray2[0]["Name"] = txtname.Text;
                   DrArray2[0]["Tel"] = Int64.Parse(txttel.Text);
                   DrArray2[0]["PriceFactor"] = Int64.Parse(txtprice.Text);
                   DrArray2[0]["Mod"] = Int64.Parse(txtmod.Text);
                   DrArray2[0]["StringMoney"] = txtstring.Text;
                   DrArray2[0]["Date"] = dateper.Text;
                   DrArray2[0]["Address"] = txtaddress.Text;
                   Program.FC.DSFactor.Tables["TPropertiesFactor"].AcceptChanges();
                   Program.FC.DSFactor.Tables["TPropertiesFactor"].WriteXml(XmlDataFileName);
                   MessageBox.Show("داده ها با موفقیت ثبت شد", "", MessageBoxButtons.OK, MessageBoxIcon.Information);
                   Program.MGF.LblSum.Text = Program.MGF.BS.Count.ToString() + " عدد ";
        }

        private void button1_Click(object sender, EventArgs e)
        {
            txtname.Text = "";
            txttel.Text = "0";
            txtprice.Text = "0";
            txtmod.Text = "0";
            txtstring.Text = "";
            dateper.Text = "";
            txtaddress.Text = "";

        }

        private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
        {
            e.Handled = (char.IsNumber(e.KeyChar) || char.IsControl(e.KeyChar) || char.IsPunctuation(e.KeyChar)) ? false : true;
        }

        private void txtwidth_KeyPress(object sender, KeyPressEventArgs e)
        {
            e.Handled = (char.IsNumber(e.KeyChar) || char.IsControl(e.KeyChar) || char.IsPunctuation(e.KeyChar)) ? false : true;
        }

        private void txtprice_TextChanged(object sender, EventArgs e)
        {
            if (txtprice.Text == "") txtprice.Text = "0";
            txtstring.Text = PDT.PersianDate.c15d(txtprice.Text) + " ریــال ";
            
        }

        private void txtmod_TextChanged(object sender, EventArgs e)
        {
            if (txtmod.Text == "")  txtmod.Text = "0";
            txtprice.Text = (Int64.Parse(txtprice.Text) - Int64.Parse(txtmod.Text)).ToString();
        }

        private void txttel_TextChanged(object sender, EventArgs e)
        {
            if (txttel.Text == "") txttel.Text = "0";
        }

     

    
    }
}
