using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Linq;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using ProjectMalekiyatArazi.CalssIliya;
using CosarMISComponents;
using DevExpress.XtraTab;
using ProjectBodybuilding;

namespace ProjectMalekiyatArazi.BaseForm
{
    public partial class BaseForm : DevExpress.XtraEditors.XtraForm
    {
        public BaseForm()
        {
            InitializeComponent();
        }

        //--------------------- مسیر نرم افزار و کلاس اصلی

        public static string appPath = Application.StartupPath;
        public ClassIliyaHesabdari IliyaClass = new ClassIliyaHesabdari();
        //---------------------------------------------------

        //---------------------- سایر متغییر های عمومی
        public static int btnPresss { get; set; }
        public static string btnPress { get; set; }
        public static string CodeAgsatT { get; set; }
        public static Int64 CodeOzvID { get; set; }
        public static Int64 CodeIDPardakht { get; set; }
        
        public static Int64 IDAnbarKala { get; set; }
        public static Int64 IDPardakht { get; set; }
        public static Int64 IDOzv { get; set; }
        public static int SelFormSelect { get; set; }
        public static Int64 IDHazine { get; set; }
        public static Int64 IDNote { get; set; }
        public static string CodeFishT { get; set; }
        public static string NumberCheckT { get; set; }
        public static int SaleMali { get; set; }
        public static int IDSaleMaliT { get; set; }
        public static string NumberFaktors { get; set; }
        public static bool TasviyeFaktor { get; set; }
        public static string CodeKalaFaktor { get; set; }
        public static string NameKalaFaktor { get; set; }
        public static string GeymatFiKalaFaktor { get; set; }
        public static int VahedKalaFaktor { get; set; }
        public static int CodeKalaFaktorExit { get; set; }
        public static int NoeFaktorF { get; set; }
        public static Int64 IDCheckHa { get; set; }
        public static Int64 IDGestHa { get; set; }
        
        public static string KhadamatName { get; set; }

        public static string UserName { get; set; }
        public static string UserFullName { get; set; }
        public static string Semat { get; set; }
        public static int UserNameID { get; set; }

        public static int PerPageNumber { get; set; }
        public static bool PerSaveRecord { get; set; }
        public static bool PerEditRecord { get; set; }
        public static bool PerDelRecord { get; set; }
        public static bool PerAddRecord { get; set; }
        public static bool PerPrintRecord { get; set; }
        public static bool PerSearchRecord { get; set; }
        public static bool PerViewRecord { get; set; }
        public static bool PerTasviyeRecord { get; set; }
        //-----------------------------------------------

        //------------پیغام های نمایش-----------------

        public static string AddMessage = "";
        public static string InsertMessage = "اطلاعات با موفقیت ذخیره شد";
        public static string EditMessage = "اطلاعات با موفقیت ویرایش شد";
        public static string DeleteMessage = "اطلاعات با موفقیت حذف شد";
        public static string QuestionEditMessage = "آیا مایل به ویرایش اطلاعات";
        public static string QuestionDeleteMessage = "آیا مایل به حذف اطلاعات";

        //---------------------------------------------- چک کردن مقادیر

