Exemplo n.º 1
0
		/// <summary>
		/// Asserts that two <see cref="DataColumn"/> are equal.
		/// </summary> 
		/// <param name="expected">Expected <see cref="DataColumn"/> instance.</param>
		/// <param name="actual">Actual <see cref="DataColumn"/> instance.</param>
		public static void AreEqual(DataColumn expected, DataColumn actual)
		{
			// null case, trivial comparaison
			if (expected==null)
				Assert.AreEqual(expected,actual);
			
			// check same type
			Assert.AreEqual(expected.GetType(), actual.GetType());

			foreach(PropertyInfo pi in expected.GetType().GetProperties())
			{
				switch(pi.Name)
				{
					case "Container": continue;
					case "Site" : continue;
				}
			
				Assert.AreValueEqual(pi, expected, actual);
			}
		}
Exemplo n.º 2
0
	//Activate This Construntor to log All To Standard output
	//public TestClass():base(true){}

	//Activate this constructor to log Failures to a log file
	//public TestClass(System.IO.TextWriter tw):base(tw, false){}


	//Activate this constructor to log All to a log file
	//public TestClass(System.IO.TextWriter tw):base(tw, true){}

	//BY DEFAULT LOGGING IS DONE TO THE STANDARD OUTPUT ONLY FOR FAILURES

	public void run()
	{
		Exception exp = null;
		DataColumn dc;
		Type myType;
		dc = new DataColumn();
		myType = dc.GetType();
	
		try
		{
			BeginCase("GetType");
			Compare(myType, typeof(DataColumn));
		} 
		catch(Exception ex)
		{
			exp = ex;
		}
		finally
		{
			EndCase(exp);
			exp = null;
		}
	}
