public DbsyncTvConstraintType(Constraintt cs)
 {
     this.constr = cs;
     this.Text = cs.Constraint_nam;
     this.typeOfIcon = ConstraintIcon;
     this.Name = this.Text;
 }
        public override List<string> addConstraint(Tablee tabIn, Constraintt constIn)
        {
            List<string> output = new List<string>();

            if (constIn.Constraint_typ == "CHECK")
                {
                    output.Add("ALTER TABLE [" + tabIn.NazovTabulky + "] ADD CONSTRAINT " + constIn.Constraint_nam + " CHECK (" + constIn.Condition + ")");
                }

            return output;
        }
 public abstract List<string> removeConstraint(Tablee tabIn, Constraintt constIn);
 public abstract List<string> alterConstraint(Tablee tabIn, Constraintt constIn);
 public override List<string> removeConstraint(Tablee tabIn, Constraintt constIn)
 {
     List<string> output = new List<string>();
     if (constIn.Constraint_typ != "PRIMARY KEY")
         if (constIn.Constraint_typ != "FOREIGN KEY")
         {
             {
                 output.Add("ALTER TABLE " + tabIn.NazovTabulky + " drop CONSTRAINT " + constIn.Constraint_nam);
             }
         }
         return output;
 }
 public override List<string> alterConstraint(Tablee tabIn, Constraintt constIn)
 {
     List<string> output = new List<string>();
     if (constIn.Constraint_typ != "PRIMARY KEY")
     {
         if (constIn.Constraint_typ != "FOREIGN KEY")
         {
             output.AddRange(removeConstraint(tabIn, constIn));
             output.AddRange(addConstraint(tabIn, constIn));
         }
     }
         return output;
 }
        private void readConstraintsForTab(Tablee tab)
        {
            SqlCommand com = pripojenie.CreateCommand();
            com.CommandText = "select * from INFORMATION_SCHEMA.TABLE_CONSTRAINTS " +
                              "where TABLE_NAME = '" + tab.NazovTabulky + "'";
            SqlDataReader red = com.ExecuteReader();
            while (red.Read())
            {
                Constraintt constr = new Constraintt();
                constr.Constraint_nam = red["Constraint_name"].ToString();
                constr.Constraint_typ = red["Constraint_type"].ToString();
                if (red["IS_deferrable"].ToString() == "YES")
                {
                    constr.Is_deferabl = true;
                }
                else constr.Is_deferabl = false;
                if (red["INITIALLY_DEFERRED"].ToString() == "YES")
                {
                    constr.Initialy_deferre = true;
                }
                else constr.Initialy_deferre = false;

                //if (constr.Constraint_typ == "PRIMARY KEY")
                //{
                    SqlCommand com2 = pripojenie.CreateCommand();
                    com2.CommandText = "select * from INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE where CONSTRAINT_NAME = '" + constr.Constraint_nam + "'";
                    SqlDataReader red2 = com2.ExecuteReader();
                    while (red2.Read())
                    {
                        constr.Column.Add(red2["COLUMN_NAME"].ToString());
                    }
                    red2.Close();
                //}

                if (constr.Constraint_typ == "CHECK")
                {
                    com2 = pripojenie.CreateCommand();
                    com2.CommandText = "SELECT * FROM INFORMATION_SCHEMA.CHECK_CONSTRAINTS where CONSTRAINT_NAME = '" + constr.Constraint_nam + "'";
                    red2 = com2.ExecuteReader();
                    while (red2.Read())
                    {
                        constr.Condition = (red2["CHECK_CLAUSE"].ToString());
                    }
                    red2.Close();
                }

                tab.Constrainty.Add(constr);

            }
            red.Close();

            //nacitam nazvy default constraint
            com = pripojenie.CreateCommand();
            com.CommandText = " select o.name name1, c.name name2 from sysobjects o " +
                                " inner join syscolumns c" +
                                " on o.id = c.cdefault" +
                                " inner join sysobjects t" +
                                " on c.id = t.id" +
                                " where o.xtype = 'd'" +
                                " and t.name = '"+tab.NazovTabulky+"'";
            red = com.ExecuteReader();
            while (red.Read())
            {
                Constraintt constrr = new Constraintt();
                constrr.Constraint_nam = red["name1"].ToString();
                constrr.Column.Add(red["name2"].ToString());
                constrr.Constraint_typ = "DEFAULT";
                tab.Constrainty.Add(constrr);
            }
        }
        public DbSyncConstraintDiff(Constraintt constAin, Constraintt constBin)
        {
            this.constA = constAin;
            this.constB = constBin;

            constraintAtributesListA = new List<ObjectAtribute>();
            constraintAtributesListB = new List<ObjectAtribute>();

            if (constA == null || constB == null)
            {
                if (constA != null)
                {
                    this.constraintName = constA.Constraint_nam;
                    constraintAtributesListA.Add(new ObjectAtribute("Constraint name ", constA.Constraint_nam, true));
                    constraintAtributesListA.Add(new ObjectAtribute("Constraint type ", constA.Constraint_typ, true));
                    constraintAtributesListA.Add(new ObjectAtribute("Initialy defered ", constA.Initialy_deferre.ToString(), true));
                    constraintAtributesListA.Add(new ObjectAtribute("Is deferable ", constA.Is_deferabl.ToString(), true));
                    constraintAtributesListA.Add(new ObjectAtribute("Condition ", constA.Condition, true));
                    foreach (string s in constA.Column)
                    {
                    constraintAtributesListA.Add(new ObjectAtribute("Column ", s, true));
                    }
                }
                else if (constB != null)
                {
                    this.constraintName = constB.Constraint_nam;
                    constraintAtributesListB.Add(new ObjectAtribute("Constraint name ", constB.Constraint_nam, true));
                    constraintAtributesListB.Add(new ObjectAtribute("Constraint type ", constB.Constraint_typ, true));
                    constraintAtributesListB.Add(new ObjectAtribute("Initialy defered ", constB.Initialy_deferre.ToString(), true));
                    constraintAtributesListB.Add(new ObjectAtribute("Is deferable ", constB.Is_deferabl.ToString(), true));
                    constraintAtributesListB.Add(new ObjectAtribute("Condition ", constB.Condition, true));
                    foreach (string s in constB.Column)
                    {
                        constraintAtributesListB.Add(new ObjectAtribute("Column ", s, true));
                    }
                }
                else this.constraintName = "UNDEFINED";
            }
            if (constA != null && constB != null)
            {
                this.constraintName = constA.Constraint_nam;
                if (constA.Constraint_nam != constB.Constraint_nam) diffConstraintName = true;
                if (constA.Constraint_typ != constB.Constraint_typ) diffConstraintType = true;
                if (constA.Initialy_deferre != constB.Initialy_deferre) diffInitialyDefered = true;
                if (constA.Is_deferabl != constB.Is_deferabl) diffIsDeferable = true;
                if (constA.Condition != constB.Condition) diffCondition = true;
                if (!CompareColumns(constA.Column,constB.Column)) diffColumns = true;

                if (diffConstraintName || diffConstraintType || diffInitialyDefered || diffIsDeferable||diffCondition||diffColumns) different = true;
                else different = false;

                ObjectAtribute cName = new ObjectAtribute("Constraint name ", constA.Constraint_nam, false);

                if (diffConstraintType)
                {
                    ObjectAtribute cTypeA = new ObjectAtribute("Constraint type ", constA.Constraint_typ, true);
                    constraintAtributesListA.Add(cTypeA);
                    ObjectAtribute cTypeB = new ObjectAtribute("Constraint type ", constB.Constraint_typ, true);
                    constraintAtributesListB.Add(cTypeB);
                }
                else
                {
                    ObjectAtribute cType = new ObjectAtribute("Constraint type ", constA.Constraint_typ, false);
                    constraintAtributesListA.Add(cType);
                    constraintAtributesListB.Add(cType);
                }

                if (diffInitialyDefered)
                {
                    ObjectAtribute cdeferedA = new ObjectAtribute("Initialy defered ", constA.Initialy_deferre.ToString(), true);
                    constraintAtributesListA.Add(cdeferedA);
                    ObjectAtribute cdeferedB = new ObjectAtribute("Initialy defered ", constB.Initialy_deferre.ToString(), true);
                    constraintAtributesListB.Add(cdeferedB);
                }
                else
                {
                    ObjectAtribute cdefered = new ObjectAtribute("Initialy defered ", constA.Initialy_deferre.ToString(), false);
                    constraintAtributesListA.Add(cdefered);
                    constraintAtributesListB.Add(cdefered);
                }

                if (diffIsDeferable)
                {
                    ObjectAtribute cDeferableA = new ObjectAtribute("Deferable ", constA.Is_deferabl.ToString(), true);
                    constraintAtributesListA.Add(cDeferableA);
                    ObjectAtribute cDeferableB = new ObjectAtribute("Deferable ", constB.Is_deferabl.ToString(), true);
                    constraintAtributesListB.Add(cDeferableB);
                }
                else
                {
                    ObjectAtribute cDeferable = new ObjectAtribute("Deferable ", constA.Is_deferabl.ToString(), false);
                    constraintAtributesListA.Add(cDeferable);
                    constraintAtributesListB.Add(cDeferable);
                }
                if (diffCondition)
                {
                    constraintAtributesListA.Add(new ObjectAtribute("Condition ", constA.Condition, true));
                    constraintAtributesListB.Add(new ObjectAtribute("Condition ", constB.Condition, true));

                }
                else
                {
                    constraintAtributesListA.Add(new ObjectAtribute("Condition ", constA.Condition, false));
                    constraintAtributesListB.Add(new ObjectAtribute("Condition ", constB.Condition, false));
                }
                if (diffColumns)
                {
                    foreach (string s in constA.Column)
                    {
                        constraintAtributesListA.Add(new ObjectAtribute("Column ", s, true));
                    }
                    foreach (string s in constB.Column)
                    {
                        constraintAtributesListB.Add(new ObjectAtribute("Column ", s, true));
                    }

                }
                else
                {
                    foreach (string s in constA.Column)
                    {
                        constraintAtributesListA.Add(new ObjectAtribute("Column ", s, false));
                        constraintAtributesListB.Add(new ObjectAtribute("Column ", s, false));
                    }
                }

            }
            else different = true;
        }
 public override List<string> alterConstraint(Tablee tabIn, Constraintt constIn)
 {
     throw new NotImplementedException();
 }