private static void assignDeletePriority(string TableName, int Priority, System.Data.DataTable Tables, System.Data.DataTable TableConstraints, System.Data.DataTable ReferentialConstraints) { System.Data.DataRow TableRow = Tables.Select("TABLE_NAME = '" + TableName + "'")[0]; if ((TableRow.IsNull("DELETE_PRIORITY")) || (Priority < Convert.ToInt32(TableRow["DELETE_PRIORITY"]))) { TableRow["DELETE_PRIORITY"] = Priority; } System.Data.DataRow[] TableConstraint = TableConstraints.Select("CONSTRAINT_TYPE = 'PRIMARY KEY' and TABLE_NAME = '" + TableName + "'"); if (TableConstraint.Length == 0) { return; } string UniqueConstraintName = (string)TableConstraint[0]["CONSTRAINT_NAME"]; System.Data.DataRow[] ParentRelations = ReferentialConstraints.Select("UNIQUE_CONSTRAINT_NAME = '" + UniqueConstraintName + "'"); for (int i = 0; i < ParentRelations.Length; i++) { System.Data.DataRow[] ChildRelations = TableConstraints.Select("CONSTRAINT_TYPE = 'FOREIGN KEY' and CONSTRAINT_NAME = '" + ParentRelations[i]["CONSTRAINT_NAME"] + "'"); // Only in case of self reference? if (ChildRelations.Length == 0) { continue; } // protect infinite recursion in case of self reference if (((string)ChildRelations[0]["TABLE_NAME"]).Equals(TableName)) { continue; } string ChildTableName = (string)ChildRelations[0]["TABLE_NAME"]; assignInsertPriority(ChildTableName, Priority + 1, Tables, TableConstraints, ReferentialConstraints); } }
/// <summary> /// Retorna o objeto da coluna selecionada /// </summary> public static T GetValue <T>(this System.Data.DataRow dr, String columnName) { if (dr == null) { return(default(T)); } if (String.IsNullOrEmpty(columnName)) { return(default(T)); } if (!dr.Table.Columns.Contains(columnName)) { throw new ArgumentOutOfRangeException(columnName, "Esta coluna (" + columnName + ") não existe na tabela."); } if (dr.IsNull(columnName)) { return(default(T)); } int index = dr.Table.Columns.IndexOf(columnName); return((index < 0 || index > dr.ItemArray.Count()) ? default(T) : (T)dr[index]); }
public DateTime GetDateTime(System.Data.DataRow row, string field) { if (row.IsNull(field)) { return(new DateTime()); } return((DateTime)row[field]); }
private static void DataRow2ObjectByObject(System.Data.DataRow dr, object ob) { if (dr == null) { return; } String obName = ob.GetType().Name; bool written = false; foreach (System.Reflection.PropertyInfo pInfo in ob.GetType().GetProperties()) { try { if (!pInfo.CanWrite) { continue; } System.Reflection.MethodInfo mInfo = pInfo.GetSetMethod(false); if (mInfo == null) { continue; } if (!dr.Table.Columns.Contains(pInfo.Name)) { if (!written) { System.Diagnostics.Debug.WriteLine(obName); written = true; } System.Diagnostics.Debug.WriteLine("Columns Not found: " + pInfo.Name); continue; } if (dr.IsNull(pInfo.Name)) { continue; } object v = dr[pInfo.Name]; if ((v == null) || (v == DBNull.Value)) { continue; } pInfo.SetValue(ob, dr[pInfo.Name], null); if (pInfo.Name == "IsDirty" || pInfo.Name == "IsDeleted") { pInfo.SetValue(ob, false, null); } } catch (Exception ex) { if (!written) { System.Diagnostics.Debug.WriteLine(obName); written = true; } System.Diagnostics.Debug.WriteLine(pInfo.Name + " Exception: " + ex.Message); } } }
public bool ValorBool(System.Data.DataRow row, string field) { if (row.IsNull(field)) { return(false); } return(true); }
public void CheckPrice() { System.Data.DataRow row = ((System.Data.DataRowView)_colView.CurrentItem).Row; if (row.IsNull("amount") || double.Parse(row["amount"].ToString()) <= 0) { if (row.IsNull("pricing_opt") || int.Parse(row["pricing_opt"].ToString()) != 3) { row.SetColumnError("amount", "Enter price"); } else { row.SetColumnError("amount", ""); } } else { row.SetColumnError("amount", ""); } }
//ใช้ผ่าน method เดียวกับ web service แทน //protected void loadMenu2() //{ // FormsAuthenticationTicket authTicket = getAuthTicket(); // if (null != authTicket) // { // System.Data.DataView dv = (System.Data.DataView)SqlDS_Menu.Select(DataSourceSelectArguments.Empty); // List<MenuModel> mainMenus = new List<MenuModel>(); // List<MenuModel> subMenus = new List<MenuModel>(); // System.Data.DataRow[] mainMenu = dv.Table.Select("MENU_PARENT_KEY IS NULL", "MENU_PRIORITY ASC"); // System.Data.DataRow[] subMenu = dv.Table.Select("MENU_PARENT_KEY IS NOT NULL", "MENU_PRIORITY ASC"); // StringBuilder builder = new StringBuilder(); // for (int i = 0; i < mainMenu.Length; i++) // { // MenuModel mainMenuModel = bindModel(mainMenu[i]); // mainMenus.Add(mainMenuModel); // builder.Append(buildMainMenuString(mainMenuModel)); // } // Literal_MM.Text = builder.ToString(); // for (int i = 0; i < subMenu.Length; i++) // { // MenuModel subMenuModel = bindModel(subMenu[i]); // subMenus.Add(subMenuModel); // //วนลูป mainMenu เพื่อหา MenuRel ที่ตรงกับ MenuParentKey // for (int j = 0; j < mainMenus.Count; j++) // { // if (subMenuModel.menuParentKey.Equals(mainMenus[j].menuKey)) // { // //เช็คว่า menuRel มีค่าหรือไม่ // if (mainMenus[j].menuRel != null) // { // System.Xml.XmlDocument subMenuXml = new System.Xml.XmlDocument(); // //load xml ของ sub menu มา // if (!Literal_MS.Text.Equals(string.Empty)) // { // subMenuXml.LoadXml(Literal_MS.Text); // } // System.Xml.XmlNode xmlNode = subMenuXml.SelectSingleNode("//div[@id=\"" + mainMenus[j].menuRel + "\"]"); // System.Xml.XmlElement aElement = subMenuXml.CreateElement("a"); // aElement.SetAttribute("id", "Link_" + subMenuModel.menuKey.ToString()); // aElement.SetAttribute("title", subMenuModel.menuTooltip); // if (subMenuModel.menuTarget == null) // { // aElement.SetAttribute("rel", subMenuModel.menuRel); // } // else // { // aElement.SetAttribute("target", subMenuModel.menuTarget); // } // //check ว่ามี popup หรือไม่ // if (subMenuModel.menuPopupOption != null) // { // aElement.SetAttribute("onclick", "openPopup('menu_" + subMenuModel.menuKey + "_Popup', '" // + Page.ResolveUrl(subMenuModel.menuUrl) + "', false, '" + subMenuModel.menuPopupOption + "');"); // aElement.SetAttribute("href", MenuModel.defaultUrl); // } // else // { // //ไม่มี popup set href // aElement.SetAttribute("href", subMenuModel.menuUrl); // } // aElement.InnerText = subMenuModel.menuTitle; // xmlNode.AppendChild(aElement); // Literal_MS.Text = subMenuXml.InnerXml; // } // //ถ้าเจอที่ตรงกันแล้ว set sub menu เสร็จก็ break ได้เลย // break; // } // } // } // //add start script // builder = new StringBuilder(); // builder.Append("<script type=\"text/javascript\">cssdropdown.startchrome(\"chromemenu\");</script>"); // //add sub menu and start script // Literal_MS.Text = Literal_MS.Text + builder.ToString(); // } //} protected Object getDbValue(System.Data.DataRow dr, string columnName) { Object result = null; if (!dr.IsNull(columnName)) { result = dr[columnName]; } return(result); }
public bool GetBool(System.Data.DataRow row, string field) { try { return(row.IsNull(field) ? false : (bool)row[field]); } catch (ArgumentException ex) { return(false); } }
public String GetString(System.Data.DataRow row, string field) { try { return(row.IsNull(field) ? null : (string)row[field]); } catch (ArgumentException ex) { return(null); } }
protected MenuModel bindModel(System.Data.DataRow dr) { MenuModel menu = new MenuModel(); if (!dr.IsNull("MENU_KEY")) { menu.menuKey = (int)getDbValue(dr, "MENU_KEY"); } if (!dr.IsNull("MENU_TITLE")) { menu.menuTitle = (string)getDbValue(dr, "MENU_TITLE"); } if (!dr.IsNull("MENU_URL")) { menu.menuUrl = Page.ResolveUrl((string)getDbValue(dr, "MENU_URL")); } if (!dr.IsNull("MENU_POPUP_OPT")) { menu.menuPopupOption = (string)getDbValue(dr, "MENU_POPUP_OPT"); } if (!dr.IsNull("MENU_REL")) { menu.menuRel = (string)getDbValue(dr, "MENU_REl"); } if (menu.menuRel == null) { menu.menuTarget = "_self"; } if (!dr.IsNull("MENU_TOOLTIP")) { menu.menuTooltip = (string)getDbValue(dr, "MENU_TOOLTIP"); } if (!dr.IsNull("MENU_PRIORITY")) { menu.menuPriority = (int)getDbValue(dr, "MENU_PRIORITY"); } if (!dr.IsNull("MENU_PARENT_KEY")) { menu.menuParentKey = (int)getDbValue(dr, "MENU_PARENT_KEY"); } return(menu); }
public static string Translate(this System.Data.DataRow dr, string column, atriumBE.FileManager fm) { string colnm = fm.AtMng.Translate(column); if (dr.IsNull(colnm)) { return(""); } else { return(dr[colnm].ToString()); } }
private object GetFieldValue(AutoGeneratedFieldProperties property, object obj, RecordField field, System.Data.DataRow dataRow) { if (field != null && field.ServerMapping.IsNotEmpty()) { string[] mapping = field.ServerMapping.Split('.'); if (mapping.Length > 1) { for (int i = 0; i < mapping.Length; i++) { if (dataRow != null && dataRow.IsNull(mapping[i])) { return(null); } PropertyInfo p = obj.GetType().GetProperty(mapping[i]); try { obj = p.GetValue(obj, null); } catch (NullReferenceException e) { throw new NullReferenceException(String.Format("Mapped property '{0}' doesn't exist", mapping[i])); } if (obj == null) { return(null); } } return(obj); } } return((dataRow != null && dataRow.IsNull(property.DataField)) ? null : DataBinder.GetPropertyValue(obj, property.DataField)); }
/// <summary> /// Map a DataRow to a Permission Entity. /// </summary> /// <returns></returns> public static Permission Row2Entity(System.Data.DataRow row) { if (row == null) { return(null); } Permission entity = new Permission(); if (!row.IsNull("PERM_ID")) { entity._permissionId = (int)(row["PERM_ID"]); } if (!row.IsNull("OPT_ID")) { entity._operationId = (int)(row["OPT_ID"]); } if (!row.IsNull("PERM_TYPE")) { entity._type = (PermissionType)Enum.Parse(typeof(PermissionType), (row["PERM_TYPE"]).ToString()); } if (!row.IsNull("USR_ID")) { entity._userId = (int)(row["USR_ID"]); } if (!row.IsNull("UGP_ID")) { entity._groupId = (int)(row["UGP_ID"]); } if (!row.IsNull("PERM_ALLOW")) { entity._isAllow = (bool)(row["PERM_ALLOW"]); } if (!row.IsNull("CREATE_TIME")) { entity._createTime = (DateTime)(row["CREATE_TIME"]); } if (!row.IsNull("CREATE_BY")) { entity._createBy = (int)(row["CREATE_BY"]); } return(entity); }
private void BindRecord(AutoGeneratedFieldProperties[] autoFieldProperties, StringBuilder sb, object obj) { sb.Append("{"); System.Data.DataRow dataRow = obj as System.Data.DataRow; foreach (AutoGeneratedFieldProperties property in autoFieldProperties) { FieldInReader field = this.IsInReader(property.DataField); if (this.IgnoreExtraFields && !field.InReader) { continue; } if (field.Fields != null && field.Fields.Count > 0) { foreach (RecordField recordField in field.Fields) { object value = this.GetFieldValue(property, obj, recordField, dataRow); if (value != null && value.GetType().IsEnum&& recordField.Type == RecordFieldType.Int) { value = (int)value; } sb.AppendFormat("{0}:{1},", JSON.Serialize(string.IsNullOrEmpty(recordField.Mapping) ? recordField.Name : recordField.Mapping), JSON.Serialize(value)); } } else { if (dataRow == null || !dataRow.IsNull(property.DataField)) { sb.AppendFormat("{0}:{1},", JSON.Serialize(property.DataField), JSON.Serialize(DataBinder.GetPropertyValue(obj, property.DataField))); } } } RemoveLastComma(sb); sb.Append("},"); }
/// <summary> /// Retorna o objeto da coluna selecionada /// </summary> public static Object GetValue(this System.Data.DataRow dr, String columnName, Object defaultValue = null) { if (dr == null) { return(defaultValue); } if (String.IsNullOrEmpty(columnName)) { return(defaultValue); } if (!dr.Table.Columns.Contains(columnName)) { throw new ArgumentOutOfRangeException(columnName, "Esta coluna (" + columnName + ") não existe na tabela."); } if (dr.IsNull(columnName)) { return(defaultValue); } return(dr[columnName]); }
/// <summary> /// Map a DataRow to a Operation Entity. /// </summary> /// <returns></returns> public static Operation Row2Entity(System.Data.DataRow row) { if (row == null) { return(null); } Operation entity = new Operation(); if (!row.IsNull("OPT_ID")) { entity._operationId = (int)(row["OPT_ID"]); } if (!row.IsNull("PARENT_ID")) { entity._parentId = (int)(row["PARENT_ID"]); } if (!row.IsNull("OPT_NAME")) { entity._name = (string)(row["OPT_NAME"]); } if (!row.IsNull("OPT_TYPE")) { entity._type = (OperationType)Enum.Parse(typeof(OperationType), (row["OPT_TYPE"]).ToString()); } if (!row.IsNull("OPT_DESC")) { entity._description = (string)(row["OPT_DESC"]); } if (!row.IsNull("OPT_ENTRY")) { entity._entry = Cast.String(row["OPT_ENTRY"]); } entity._seqNo = Cast.Int(row["OPT_SEQNUM"]); entity._image = Cast.String(row["OPT_IMAGE"]); entity._level = Cast.Int(row["OPT_LEVEL"]); return(entity); }
public double Getdbl(System.Data.DataRow row, string field) { return(row.IsNull(field) ? 0 : (double)row[field]); }
/// <summary> /// Map a DataRow to a User Entity. /// </summary> /// <returns></returns> public static User Row2Entity(System.Data.DataRow row) { if (row == null) { return(null); } User entity = new User(); if (!row.IsNull("USR_ID")) { entity._userId = (int)(row["USR_ID"]); } if (!row.IsNull("USR_LOGIN_ID")) { entity._userName = (string)(row["USR_LOGIN_ID"]); } if (!row.IsNull("USR_PSW")) { entity._password = (string)(row["USR_PSW"]); } if (!row.IsNull("USR_NAME")) { entity._fullName = (string)(row["USR_NAME"]); } if (!row.IsNull("USR_TYPE")) { entity._userType = (OrgType)Enum.Parse(typeof(OrgType), (row["USR_TYPE"]).ToString()); } if (!row.IsNull("USR_EMAIL")) { entity._email = (string)(row["USR_EMAIL"]); } if (!row.IsNull("USR_GENDER")) { entity._gender = (bool)(row["USR_GENDER"]); } if (!row.IsNull("USR_WORK_NUM")) { entity._employeeNo = (string)(row["USR_WORK_NUM"]); } if (!row.IsNull("USR_EXT")) { entity._ext = (string)(row["USR_EXT"]); } if (!row.IsNull("USR_MOBILE")) { entity._mobile = (string)(row["USR_MOBILE"]); } if (!row.IsNull("USR_HOME_PHONE")) { entity._homePhone = (string)(row["USR_HOME_PHONE"]); } if (!row.IsNull("USR_HOME_ADDR")) { entity._homeAddress = (string)(row["USR_HOME_ADDR"]); } if (!row.IsNull("USR_BIRTHDAY")) { entity._birthday = (DateTime)(row["USR_BIRTHDAY"]); } if (!row.IsNull("USR_NOTE")) { entity._note = (string)(row["USR_NOTE"]); } if (!row.IsNull("USR_STATUS")) { entity._status = (UserStatus)Enum.Parse(typeof(UserStatus), (row["USR_STATUS"]).ToString()); } if (!row.IsNull("ORG_ID")) { entity._orgId = (int)(row["ORG_ID"]); } if (!row.IsNull("LAST_LOGIN")) { entity._lastLogonTime = (DateTime)(row["LAST_LOGIN"]); } if (!row.IsNull("CREATE_TIME")) { entity._createTime = (DateTime)(row["CREATE_TIME"]); } if (!row.IsNull("CREATE_BY")) { entity._createBy = (int)(row["CREATE_BY"]); } if (!row.IsNull("MODIFY_BY")) { entity._modifyBy = (int)(row["MODIFY_BY"]); } if (!row.IsNull("MODIFY_TIME")) { entity._modifyTime = (DateTime)(row["MODIFY_TIME"]); } return(entity); }
public float GetFloat(System.Data.DataRow row, string field) { return(row.IsNull(field) ? 0 : (float)row[field]); }
private void DecodeFieldList() { SPFieldDefinitionCollection oTemplateFields = SPFieldListTemplates.GetTemplateFieldList(this.ServerTemplate); _Fields = new SPFieldDefinitionCollection(); _Fields.AddRange(SPFieldListTemplates.GetBasicFieldList(this.ListType)); // add the default definitions available no matter the list template. if (_ListData.IsNull("Fields")) { // the field definition is NULL, that means no customization has been applied to the server template for this list. // // We get the default field definitions for the list template. _Fields.AddRange(oTemplateFields); } else { // the field definitions are specified, that means the default server template has been override with custom metadata. // there 2 main node types for field definitions. // FieldRef and Field. I understood that FieldRef maps to a server template default definition and // Field is a custom definition. // For each fieldref, we try to get its definition from the template field definitions. // for each field, we are going to create a new instance of field definition based on the element attributes. System.Xml.XmlDocument oDoc = null; string sXML = "<Fields>" + _ListData["Fields"].ToString() + "</Fields>"; //note: for an unknown reason, oDoc.LoadXml fails in debug (within the VS IDE) // I get rid of the error by freeing memory (closing other opened application). // That piss me off and I discovered that when using an XmlReader it does not generate this error... oDoc = new System.Xml.XmlDocument(); System.IO.StringReader oXmlReader = new System.IO.StringReader(sXML); oDoc.Load(oXmlReader); System.Xml.XmlNodeList oNodes = oDoc.SelectNodes("Fields/*"); if (oNodes != null) { foreach (System.Xml.XmlElement oFieldXmlNode in oNodes) { SPFieldDefinition oDefinition = null; string sAttributeValue = null; switch (oFieldXmlNode.Name) { case "Field": if (oFieldXmlNode.GetAttribute("Type") == "URL") { oDefinition = new SPUrlFieldDefinition( oFieldXmlNode.GetAttribute("DisplayName"), oFieldXmlNode.GetAttribute("Name"), new string[] { oFieldXmlNode.GetAttribute("ColName"), oFieldXmlNode.GetAttribute("ColName2") }); } else if (oFieldXmlNode.GetAttribute("ColName").Length != 0) { oDefinition = new SPFieldDefinition( oFieldXmlNode.GetAttribute("DisplayName"), oFieldXmlNode.GetAttribute("Name"), oFieldXmlNode.GetAttribute("ColName")); } break; case "FieldRef": sAttributeValue = oFieldXmlNode.GetAttribute("ColName"); string sName = oFieldXmlNode.GetAttribute("Name"); if (sAttributeValue != null && sAttributeValue.Length > 0) { // we have a ColName value, we use it. string sDisplayName = sName.Replace("_x0020_", " "); oDefinition = new SPFieldDefinition(sDisplayName, sName, sAttributeValue); } else { // we do not have a ColName value. // we search the server template definition to get the default column mapping oDefinition = oTemplateFields.FindByInternalName(sName); } break; } if (oDefinition != null && _Fields.FindByInternalName(oDefinition.InternalName) == null) { _Fields.Add(oDefinition); } } } } }
public long GetLng(System.Data.DataRow row, string field) { return(row.IsNull(field) ? 0 : (long)row[field]); }
public decimal GetDcm(System.Data.DataRow row, string field) { return(row.IsNull(field) ? 0 : (decimal)row[field]); }
public bool IsNull(int ordinal) { return(NativeRow.IsNull(ordinal)); }
public int GetInt(System.Data.DataRow row, string field) { return(row.IsNull(field) ? 0 : (int)row[field]); }