Exemplo n.º 3
0
        internal XmlElement HandleColumn(DataColumn col, XmlDocument dc, XmlElement schema, bool fWriteOrdinal) {
            XmlElement  root;
            int         minOccurs;

            Debug.Assert(col.ColumnMapping != MappingType.SimpleContent , "Illegal state");

            String refString = (col.ColumnMapping != MappingType.Element) ? Keywords.XSD_ATTRIBUTE : Keywords.XSD_ELEMENT;
            root = dc.CreateElement(Keywords.XSD_PREFIX, refString, Keywords.XSDNS);

            // First add any attributes.
            root.SetAttribute( Keywords.NAME, col.EncodedColumnName);

            if (col.Namespace.Length == 0) {
                DataTable _table = col.Table;
                // We need to travese the hirerarchy to find the targetnamepace
                string tgNamespace = FindTargetNamespace(_table);
                if (col.Namespace != tgNamespace) {
                    root.SetAttribute( Keywords.FORM, Keywords.UNQUALIFIED);
                }
            }

            if (col.GetType() != typeof(DataColumn))
                AddXdoProperties(col, root, dc);
            else
                AddColumnProperties(col, root);


            AddExtendedProperties(col.extendedProperties, root);
            HandleColumnType(col, dc, root, schema);
            if (col.ColumnMapping == MappingType.Hidden) { // CDT / UDT can not be mapped to Hidden column
                if (!col.AllowDBNull)
                    root.SetAttribute(Keywords.MSD_ALLOWDBNULL, Keywords.MSDNS, Keywords.FALSE);

                if (!col.DefaultValueIsNull)
                    if (col.DataType == typeof(bool))
                        root.SetAttribute(Keywords.MSD_DEFAULTVALUE, Keywords.MSDNS, (bool)(col.DefaultValue)? Keywords.TRUE : Keywords.FALSE);
                    else 
                    {
                    XmlTreeGen.ValidateColumnMapping(col.DataType);
                    root.SetAttribute(Keywords.MSD_DEFAULTVALUE, Keywords.MSDNS, col.ConvertObjectToXml(col.DefaultValue));
                    }
            }


            if ((!col.DefaultValueIsNull)&& (col.ColumnMapping != MappingType.Hidden)){
                XmlTreeGen.ValidateColumnMapping(col.DataType);
                if (col.ColumnMapping == MappingType.Attribute && !col.AllowDBNull ) {
                    if (col.DataType == typeof(bool)) {
                        root.SetAttribute(Keywords.MSD_DEFAULTVALUE, Keywords.MSDNS, (bool)(col.DefaultValue)? Keywords.TRUE : Keywords.FALSE);
                    }
                    else { // CDT / UDT columns cn not be mapped to Attribute also
                        root.SetAttribute(Keywords.MSD_DEFAULTVALUE, Keywords.MSDNS, col.ConvertObjectToXml(col.DefaultValue));
                    }
                }
                else { // Element Column : need to handle CDT
                    if (col.DataType == typeof(bool)) {
                        root.SetAttribute(Keywords.DEFAULT, (bool)(col.DefaultValue)? Keywords.TRUE : Keywords.FALSE);
                    }
                    else {
                        if (!col.IsCustomType) { // built in type
                            root.SetAttribute(Keywords.DEFAULT, col.ConvertObjectToXml(col.DefaultValue));
                        }
                        else { // UDT column
                        }
                    }
                }
            }

            if (schFormat == SchemaFormat.Remoting)
                root.SetAttribute( Keywords.TARGETNAMESPACE, Keywords.MSDNS, col.Namespace);

            else {

                if ((col.Namespace != (col.Table.TypeName.IsEmpty ? col.Table.Namespace : col.Table.TypeName.Namespace)) && (col.Namespace.Length != 0))
             {
                        XmlElement schNode = GetSchema(col.Namespace);
                        if (FindTypeNode(schNode, col.EncodedColumnName) == null)
                            schNode.AppendChild(root);
                        root = _dc.CreateElement(Keywords.XSD_PREFIX, refString, Keywords.XSDNS);
                        root.SetAttribute( Keywords.REF, prefixes[ col.Namespace]+":"+ col.EncodedColumnName);
                        if (col.Table.Namespace!=_ds.Namespace) {
                            string prefix = (string)prefixes[col.Namespace];
                            XmlElement tNode = GetSchema(col.Table.Namespace);
                    }
                    }
                }


            minOccurs = (col.AllowDBNull) ? 0 : 1;


            // [....] 2001 change
            if (col.ColumnMapping == MappingType.Attribute && minOccurs != 0)
                root.SetAttribute(Keywords.USE, Keywords.REQUIRED);


            if (col.ColumnMapping == MappingType.Hidden) {
                root.SetAttribute(Keywords.USE, Keywords.PROHIBITED);
            }
            else
                if (col.ColumnMapping != MappingType.Attribute && minOccurs != 1)
                    root.SetAttribute(Keywords.MINOCCURS, minOccurs.ToString(CultureInfo.InvariantCulture));

            if ((col.ColumnMapping == MappingType.Element) && fWriteOrdinal)
                root.SetAttribute(Keywords.MSD_ORDINAL,Keywords.MSDNS, col.Ordinal.ToString(CultureInfo.InvariantCulture));

            return root;
        }
