private void btnOK_Click(object sender, EventArgs e)
        {
            if (!CheckNull()) return;
            if (!CheckLogicValue()) return;
            //ContinuousFuzzySetBLL newFS = new ContinuousFuzzySetBLL();
            FuzzyProcess fz = new FuzzyProcess();
            ConFS newFS = new ConFS();
            //newFS.FuzzySetName = txtLinguistic.Text.Trim();
            newFS.Name = txtLinguistic.Text.Trim() + ".conFS";

            String content = txtBottomLeft.Text.Trim();

            string path = Directory.GetCurrentDirectory() + @"\lib\";

            if (txtTopLeft.Text.Trim() == "" && txtTopRight.Text.Trim() != "")
            {
                newFS.Bottom_Left = Convert.ToDouble(txtBottomLeft.Text);
                newFS.Top_Left = newFS.Top_Right = Convert.ToDouble(txtTopRight.Text);
                newFS.Bottom_Right = Convert.ToDouble(txtBottomRight.Text);
                content += "," + txtTopRight.Text.Trim() + "," + txtTopRight.Text.Trim() + "," + txtBottomRight.Text.Trim();
                //if (newFS.Update() == 1)
                if (fz.UpdateFS(path, content, newFS.Name) == 1)
                {
                    MessageBox.Show("Save Fuzzy Set DONE!");
                }
                else
                {
                    frmRunAsAdministrator frm = new frmRunAsAdministrator();
                    frm.ShowDialog();
                }
            }
            else if (txtTopLeft.Text.Trim() != "" && txtTopRight.Text.Trim() == "")
            {
                newFS.Bottom_Left = Convert.ToDouble(txtBottomLeft.Text);
                newFS.Top_Left = newFS.Top_Right = Convert.ToDouble(txtTopLeft.Text);
                newFS.Bottom_Right = Convert.ToDouble(txtBottomRight.Text);

                content += "," + txtTopLeft.Text.Trim() + "," + txtTopLeft.Text.Trim() + "," + txtBottomRight.Text.Trim();
                //if (newFS.Update() == 1)
                if (fz.UpdateFS(path, content, newFS.Name) == 1)
                {
                    MessageBox.Show("Save Fuzzy Set DONE!");
                }
                else
                {
                    frmRunAsAdministrator frm = new frmRunAsAdministrator();
                    frm.ShowDialog();
                }
            }
            else
            {
                newFS.Bottom_Left = Convert.ToDouble(txtBottomLeft.Text);
                newFS.Top_Left = Convert.ToDouble(txtTopLeft.Text);
                newFS.Top_Right = Convert.ToDouble(txtTopRight.Text);
                newFS.Bottom_Right = Convert.ToDouble(txtBottomRight.Text);

                content += "," + txtTopLeft.Text.Trim() + "," + txtTopRight.Text.Trim() + "," + txtBottomRight.Text.Trim();
                //if (newFS.Update() == 1)
                if (fz.UpdateFS(path, content, newFS.Name) == 1)
                {
                    MessageBox.Show("Save Fuzzy Set DONE!");
                }
                else
                {
                    frmRunAsAdministrator frm = new frmRunAsAdministrator();
                    frm.ShowDialog();
                }
            }
        }
        /// <summary>
        ///  The variable i for getting the previous logicality
        /// </summary>
        //private Boolean SatisfyItem(List<String> itemCondition, FzTupleEntity tuple, int i)
        //{
        //    int indexAttr = Convert.ToInt32(itemCondition[0]);
        //    String dataType = this._attributes[indexAttr].DataType.DataType;
        //    Object value = tuple.ValuesOnPerRow[indexAttr];//we don't know the data type of value
        //    int count = 0;
        //    String fs = itemCondition[2];
        //        //fs = itemCondition[2].Substring(1, itemCondition[2].Length - 2);;
        //    ContinuousFuzzySetBLL conFS = null;
        //    DiscreteFuzzySetBLL disFS = null;
        //    if (itemCondition[1] == "->" || itemCondition[1] == "→")
        //    {
        //        //fs = fs.Substring(1, fs.Length - 2);
        //        conFS = new ContinuousFuzzySetBLL().GetByName(fs);
        //        disFS = new DiscreteFuzzySetBLL().GetByName(fs);//2 is value of user input
        //    }
        //    if (conFS != null)//continuous fuzzy set is priorer than discrete fuzzy set
        //    {
        //        //itemCondition[1] is operator, uValue is the membership of the value on current cell for the selected fuzzy set
        //        Double uValue = FuzzyCompare(Convert.ToDouble(value), conFS, itemCondition[1]);
        //        uValue = Math.Min(uValue, _uRelation);//Update the min value
        //        if (uValue != 0)
        //        {
        //            if (i != -1 && _memberships.Count > 0)// Getting previous logicality
        //                _memberships.Add(_itemConditions[i].nextLogic);
        //            _memberships.Add(uValue.ToString());
        //            count++;
        //        }
        //    }
        //    if (disFS != null && conFS == null)
        //    {
        //        Double uValue = FuzzyCompare(Convert.ToDouble(value), disFS, itemCondition[1]);
        //        uValue = Math.Min(uValue, _uRelation);//Update the min value
        //        if (uValue != 0)
        //        {
        //            if (i != -1 && _memberships.Count > 0)// Getting previous logicality
        //                _memberships.Add(_itemConditions[i].nextLogic);
        //            _memberships.Add(uValue.ToString());
        //            count++;
        //        }
        //    }
        //    if (disFS == null && conFS == null)
        //    {
        //        //if (fs.Contains("\""))
        //        //    fs = fs.Substring(1, fs.Length - 2);
        //        if (ObjectCompare(value, fs, itemCondition[1], dataType))
        //        {
        //            count++;
        //        }
        //    }
        //    if (count == 1)//it mean the tuple is satisfied with all the compare operative
        //    {
        //        return true;
        //    }
        //    return false;
        //}
        private Boolean SatisfyItem(List<String> itemCondition, FzTupleEntity tuple, int i)
        {
            int indexAttr = Convert.ToInt32(itemCondition[0]);
            String dataType = this._attributes[indexAttr].DataType.DataType;
            Object value = tuple.ValuesOnPerRow[indexAttr];//we don't know the data type of value
            int count = 0;
            String fs = itemCondition[2];
            //fs = itemCondition[2].Substring(1, itemCondition[2].Length - 2);;
            ConFS conFS = null;
            DisFS disFS = null;
            string path = Directory.GetCurrentDirectory() + @"\lib\";
            if (itemCondition[1] == "->" || itemCondition[1] == "→")
            {
                //fs = fs.Substring(1, fs.Length - 2);
                conFS = new FuzzyProcess().ReadEachConFS(path + fs + ".conFS");
                disFS = new FuzzyProcess().ReadEachDisFS(path + fs + ".disFS");//2 is value of user input
            }
            if (conFS != null)//continuous fuzzy set is priorer than discrete fuzzy set
            {
                //itemCondition[1] is operator, uValue is the membership of the value on current cell for the selected fuzzy set
                Double uValue = FuzzyCompare(Convert.ToDouble(value), conFS, itemCondition[1]);
                uValue = Math.Min(uValue, _uRelation);//Update the min value
                if (uValue != 0)
                {
                    if (i != -1 && _memberships.Count > 0)// Getting previous logicality
                        _memberships.Add(_itemConditions[i].nextLogic);
                    _memberships.Add(uValue.ToString());
                    count++;
                }
            }
            if (disFS != null && conFS == null)
            {
                Double uValue = FuzzyCompare(Convert.ToDouble(value), disFS, itemCondition[1]);
                uValue = Math.Min(uValue, _uRelation);//Update the min value
                if (uValue != 0)
                {
                    if (i != -1 && _memberships.Count > 0)// Getting previous logicality
                        _memberships.Add(_itemConditions[i].nextLogic);
                    _memberships.Add(uValue.ToString());
                    count++;
                }
            }
            if (disFS == null && conFS == null)
            {
                //if (fs.Contains("\""))
                //    fs = fs.Substring(1, fs.Length - 2);
                if (ObjectCompare(value, fs, itemCondition[1], dataType))
                {
                    count++;
                }
            }

            if (count == 1)//it mean the tuple is satisfied with all the compare operative
            {
                return true;
            }

            return false;
        }
        private bool CheckNull()
        {
            if (txtLinguistic.Text.Trim() == "")
            {
                MessageBox.Show("The linguistic does not empty!");
                return false;
            }
            string path1 = Directory.GetCurrentDirectory() + @"\lib\";
            List<DisFS> list = new FuzzyProcess().GenerateAllDisFS(path1);

            if (txtBottomLeft.Text.Trim() == "" || txtBottomLeft.Text.Trim() == null)
            {
                MessageBox.Show("Bottom-Left is empty!");
                return false;
            }

            if ((txtTopLeft.Text.Trim() == "" && txtTopRight.Text == ""))
            {
                MessageBox.Show("It' just allow one of Top-Left and Top-Right null!");
                return false;
            }

            if (txtBottomRight.Text.Trim() == "" || txtBottomRight.Text.Trim() == null)
            {
                MessageBox.Show("Bottom-Right is empty!");
                return false;
            }

            return true;
        }
        private Boolean IsValuesNull()
        {
            if (txtLinguistic.Text.Trim() == "")
            {
                MessageBox.Show("Fuzzy Set Name is missing!");
                return false;
            }
            string path1 = Directory.GetCurrentDirectory() + @"\lib\";
            List<DisFS> list = new FuzzyProcess().GenerateAllDisFS(path1);

            for (int i = 0; i < gridView1.DataRowCount; i++)
            {
                if (gridView1.GetRowCellValue(i, "values").ToString().Trim() == "" ||
                    gridView1.GetRowCellValue(i, "memberships").ToString().Trim() == "")
                {
                    MessageBox.Show("Missing values on row!\n(Remove row or fill values in row)");
                    return false;
                }
            }

            return true;
        }
        private String ExistsFuzzySet(List<Item> items)
        {
            String message = "";
            FuzzyProcess fp = new FuzzyProcess();
            String path = Directory.GetCurrentDirectory() + @"\lib\";
            foreach (var item in items)
            {
                if (item.elements[1] == "->" || item.elements[1] == "→")
                {
                    if (!fp.Exists(path + item.elements[2] + ".conFS") &&
                        !fp.Exists(path + item.elements[2] + ".disFS"))
                    {
                        return message = "Incorrect fuzzy set: '" + item.elements[2] + "'.";
                    }
                }
            }

            return message;
        }
        private void RefreshData1()
        {
            gridControl1.DataSource = null;
            string path = Directory.GetCurrentDirectory() + @"\lib\";
            List<DisFS> list = new FuzzyProcess().GenerateAllDisFS(path);
            dt = new DataTable();

            dt.Columns.Add("check", typeof(Boolean));
            dt.Columns.Add(new DataColumn("name"));
            dt.Columns.Add(new DataColumn("values"));
            dt.Columns.Add(new DataColumn("memberships"));

            foreach (var item in list)
            {
                DataRow dr = dt.NewRow();
                dr[0] = false;
                dr[1] = item.Name;
                dr[2] = "{" + item.V + "}";
                dr[3] = "{"+ item.M +"}";
                dt.Rows.Add(dr);
            }

            gridControl1.DataSource = dt;
        }
        private void RefreshData()
        {
            ///////Old database//////////////////////////////
            //gridControl1.DataSource = null;
            //List<ContinuousFuzzySetBLL> list = new ContinuousFuzzySetBLL().GetAll();
            //dt = new DataTable();

            //dt.Columns.Add("check", typeof(Boolean));
            //dt.Columns.Add("name", typeof(String));
            //dt.Columns.Add("bottomLeft", typeof(Double));
            //dt.Columns.Add("topLeft", typeof(Double));
            //dt.Columns.Add("topRight", typeof(Double));
            //dt.Columns.Add("bottomRight", typeof(Double));

            //foreach (var item in list)
            //{
            //    DataRow dr = dt.NewRow();
            //    dr[0] = false;
            //    dr[1] = item.FuzzySetName;
            //    dr[2] = item.Bottom_Left;
            //    dr[3] = item.Top_Left;
            //    dr[4] = item.Top_Right;
            //    dr[5] = item.Bottom_Right;
            //    dt.Rows.Add(dr);
            //}

            gridControl1.DataSource = dt;
            gridControl1.DataSource = null;
            FuzzyProcess fz = new FuzzyProcess();
            List<ConFS> list = fz.GenerateAllConFS(Directory.GetCurrentDirectory() + @"\lib\");

            dt = new DataTable();

            dt.Columns.Add("check", typeof(Boolean));
            dt.Columns.Add("name", typeof(String));
            dt.Columns.Add("bottomLeft", typeof(Double));
            dt.Columns.Add("topLeft", typeof(Double));
            dt.Columns.Add("topRight", typeof(Double));
            dt.Columns.Add("bottomRight", typeof(Double));

            foreach (var item in list)
            {
                DataRow dr = dt.NewRow();
                dr[0] = false;
                dr[1] = item.Name;
                dr[2] = item.Bottom_Left;
                dr[3] = item.Top_Left;
                dr[4] = item.Top_Right;
                dr[5] = item.Bottom_Right;
                dt.Rows.Add(dr);
            }

            gridControl1.DataSource = dt;
        }