private void MainGridView_CellEnter(object sender, DataGridViewCellEventArgs e) { mainview.Sort = "cod_pr, cod_postsh, data"; Object[] cod = new object[3]; cod[0] = MainGridView.CurrentRow.Cells["cod_pr"].Value; cod[1] = MainGridView.CurrentRow.Cells["cod_postsh"].Value; cod[2] = MainGridView.CurrentRow.Cells["data"].Value; DataRow r = mainview[mainview.Find(cod)].Row; if (is_error_handling) { textBox1.Text = r.RowError; } if (r.RowState == DataRowState.Modified) { selectedview.RowFilter = "cod_pr = " + cod[0] + " and cod_postsh = " + cod[1] + " and data = '" + cod[2] + "'"; SelectedGridView.Columns["cod_pr"].Visible = false; SelectedGridView.Columns["cod_postsh"].Visible = false; //SelectedGridView.Columns["nazv"].HeaderText = "Исполнитель"; panel1.Visible = true; } else { panel1.Visible = false; } }
protected void AnalizaClickLocalizaciones() { string strLocalizacion = ListaTerritoriosProvincia.SelectedItem.Text; DataView Visor = (DataView)SQLLocalizacionesRegistradas.Select(DataSourceSelectArguments.Empty); Visor.Sort = "Localizacion ASC"; int index = Visor.Find(strLocalizacion); int index2 = Visor.Find(strLocalizacion); SeccionProvincia.Visible = true; if (index > -1) { String strProvincia = Visor[index]["Provincia"].ToString(); index2 = ListaProvinciadelTerritorio.Items.IndexOf(ListaProvinciadelTerritorio.Items.FindByText(strProvincia)); if (index2 > -1) { ListaProvinciadelTerritorio.Items.RemoveAt(index2); ListaProvinciadelTerritorio.Items.Insert(0, strProvincia); ListaProvinciadelTerritorio.SelectedIndex = 0; } else { ListaProvinciadelTerritorio.SelectedIndex = -1; } } else { ListaProvinciadelTerritorio.SelectedIndex = -1; } }
private void MainGridView_CellEnter(object sender, DataGridViewCellEventArgs e) { mainview.Sort = "cod_zap"; DataRow r = mainview[mainview.Find(MainGridView.CurrentRow.Cells["cod_zap"].Value)].Row; if (is_error_handling) { textBox1.Text = r.RowError; } if (r.RowState == DataRowState.Modified) { selectedview.RowFilter = "cod_zap=" + MainGridView.CurrentRow.Cells["cod_zap"].Value.ToString(); SelectedGridView.Rows[0].Cells["Isp"].Value = dataSet.Ispolnitel. FindBycod_isp((int)SelectedGridView.CurrentRow.Cells["cod_isp"].Value).naim; SelectedGridView.Rows[0].Cells["Janr"].Value = dataSet.Janr. FindBycod_janr((int)SelectedGridView.CurrentRow.Cells["cod_janr"].Value).naim; SelectedGridView.Rows[0].Cells["Sotr"].Value = dataSet.Sotrudnik. FindBycod_sotr((int)SelectedGridView.CurrentRow.Cells["cod_sotr"].Value).fam; panel1.Visible = true; } else { panel1.Visible = false; } }
private void MainGridView_CellEnter(object sender, DataGridViewCellEventArgs e) { mainview.Sort = "cod_sotr"; int cod = (int)MainGridView.CurrentRow.Cells["cod_sotr"].Value; DataRow r = mainview[mainview.Find(cod)].Row; if (is_error_handling) { textBox1.Text = r.RowError; } if (r.RowState == DataRowState.Modified) { selectedview.RowFilter = "cod_sotr=" + cod; SelectedGridView.Columns["cod_sotr"].Visible = false; SelectedGridView.Columns["fam"].HeaderText = "Фамилия"; SelectedGridView.Columns["im"].HeaderText = "Имя"; SelectedGridView.Columns["otch"].HeaderText = "Отчество"; SelectedGridView.Columns["dr"].HeaderText = "День рождения"; SelectedGridView.Columns["pol"].HeaderText = "Пол"; panel1.Visible = true; } else { panel1.Visible = false; } }
private void PostavkiExtra_Load(object sender, EventArgs e) { currentview.Table = dataset.postavki; currentview.RowStateFilter = DataViewRowState.CurrentRows; editedview.Table = dataset.postavki; editedview.RowStateFilter = DataViewRowState.Added | DataViewRowState.Deleted | DataViewRowState.ModifiedOriginal; CurrentGridView.DataSource = currentview; CurrentGridView.AutoResizeColumns(); EditedGridView.DataSource = editedview; EditedGridView.Columns.Add("RowState", "RowState"); EditedGridView.Columns["RowState"].DisplayIndex = 0; editedview.Sort = "pc, pr, data"; for (int i = 0; i < EditedGridView.Rows.Count; i++) { object[] temp = new object[] { EditedGridView.Rows[i].Cells["pc"].Value, EditedGridView.Rows[i].Cells["pr"].Value, EditedGridView.Rows[i].Cells["data"].Value }; EditedGridView.Rows[i].Cells["RowState"].Value = editedview[editedview.Find(temp)].Row.RowState.ToString(); } EditedGridView.AutoResizeColumns(); if (currentview.Count == 0) { Delbutton.Enabled = false; } if (editedview.Count == 0) { Cancelbutton.Enabled = false; } }
// class to read and fetch xmls for currency and account type. xml can further be modified without changing the class. public string Get_Account_Type(string type) { string acc_type = ""; XmlReader xmlFile; xmlFile = XmlReader.Create("Type.xml", new XmlReaderSettings()); DataSet ds = new DataSet(); DataView dv; ds.ReadXml(xmlFile); dv = new DataView(ds.Tables[0]); dv.Sort = "code"; int index = dv.Find(type); if (index == -1) { dv.Sort = "account_type"; int index1 = dv.Find(type); if (index1 >= 0) { acc_type = dv[index]["code"].ToString(); } } else { acc_type = dv[index]["type"].ToString(); } return(acc_type); }
public new void OneTimeSetup() { ConnectionStringBlogContext = $"{ConfigurationManager.ConnectionStrings["BlogsContext"].ConnectionString}port={Port}"; configuration = new Configuration(); DataSet dataSet = ConfigurationManager.GetSection("system.data") as System.Data.DataSet; if (dataSet != null) { DataView vi = dataSet.Tables[0].DefaultView; vi.Sort = "Name"; int idx = -1; if (((idx = vi.Find("MySql")) != -1) || ((idx = vi.Find("MySQL Data Provider")) != -1)) { DataRow row = vi[idx].Row; dataSet.Tables[0].Rows.Remove(row); } dataSet.Tables[0].Rows.Add("MySql" , "MySql.Data.MySqlClient" , "MySql.Data.MySqlClient" , typeof(MySql.Data.MySqlClient.MySqlClientFactory).AssemblyQualifiedName); } Migrator = new DbMigrator(configuration); }
public string Get_Currency(string cur) { string cur_type = ""; XmlReader xmlFile; xmlFile = XmlReader.Create("Type.xml", new XmlReaderSettings()); DataSet ds = new DataSet(); DataView dv; ds.ReadXml(xmlFile); dv = new DataView(ds.Tables[1]); dv.Sort = "ccode"; int index = dv.Find(cur); if (index == -1) { dv.Sort = "ctype"; int index1 = dv.Find(cur); if (index1 >= 0) { cur_type = dv[index]["ctype"].ToString(); } } else { cur_type = dv[index]["ctype"].ToString(); } return(cur_type); }
public void Find_ByObject() { int FindResult, ExpectedResult = -1; //create the source datatable DataTable dt = DataProvider.CreateParentDataTable(); //create the dataview for the table DataView dv = new DataView(dt); for (int i = 0; i < dt.Rows.Count; i++) { if ((int)dt.Rows[i]["ParentId"] == 3) { ExpectedResult = i; break; } } // Find ,no sort - exception Assert.Throws <ArgumentException>(() => { FindResult = dv.Find("3"); }); dv.Sort = "String1"; // Find = wrong sort, can not find FindResult = dv.Find("3"); Assert.Equal(-1, FindResult); dv.Sort = "ParentId"; // Find FindResult = dv.Find("3"); Assert.Equal(ExpectedResult, FindResult); }
public new void OneTimeSetup() { // Override sql_mode so it converts automatically from varchar(65535) to text MySqlCommand cmd = new MySqlCommand("SET GLOBAL SQL_MODE=``", Connection); cmd.ExecuteNonQuery(); // Replace existing listeners with listener for testing. Trace.Listeners.Clear(); Trace.Listeners.Add(this.asertFailListener); DataSet dataSet = ConfigurationManager.GetSection("system.data") as DataSet; if (dataSet != null) { DataView vi = dataSet.Tables[0].DefaultView; vi.Sort = "Name"; int idx = -1; if (((idx = vi.Find("MySql")) != -1) || ((idx = vi.Find("MySQL Data Provider")) != -1)) { DataRow row = vi[idx].Row; dataSet.Tables[0].Rows.Remove(row); } dataSet.Tables[0].Rows.Add("MySql" , "MySql.Data.MySqlClient" , "MySql.Data.MySqlClient" , typeof(MySqlClientFactory).AssemblyQualifiedName); } cmd = new MySqlCommand("SELECT COUNT(SCHEMA_NAME) FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME = 'sakila'", Connection); if (Convert.ToInt32(cmd.ExecuteScalar() ?? 0) == 0) { Assembly executingAssembly = Assembly.GetExecutingAssembly(); using (var stream = executingAssembly.GetManifestResourceStream("MySql.EntityFramework.CodeFirst.Tests.Properties.sakila-schema.sql")) { using (StreamReader sr = new StreamReader(stream)) { string sql = sr.ReadToEnd(); MySqlScript s = new MySqlScript(Connection, sql); s.Execute(); } } using (var stream = executingAssembly.GetManifestResourceStream("MySql.EntityFramework.CodeFirst.Tests.Properties.sakila-data.sql")) { using (StreamReader sr = new StreamReader(stream)) { string sql = sr.ReadToEnd(); MySqlScript s = new MySqlScript(Connection, sql); s.Execute(); } } } }
/// <summary> /// Saves one specific changed User Default. /// /// </summary> /// <param name="AKey">The Key of the User Default that should get saved.</param> /// <returns>true if successful, false if not. /// </returns> public static Boolean SaveChangedUserDefault(String AKey) { Boolean ReturnValue; SUserDefaultsRow SubmittedUserDefaultRow; SUserDefaultsTable DesiredUserDefaultsDataTable; Int32 FoundInRow; ReturnValue = false; FoundInRow = UUserDefaults.Find(AKey); if (FoundInRow != -1) { // User default found // MessageBox.Show('Found changed User Default with RowState ''' + Enum(UUserDefaults.Item[FoundInRow].Row.RowState).ToString("G") + ''''); if ((UUserDefaults[FoundInRow].Row.RowState == DataRowState.Modified) || (UUserDefaults[FoundInRow].Row.RowState == DataRowState.Added)) { DesiredUserDefaultsDataTable = (SUserDefaultsTable)UUserDefaultsDataTable.Clone(); DesiredUserDefaultsDataTable.InitVars(); SubmittedUserDefaultRow = DesiredUserDefaultsDataTable.NewRowTyped(false); SubmittedUserDefaultRow.ItemArray = UUserDefaults[FoundInRow].Row.ItemArray; DesiredUserDefaultsDataTable.Rows.Add(SubmittedUserDefaultRow); if (UUserDefaults[FoundInRow].Row.RowState == DataRowState.Modified) { // Mark row as no longer beeing new SubmittedUserDefaultRow.AcceptChanges(); // Mark row as beeing changed SubmittedUserDefaultRow.DefaultValue = SubmittedUserDefaultRow.DefaultValue + ' '; SubmittedUserDefaultRow.AcceptChanges(); SubmittedUserDefaultRow.DefaultValue = SubmittedUserDefaultRow.DefaultValue.Substring(0, SubmittedUserDefaultRow.DefaultValue.Length - 1); } // MessageBox.Show('Saving single User Default ''' + DesiredUserDefaultsDataTable.Rows[0].Item['s_default_code_c'].ToString + ''''); TRemote.MSysMan.Maintenance.UserDefaults.WebConnectors.SaveUserDefaults(Ict.Petra.Shared.UserInfo.GUserInfo.UserID, ref DesiredUserDefaultsDataTable); // Copy over ModificationId that was changed on the Server side! UUserDefaults[FoundInRow].Row.ItemArray = DesiredUserDefaultsDataTable.Rows.Find( new Object[] { UUserDefaults[FoundInRow][0], UUserDefaults[FoundInRow][1] }).ItemArray; // Mark this User Default as saved (unchanged) UUserDefaults[FoundInRow].Row.AcceptChanges(); ReturnValue = true; } } else { ReturnValue = false; } return(ReturnValue); }
protected CMSMStruct.CompDeptStruct GetComDeptByCompName(string strCompName) { DataView dv = new DataView(SysInitial.dsSys.Tables["MebComp"]); dv.Sort = "cnvcCompanyName"; CMSMStruct.CompDeptStruct comd1 = new CMSMStruct.CompDeptStruct(); comd1.strCompanyID = dv[dv.Find(strCompName)]["cnvcCompanyID"].ToString().Trim(); comd1.strCompanyName = dv[dv.Find(strCompName)]["cnvcCompanyName"].ToString().Trim(); comd1.strDeptID = dv[dv.Find(strCompName)]["cnvcDeptID"].ToString().Trim(); comd1.strDeptName = dv[dv.Find(strCompName)]["cnvcDeptName"].ToString().Trim(); return(comd1); }
public static void SetDefault(String AKey, object AValue, Boolean ASendUpdateInfoToClient = true, TDataBase ADataBase = null) { SUserDefaultsTable UserDefaultsDataTable; TDataBase db = DBAccess.Connect("LoadUserDefaultsTable", ADataBase); TDBTransaction WriteTransaction = new TDBTransaction(); bool SubmitOK = false; db.WriteTransaction(ref WriteTransaction, ref SubmitOK, delegate { LoadUserDefaultsTable(UserInfo.GetUserInfo().UserID, out UserDefaultsDataTable, db); DataView view = new DataView(UserDefaultsDataTable); view.Sort = SUserDefaultsTable.GetDefaultCodeDBName(); int FoundInRow = view.Find(AKey); if (FoundInRow != -1) { // User default found if (AValue.ToString() != view[FoundInRow][SUserDefaultsTable.GetDefaultValueDBName()].ToString()) { // Update only if the value is actually different view[FoundInRow][SUserDefaultsTable.GetDefaultValueDBName()] = AValue.ToString(); SubmitOK = true; } } else { // User default not found, add it to the user defaults table SUserDefaultsRow row = UserDefaultsDataTable.NewRowTyped(); row.UserId = UserInfo.GetUserInfo().UserID; row.DefaultCode = AKey; row.DefaultValue = AValue.ToString(); UserDefaultsDataTable.Rows.Add(row); FoundInRow = view.Find(AKey); SubmitOK = true; } if (SubmitOK) { SUserDefaultsAccess.SubmitChanges(UserDefaultsDataTable, WriteTransaction); if (ASendUpdateInfoToClient) { UpdateUserDefaultsOnClient(UserInfo.GetUserInfo().UserID, AKey, AValue.ToString(), view[FoundInRow][SUserDefaultsTable.GetModificationIdDBName()].ToString()); } } }); }
protected void Page_Load(object sender, EventArgs e) { if (Session["inp"] == null) { Response.Redirect("inputLogin.aspx"); } if (Request.QueryString["mid"] == null) { Response.Redirect("assembly.aspx"); } lblmid.Text = Request.QueryString["mid"].ToString(); DataView dvplan = (DataView)(sdsplan.Select(DataSourceSelectArguments.Empty)); DataView dvphase = (DataView)(sdsphase.Select(DataSourceSelectArguments.Empty)); dvphase.Sort = "phaseORDER"; int x; for (int i = 0; i < dvplan.Table.Rows.Count; i++) { string coll = dvplan.Table.Rows[i]["date"].ToString(); string[] collarr = coll.Split(','); x = 0; foreach (string c in collarr) { TableRow tr = new TableRow(); tblplanning.Rows.Add(tr); TableCell c1 = new TableCell(); tr.Cells.Add(c1); TableCell c2 = new TableCell(); tr.Cells.Add(c2); if (x == 0) { c1.Text = dvphase.Table.Rows[dvphase.Find(dvplan.Table.Rows[i]["phase"])]["phaseNAME"].ToString(); c2.Text = dvphase.Table.Rows[dvphase.Find(dvplan.Table.Rows[i]["phase"])]["phaseDURATION"].ToString(); x = 1; } TableCell c3 = new TableCell(); tr.Cells.Add(c3); c3.Text = c; TableCell c4 = new TableCell(); tr.Cells.Add(c4); Button bdel = new Button(); bdel.Text = "REMOVE"; bdel.ID = dvplan.Table.Rows[i]["phase"].ToString() + "," + c; bdel.Click += Bdel_Click; bdel.CausesValidation = false; c4.Controls.Add(bdel); } } }
/// <summary> /// Returns true it item exists in gvItemList /// </summary> /// <param name="p"></param> /// <returns>True when item exists, False if item does not exist</returns> private bool IsItemInGrid(int p, string colName) { try { DataView dvItems = new DataView(); dvItems = (DataView)gvItemList.DataSource; if (dvItems != null) { dvItems.Sort = colName; Int32 rowId = -1; rowId = dvItems.Find(p); if (rowId != -1) { return(true); } else { return(false); } } else { return(false); } } catch (Exception ex) { throw ex; } }
void SetDisplay() { if (SearchDataSource == null) { return; } int _row = SearchDataSource.Find(_datavalue); Hashtable _result = new Hashtable(); if (_row > -1) { this.Text = SearchDataSource[_row][_displayfield].ToString(); for (int i = 0; i <= SearchDataSource.Table.Columns.Count - 1; i++) { _result.Add(SearchDataSource.Table.Columns[i].ColumnName, SearchDataSource[_row][i].ToString()); } _selectedvalue = _result; } else { this.Text = ""; } if (LookupComplete != null) { LookupComplete(_result); } _result = null; }
/// <summary> /// Получить имя пользователя по идентификатору. /// </summary> public string GetUserName(int userID) { try { dataCache.RefreshBaseTables(); BaseTables baseTables = dataCache.BaseTables; lock (baseTables.SyncRoot) { BaseTables.CheckColumnsExist(baseTables.UserTable, true); DataView viewUser = baseTables.UserTable.DefaultView; viewUser.Sort = "UserID"; int rowInd = viewUser.Find(userID); return(rowInd >= 0 ? (string)viewUser[rowInd]["Name"] : "[" + userID + "]"); // deleted or external user } } catch (Exception ex) { log.WriteException(ex, Localization.UseRussian ? "Ошибка при получении имени пользователя по ид.={0}" : "Error getting user name by ID={0}", userID); return(null); } }
/// <summary> /// Получить идентификатор пользователя по имени. /// </summary> public int GetUserID(string username) { try { username = username ?? ""; dataCache.RefreshBaseTables(); BaseTables baseTables = dataCache.BaseTables; lock (baseTables.SyncRoot) { BaseTables.CheckColumnsExist(baseTables.UserTable, true); DataView viewUser = baseTables.UserTable.DefaultView; viewUser.Sort = "Name"; int rowInd = viewUser.Find(username); return(rowInd >= 0 ? (int)viewUser[rowInd]["UserID"] : BaseValues.EmptyDataID); } } catch (Exception ex) { log.WriteException(ex, Localization.UseRussian ? "Ошибка при получении идентификатора пользователя по имени \"{0}\"" : "Error getting user ID by name \"{0}\"", username); return(BaseValues.EmptyDataID); } }
/// <summary> /// Получить свойства объекта пользовательского интерфейса по идентификатору. /// </summary> public UiObjProps GetUiObjProps(int uiObjID) { try { dataCache.RefreshBaseTables(); // необходимо сохранить ссылку, т.к. объект может быть пересоздан другим потоком BaseTables baseTables = dataCache.BaseTables; lock (baseTables.SyncRoot) { BaseTables.CheckColumnsExist(baseTables.InterfaceTable, true); DataView viewInterface = baseTables.InterfaceTable.DefaultView; viewInterface.Sort = "ItfID"; int rowInd = viewInterface.Find(uiObjID); // столбец TypeCode добавлен в таблицу Интерфейс, начиная с версии 5.8 return(rowInd >= 0 ? GetUiObjFromRow(viewInterface[rowInd], viewInterface.Table.Columns.Contains("TypeCode")) : null); } } catch (Exception ex) { log.WriteException(ex, Localization.UseRussian ? "Ошибка при получении свойств объекта пользовательского интерфейса по ид.={0}" : "Error getting user interface object properties by ID={0}", uiObjID); return(null); } }
/// <summary> /// Find and Item by ItemId in the Store and return the items row /// The method makes a copy of the store items table /// adds the "itemInstance_Id" column (relationship to parent) to the item clone table /// adds the "assets" column to the table (used for the Assest XML) /// gets the row if it exists for the item. /// </summary> /// <param name="itemId">the itemId of the row to find in the items table</param> /// <returns>returns the item data row if the row is found or else returns null</returns> public DataRow FindItemInStore(string itemId) { DataRow itemRow = null; lock (lockObject) { foreach (KeyValuePair <string, DataSet> kvp in mStoreDataSet) { DataSet storeDataSet = (DataSet)kvp.Value; DataTable itemTableOrg = storeDataSet.Tables["item"]; DataTable itemTable = itemTableOrg.Copy(); DataColumn itemInstanceId = new DataColumn("itemInstance_Id", System.Type.GetType("System.Int32")); itemInstanceId.ColumnMapping = MappingType.Hidden; itemTable.Columns.Add(itemInstanceId); DataView itemTableView = new DataView(itemTable); itemTableView.Sort = "id asc"; int rowIndex = itemTableView.Find(itemId); if (rowIndex != -1) { DataRowView itemRowView = itemTableView[rowIndex]; itemRow = itemRowView.Row; break; } } } return(itemRow); }
/// <summary> /// Retrieve an item from the repository /// </summary> /// <param name="itemName"></param> /// <returns></returns> public string Retrieve(string itemName) { string result = string.Empty; XmlReader xmlFile; xmlFile = XmlReader.Create("ItemRepository.xml", new XmlReaderSettings()); DataSet dtSet = new DataSet(); DataView dtView; dtSet.ReadXml(xmlFile); dtView = new DataView(dtSet.Tables[0]); dtView.Sort = "Name"; int index = dtView.Find(itemName); if (index == -1) { Console.WriteLine("Item Not Found"); } else { Console.WriteLine(dtView[index]["Name"].ToString() + " " + dtView[index]["Content"].ToString() + " " + dtView[index]["Type"].ToString()); result = dtView[index]["Name"].ToString() + " " + dtView[index]["Content"].ToString() + " " + dtView[index]["Type"].ToString(); } return(result); }
//Tìm theo mã sp, nếu có thì hiển thị private void TimMaSP() { _dv = new DataView(_DtSP); _dv.Sort = "MaSP_SP"; int _index = _dv.Find(txtMaSP.Text.Trim()); txtbWarning.Text = @""; if (_index != -1) { gdSP.Visibility = System.Windows.Visibility.Visible; lbMa.Content = _dv[_index]["MaSP_SP"].ToString(); txtbTen.Text = _dv[_index]["TenSP_SP"].ToString(); lbGia.Content = _dv[_index]["GiaBanLe_SP"].ToString(); } else { //Ẩn khung thông tin sp gdSP.Visibility = System.Windows.Visibility.Collapsed; lbMa.Content = ""; txtbTen.Text = ""; lbGia.Content = ""; //Đặt con trỏ vào ô mã txtMaSP.SelectAll(); txtMaSP.Focus(); txtMaSP.SelectionStart = txtMaSP.Text.Length; txtbWarning.Text = @"Không có mã sản phẩm này!"; } }
private void buttonOk_Click(object sender, EventArgs e) { MainForm main = this.Owner as MainForm; DataTable dt = main.aptecaDataSet.Tables[0]; // проверка на совпадение наименования DataView custView = new DataView(dt, "", "NAME_MED", DataViewRowState.CurrentRows); int rowIndex = custView.Find(textBox1.Text); if (rowIndex != -1) { MessageBox.Show("Препарат с таким наименованием уже есть в базе!"); return; } DataRow row = dt.NewRow(); row["NAME_MED"] = textBox1.Text; row["arrival"] = counter.Value; row["sell"] = 0; row["ID_type"] = main.comboBoxCategory.SelectedValue; dt.Rows.Add(row); main.типмедикаментовмедикаментыBindingSource.EndEdit(); main.медикаментыTableAdapter.Update(main.aptecaDataSet); main.медикаментыTableAdapter.Fill(main.aptecaDataSet.медикаменты); Close(); }
internal static DataRowView GetRow(DataView dv, string columnName, object[] keys) { dv.Sort = columnName; var i = dv.Find(keys); return(i == -1 ? null : dv[i]); }
protected string GetColCh(string strCode, string tabName) { string colch = ""; DataView dv = new DataView(SysInitial.dsSys.Tables[tabName]); dv.Sort = "vcCommCode"; if (dv.Find(strCode) == -1) { colch = "未定义的编码:" + strCode; } else { colch = dv[dv.Find(strCode)]["vcCommName"].ToString().Trim(); } return(colch); }
private void EnableRemoteManagementQuota(List <HostingPlanQuotaInfo> quotas, DataView dataView) { // Sort by quota name dataView.Sort = "QuotaName"; // Try to find out the quota we are looking for... var indexOf = dataView.Find(Quotas.WEB_REMOTEMANAGEMENT); // Exit if nothing has been found if (indexOf == -1) { return; } // Retrieve QuotaID value from the row we have found var quotaId = Convert.ToInt32(dataView[indexOf]["QuotaID"]); // Look for the quota in quotas list var quotaInfo = quotas.Find(x => x.QuotaId.Equals(quotaId)); // Exit if nothing has been found if (quotaInfo == default(HostingPlanQuotaInfo)) { return; } // Enable quota if found quotaInfo.QuotaValue = 1; }
public DataView GetNodeChildren(string ID) { NodeTypes?nodeType = GetNodeType(ID); if (nodeType == null) { return(null); } string dtableName = Enum.GetName(typeof(NodeTypes), nodeType); var retTable = new DataTable("ChildNodes"); retTable.Columns.Add(new DataColumn("ID", typeof(string))); retTable.Columns.Add(new DataColumn("DisplayName", typeof(string))); retTable.Columns.Add(new DataColumn("NodeType", typeof(NodeTypes))); if (dtableName == "WorkingSet") { DataView workingLinks = workingSet.NodeChildren(ID); //dsWorkingSet.Tables["WorkingSetLinks"].Select(string.Format("WorkingSetID='{0}'",ID)); foreach (DataRowView rowView in workingLinks) { if (GetNodeType(rowView["LinkID"].ToString()) == null) { workingSet.RemoveWorkingSetLink(ID, rowView["LinkID"].ToString()); continue; } DataRow dRowInfo = GetNodeInfo(rowView["LinkID"].ToString()); string copyID = dRowInfo["ID"].ToString(); string copyDisplayName = dRowInfo["name"].ToString(); NodeTypes copyNodeType = (NodeTypes)Enum.Parse(typeof(NodeTypes), dRowInfo.Table.TableName, true); retTable.Rows.Add(new object[] { copyID, copyDisplayName, copyNodeType }); } } else { // logic to get all the children from the tables and put into a single table foreach (DataRelation dRelation in dsOneNote.Tables[dtableName].ChildRelations) { var dataViewNode = new DataView(dsOneNote.Tables[dtableName]) { Sort = "ID" }; Int32 drowindex = dataViewNode.Find(ID); DataView dvTemp = dataViewNode[drowindex].CreateChildView(dRelation); foreach (DataRowView rowView in dvTemp) { string copyID = rowView["ID"].ToString(); string copyDisplayName = rowView["name"].ToString(); NodeTypes copyNodeType = (NodeTypes)Enum.Parse(typeof(NodeTypes), dvTemp.Table.TableName, true); retTable.Rows.Add(new object[] { copyID, copyDisplayName, copyNodeType }); } } } return(retTable.DefaultView); }
public override void Setup() { base.Setup(); // Override sql_mode so it converts automatically from varchar(65535) to text MySqlCommand cmd = new MySqlCommand("SET GLOBAL SQL_MODE=``", rootConn); cmd.ExecuteNonQuery(); // Replace existing listeners with listener for testing. Trace.Listeners.Clear(); Trace.Listeners.Add(this.asertFailListener); DataSet dataSet = ConfigurationManager.GetSection("system.data") as System.Data.DataSet; DataView vi = dataSet.Tables[0].DefaultView; vi.Sort = "Name"; if (vi.Find("MySql") == -1) { dataSet.Tables[0].Rows.Add("MySql" , "MySql.Data.MySqlClient" , "MySql.Data.MySqlClient" , typeof(MySql.Data.MySqlClient.MySqlClientFactory).AssemblyQualifiedName); } }
private void btnTimKiem_Click(object sender, EventArgs e) { XmlTextReader reader = new XmlTextReader("NhaCungCap.xml"); DataSet ds = new DataSet(); ds.ReadXml(reader); DataView dv = new DataView(ds.Tables[0]); dv.Sort = "MaNCC"; reader.Close(); int index = dv.Find(txtTimKiem.Text); if (index == -1) { MessageBox.Show("Không tìm thấy"); txtTimKiem.Text = ""; txtTimKiem.Focus(); } else { DataTable dt = new DataTable(); dt.Columns.Add("Mã NCC"); dt.Columns.Add("Tên NCC"); dt.Columns.Add("Địa chỉ"); dt.Columns.Add("SDT"); dt.Columns.Add("Email"); dt.Columns.Add("Mô tả"); object[] list = { dv[index]["MaNCC"], dv[index]["TenNCC"], dv[index]["DiaChi"], dv[index]["SDT"], dv[index]["Email"], dv[index]["MoTa"] }; dt.Rows.Add(list); dgvNhaCungCap.DataSource = dt; txtTimKiem.Text = ""; } }
public static bool check(string DBName) { //بررسی اینکه دیتابیس وارد شده آیا در اس کیو ال سرور اتچ هست یا نه bool re = false; try { //در صورتی که سرور شما نام دیگری دارد به جای نام سرور زیر وارد کنید SqlConnection sq = new SqlConnection("server=.\\SQLExpress;trusted_connection=yes;"); SqlDataAdapter adapt = new SqlDataAdapter("Exec sp_helpdb", sq); DataSet set = new DataSet(); adapt.Fill(set); DataView view = new DataView(set.Tables[0]); view.Sort = "name"; int res = view.Find(DBName); if (res >= 0) { re = true; } else if (res == -1) { re = false; } } catch { re = false; } return(re); }
public void FindRowsWithoutSort() { Assert.Throws<ArgumentException>(() => { DataTable dt = new DataTable("table"); dt.Columns.Add("col1"); dt.Columns.Add("col2"); dt.Columns.Add("col3"); dt.Rows.Add(new object[] { 1, 2, 3 }); dt.Rows.Add(new object[] { 4, 5, 6 }); dt.Rows.Add(new object[] { 4, 7, 8 }); dt.Rows.Add(new object[] { 5, 7, 8 }); dt.Rows.Add(new object[] { 4, 8, 9 }); DataView dv = new DataView(dt); dv.Find(1); }); }
public void Find_ByArray() { int FindResult, ExpectedResult = -1; //create the source datatable DataTable dt = DataProvider.CreateParentDataTable(); //create the dataview for the table DataView dv = new DataView(dt); for (int i = 0; i < dt.Rows.Count; i++) { if ((int)dt.Rows[i]["ParentId"] == 3 && dt.Rows[i]["String1"].ToString() == "3-String1") { ExpectedResult = i; break; } } // Find ,no sort - exception Assert.Throws<ArgumentException>(() => { FindResult = dv.Find(new object[] { "3", "3-String1" }); }); dv.Sort = "String1,ParentId"; // Find = wrong sort, can not find Assert.Throws<FormatException>(() => { FindResult = dv.Find(new object[] { "3", "3-String1" }); }); dv.Sort = "ParentId,String1"; // Find FindResult = dv.Find(new object[] { "3", "3-String1" }); Assert.Equal(ExpectedResult, FindResult); }