Exemplo n.º 4
0
		[Test] public void TestGetType()
		{
			DataColumn dc;
			Type myType;
			dc = new DataColumn();
			myType = dc.GetType();

			// GetType
			Assert.AreEqual(typeof(DataColumn), myType, "DC28");
		}
 internal XmlElement HandleColumn(DataColumn col, XmlDocument dc, XmlElement schema, bool fWriteOrdinal)
 {
     string localName = (col.ColumnMapping != MappingType.Element) ? "attribute" : "element";
     XmlElement root = dc.CreateElement("xs", localName, "http://www.w3.org/2001/XMLSchema");
     root.SetAttribute("name", col.EncodedColumnName);
     if (col.Namespace.Length == 0)
     {
         DataTable table = col.Table;
         string str2 = this.FindTargetNamespace(table);
         if (col.Namespace != str2)
         {
             root.SetAttribute("form", "unqualified");
         }
     }
     if (col.GetType() != typeof(DataColumn))
     {
         this.AddXdoProperties(col, root, dc);
     }
     else
     {
         this.AddColumnProperties(col, root);
     }
     AddExtendedProperties(col.extendedProperties, root);
     this.HandleColumnType(col, dc, root, schema);
     if (col.ColumnMapping == MappingType.Hidden)
     {
         if (!col.AllowDBNull)
         {
             root.SetAttribute("AllowDBNull", "urn:schemas-microsoft-com:xml-msdata", "false");
         }
         if (!col.DefaultValueIsNull)
         {
             if (col.DataType == typeof(bool))
             {
                 root.SetAttribute("DefaultValue", "urn:schemas-microsoft-com:xml-msdata", ((bool) col.DefaultValue) ? "true" : "false");
             }
             else
             {
                 ValidateColumnMapping(col.DataType);
                 root.SetAttribute("DefaultValue", "urn:schemas-microsoft-com:xml-msdata", col.ConvertObjectToXml(col.DefaultValue));
             }
         }
     }
     if (!col.DefaultValueIsNull && (col.ColumnMapping != MappingType.Hidden))
     {
         ValidateColumnMapping(col.DataType);
         if ((col.ColumnMapping == MappingType.Attribute) && !col.AllowDBNull)
         {
             if (col.DataType == typeof(bool))
             {
                 root.SetAttribute("DefaultValue", "urn:schemas-microsoft-com:xml-msdata", ((bool) col.DefaultValue) ? "true" : "false");
             }
             else
             {
                 root.SetAttribute("DefaultValue", "urn:schemas-microsoft-com:xml-msdata", col.ConvertObjectToXml(col.DefaultValue));
             }
         }
         else if (col.DataType == typeof(bool))
         {
             root.SetAttribute("default", ((bool) col.DefaultValue) ? "true" : "false");
         }
         else if (!col.IsCustomType)
         {
             root.SetAttribute("default", col.ConvertObjectToXml(col.DefaultValue));
         }
     }
     if (this.schFormat == SchemaFormat.Remoting)
     {
         root.SetAttribute("targetNamespace", "urn:schemas-microsoft-com:xml-msdata", col.Namespace);
     }
     else if ((col.Namespace != (col.Table.TypeName.IsEmpty ? col.Table.Namespace : col.Table.TypeName.Namespace)) && (col.Namespace.Length != 0))
     {
         XmlElement node = this.GetSchema(col.Namespace);
         if (this.FindTypeNode(node, col.EncodedColumnName) == null)
         {
             node.AppendChild(root);
         }
         root = this._dc.CreateElement("xs", localName, "http://www.w3.org/2001/XMLSchema");
         root.SetAttribute("ref", this.prefixes[col.Namespace] + ":" + col.EncodedColumnName);
         if (col.Table.Namespace != this._ds.Namespace)
         {
             string text1 = (string) this.prefixes[col.Namespace];
             this.GetSchema(col.Table.Namespace);
         }
     }
     int num = col.AllowDBNull ? 0 : 1;
     if ((col.ColumnMapping == MappingType.Attribute) && (num != 0))
     {
         root.SetAttribute("use", "required");
     }
     if (col.ColumnMapping == MappingType.Hidden)
     {
         root.SetAttribute("use", "prohibited");
     }
     else if ((col.ColumnMapping != MappingType.Attribute) && (num != 1))
     {
         root.SetAttribute("minOccurs", num.ToString(CultureInfo.InvariantCulture));
     }
     if ((col.ColumnMapping == MappingType.Element) && fWriteOrdinal)
     {
         root.SetAttribute("Ordinal", "urn:schemas-microsoft-com:xml-msdata", col.Ordinal.ToString(CultureInfo.InvariantCulture));
     }
     return root;
 }
        /// <summary>
        /// Devuelve el valor pasado por el parámetro sValorCampo formateado dependiendo del tipo 
        /// de datos para asignarlo como valor a un campo en una SQL.
        /// </summary>
        /// <param name="sTipoCampo">
        /// Tipo de datos del campo
        /// </param>
        /// <param name="sValorCampo">
        /// Valor que se devolverá formateado
        /// </param>
        /// <returns></returns>
        private String GetFormatoCampo(DataColumn sTipoCampo, String sValorCampo)
        {
            switch (sTipoCampo.GetType().ToString())
            {
                case "System.String":
                    if (String.IsNullOrEmpty(sValorCampo))
                        sValorCampo = "";

                    break;

                case "System.DateTime":
                    if (ClsGeneral.IsDate(sValorCampo) )
                        sValorCampo = DateTime.Parse(sValorCampo).ToString();
                    else
                        sValorCampo = "";

                    break;

                case "System.Decimal":
                    if (ClsGeneral.IsNumeric(sValorCampo) )
                        //convierte la coma en punto
                        sValorCampo = sValorCampo.Replace(",", ".");
                    else
                        sValorCampo = "0";

                    break;

                case "System.Int16":case "System.Int32":case "System.Int64":
                    if (ClsGeneral.IsNumeric(sValorCampo))
                        //si viene con decimales se los quita
                        sValorCampo = int.Parse(sValorCampo).ToString();
                    else
                        sValorCampo = "0";

                   break;

                case  "System.Double":
                    if (ClsGeneral.IsNumeric(sValorCampo))
                        sValorCampo = sValorCampo.Replace(",", ".");
                    else
                        sValorCampo = "0";

                    break;
                default:
                    //----------- NO COMENTAR ESTAS LINEAS -----------
                    //hay que definir el tipo de datos del campo para mayor seguridad
                    System.Windows.Forms.MessageBox.Show("El tipo de datos no esta definido en ClsTableStructure.");
                    break;

            //devuelve el valor entre comillas (si es varchar o datetime) y reemplazando todas las comillas simples por dobles

            }
            return sValorCampo;
        }