        public virtual void CheckValidation()
        {
            foreach (var groupBox in Controls.OfType<GroupControl>())
            {
                foreach (var ctrl in groupBox.Controls.OfType<CMISTextEdit>())
                {
                    if (ctrl is CMISTextEdit && ((CMISTextEdit)ctrl).RequiredField &&
                        string.IsNullOrEmpty(((CMISTextEdit)ctrl).Text) || ((CMISTextEdit)ctrl).RequiredField && ((CMISTextEdit)ctrl).Text == "0"
                        || ((CMISTextEdit)ctrl).RequiredField && ((CMISTextEdit)ctrl).Text == "ريال 0/0")
                    {
                        ((CMISTextEdit)ctrl).Focus();
                        throw new Exception("لطفا " + ((CMISTextEdit)ctrl).RequiredFieldCaption + " " +
                            "را وارد نمایید");
                    }
                }

                foreach (var ctrl in groupBox.Controls.OfType<CMISButtonEdit>())
                {
                    if (ctrl is CMISButtonEdit && ((CMISButtonEdit)ctrl).RequiredField &&
                        string.IsNullOrEmpty(((CMISButtonEdit)ctrl).Text) || ((CMISButtonEdit)ctrl).RequiredField && ((CMISButtonEdit)ctrl).Text == "0" ||
                        ((CMISButtonEdit)ctrl).RequiredField && ((CMISButtonEdit)ctrl).Text == "ريال 0/0")
                    {
                        ((CMISButtonEdit)ctrl).Focus();
                        throw new Exception("لطفا " + ((CMISButtonEdit)ctrl).RequiredFieldCaption + " " +
                            "را وارد نمایید");
                    }
                }

                foreach (var ctrl in groupBox.Controls.OfType<CMISMemoEdit>())
                {
                    if (ctrl is CMISMemoEdit && ((CMISMemoEdit)ctrl).RequiredField &&
                        string.IsNullOrEmpty(((CMISMemoEdit)ctrl).Text))
                    {
                        ((CMISMemoEdit)ctrl).Focus();
                        throw new Exception("لطفا " + ((CMISMemoEdit)ctrl).RequiredFieldCaption + " " +
                            "را وارد نمایید");
                    }
                }

                foreach (var ctrl in groupBox.Controls.OfType<CMISLookUpEdit>())
                {
                    if (ctrl is CMISLookUpEdit && ((CMISLookUpEdit)ctrl).RequiredField &&
                        string.IsNullOrEmpty(((CMISLookUpEdit)ctrl).Text))
                    {
                        ((CMISLookUpEdit)ctrl).Focus();
                        throw new Exception("لطفا " + ((CMISLookUpEdit)ctrl).RequiredFieldCaption + " " +
                            "را انتخاب نمایید");
                    }
                }

                foreach (var ctrl in groupBox.Controls.OfType<CMISComboBoxEdit>())
                {
                    if (ctrl is CMISComboBoxEdit && ((CMISComboBoxEdit)ctrl).RequiredField &&
                        string.IsNullOrEmpty(((CMISComboBoxEdit)ctrl).Text))
                    {
                        ((CMISComboBoxEdit)ctrl).Focus();
                        throw new Exception("لطفا " + ((CMISComboBoxEdit)ctrl).RequiredFieldCaption + " " +
                            "را انتخاب نمایید");
                    }
                }
            }
        }

        public virtual void CheckValidationDate()
        {
            foreach (var groupBox in Controls.OfType<GroupControl>())
            {
                foreach (var ctrl in groupBox.Controls.OfType<CMISTextEdit>())
                {
                    if (ctrl is CMISTextEdit && ((CMISTextEdit)ctrl).DateField && ((CMISTextEdit)ctrl).RequiredField &&
                        ((CMISTextEdit)ctrl).Text != null && IliyaClass.standarddate(((CMISTextEdit)ctrl).Text) == false)
                    {
                        throw new Exception("لطفا " + ((CMISTextEdit)ctrl).RequiredFieldCaption + " " +
                         "را صحیح وارد نمایید");
                    }
                }

                foreach (var ctrl in groupBox.Controls.OfType<CMISButtonEdit>())
                {
                    if (ctrl is CMISButtonEdit && ((CMISButtonEdit)ctrl).DateField && ((CMISButtonEdit)ctrl).RequiredField &&
                        ((CMISButtonEdit)ctrl).Text != null && IliyaClass.standarddate(((CMISButtonEdit)ctrl).Text) == false)
                    {
                        throw new Exception("لطفا " + ((CMISButtonEdit)ctrl).RequiredFieldCaption + " " +
                         "را صحیح وارد نمایید");
                    }
                }
            }
        }