Exemplo n.º 7
0
 /// <summary>
 /// 打印 DataColumn .
 /// </summary>
 /// <param name="sb">输出缓冲区.</param>
 /// <param name="indent">缩进.</param>
 /// <param name="obj">对象.</param>
 public static void PrintDataColumn(StringBuilder sb, int indent, DataColumn obj)
 {
     int indentnext = indent + 1;
     String indentstr = GetIndentStr(indent);
     sb.AppendLine(string.Format("{0}# <{1}>", indentstr, obj.GetType().FullName));
     sb.AppendLine(string.Format("{0}AllowDBNull:\t{1}", indentstr, obj.AllowDBNull));
     sb.AppendLine(string.Format("{0}AutoIncrement:\t{1}", indentstr, obj.AutoIncrement));
     sb.AppendLine(string.Format("{0}AutoIncrementSeed:\t{1}", indentstr, obj.AutoIncrementSeed));
     sb.AppendLine(string.Format("{0}AutoIncrementStep:\t{1}", indentstr, obj.AutoIncrementStep));
     sb.AppendLine(string.Format("{0}Caption:\t{1}", indentstr, obj.Caption));
     sb.AppendLine(string.Format("{0}ColumnMapping:\t{1}", indentstr, obj.ColumnMapping));
     sb.AppendLine(string.Format("{0}ColumnName:\t{1}", indentstr, obj.ColumnName));
     sb.AppendLine(string.Format("{0}DataType:\t{1}", indentstr, obj.DataType));
     sb.AppendLine(string.Format("{0}DateTimeMode:\t{1}", indentstr, obj.DateTimeMode));
     sb.AppendLine(string.Format("{0}DefaultValue:\t{1}", indentstr, obj.DefaultValue));
     sb.AppendLine(string.Format("{0}Expression:\t{1}", indentstr, obj.Expression));
     sb.AppendLine(string.Format("{0}MaxLength:\t{1}", indentstr, obj.MaxLength));
     sb.AppendLine(string.Format("{0}Namespace:\t{1}", indentstr, obj.Namespace));
     sb.AppendLine(string.Format("{0}Ordinal:\t{1}", indentstr, obj.Ordinal));
     sb.AppendLine(string.Format("{0}Prefix:\t{1}", indentstr, obj.Prefix));
     sb.AppendLine(string.Format("{0}ReadOnly:\t{1}", indentstr, obj.ReadOnly));
     sb.AppendLine(string.Format("{0}Unique:\t{1}", indentstr, obj.Unique));
     sb.AppendLine(string.Format("{0}ExtendedProperties:\t{1}", indentstr, obj.ExtendedProperties));
     PrintPropertyCollection(sb, indentnext, obj.ExtendedProperties);
 }