        public virtual void ClearValidation()
        {
            foreach (var groupBox in Controls.OfType<GroupControl>())
            {
                try
                {
                    foreach (var ctrl in groupBox.Controls.OfType<CMISTextEdit>())
                    {
                        if (ctrl is CMISTextEdit && ((CMISTextEdit)ctrl).GetCleaned &&
                            ((CMISTextEdit)ctrl).Text != null)
                        {
                            ((CMISTextEdit)ctrl).Text = string.Empty;
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }

                foreach (var ctrl in groupBox.Controls.OfType<CMISButtonEdit>())
                {
                    if (ctrl is CMISButtonEdit && ((CMISButtonEdit)ctrl).GetCleaned &&
                        ((CMISButtonEdit)ctrl).Text != null)
                    {
                        ((CMISButtonEdit)ctrl).Text = string.Empty;
                    }
                }

                foreach (var ctrl in groupBox.Controls.OfType<CMISMemoEdit>())
                {
                    if (ctrl is CMISMemoEdit && ((CMISMemoEdit)ctrl).GetCleaned &&
                        ((CMISMemoEdit)ctrl).Text != null)
                    {
                        ((CMISMemoEdit)ctrl).Text = string.Empty;
                    }
                }

                foreach (var ctrl in groupBox.Controls.OfType<CMISLookUpEdit>())
                {
                    if (ctrl is CMISLookUpEdit && ((CMISLookUpEdit)ctrl).GetCleaned &&
                        ((CMISLookUpEdit)ctrl).Text != null)
                    {
                        ((CMISLookUpEdit)ctrl).EditValue = -1;
                    }
                }

                foreach (var ctrl in groupBox.Controls.OfType<CMISSearchLookUpEdit>())
                {
                    if (ctrl is CMISSearchLookUpEdit && ((CMISSearchLookUpEdit)ctrl).GetCleaned &&
                        ((CMISSearchLookUpEdit)ctrl).Text != null)
                    {
                        ((CMISSearchLookUpEdit)ctrl).EditValue = -1;
                    }
                }

                foreach (var ctrl in groupBox.Controls.OfType<CMISComboBoxEdit>())
                {
                    if (ctrl is CMISComboBoxEdit && ((CMISComboBoxEdit)ctrl).GetCleaned &&
                        ((CMISComboBoxEdit)ctrl).Text != null)
                    {
                        ((CMISComboBoxEdit)ctrl).EditValue = -1;
                    }
                }

            }
        }

        //--------------------------------------------------------------------------------------

        public virtual void SaveRecord(bool applyMode)
        {
            CheckValidation();
            CheckValidationDate();
        }

        public virtual void EditRecord(bool applyMode)
        {
            CheckValidation();
            CheckValidationDate();
        }

        public virtual void DeleteRecord(bool applyMode)
        {

        }

        public virtual void RefreshRecord(bool applyMode)
        {

        }

        public virtual void PrintReportRecord()
        {

        }

        private void BaseForm_Load(object sender, EventArgs e)
        {
            /*PerPageNumber = 0;
            this.tblUserActionSectionTableAdapter.LoadUserActionSectionPer(this.iLIYADataBaseHDataSet.tblUserActionSection, 0, PerPageNumber);
            for (int i = 0; i <= iLIYADataBaseHDataSet.tblUserActionSection.Rows.Count; i++)
            {
                var rowA = iLIYADataBaseHDataSet.tblUserActionSection.Rows[i] as ILIYADataBaseHDataSet.tblUserActionSectionRow;

                if (rowA.IDAction == 1)
                {
                    PerSaveRecord = true;
                }
                if (rowA.IDAction == 2)
                {
                    PerEitRecord = true;
                }
                if (rowA.IDAction == 3)
                {
                    PerDelRecord = true;
                }
                if (rowA.IDAction == 4)
                {
                    PerAddRecord = true;
                }
                if (rowA.IDAction == 5)
                {
                    PerPrintRecord = true;
                }
                if (rowA.IDAction == 6)
                {
                    PerSearchRecord = true;
                }
                if (rowA.IDAction == 7)
                {
                    PerViewRecord = true;
                }
            }*/
        }
    }
}