예제 #1
0
        public void DeleteRow(DataGridViewRow row)
        {
            if (!DataColumns.Contains("ID"))
            {
                return;
            }
            string recordID = row.Cells["ID"].Value.ToString();

            if (MessageBox.Show("确认删除已选的记录吗?", "确认?", MessageBoxButtons.YesNo) == DialogResult.Yes)
            {
                if (GoalTables.Contains(this.TableName))
                {
                    DBHelper.GetDBHelper().DelDataFromTable(this.TableName + "DataDetail", recordID);
                }
                DBHelper.GetDBHelper().DelDataFromTable(this.TableName, recordID);
                DoSearch();
            }
        }
예제 #2
0
        /// <summary>
        /// Fills the schema of the table consulting the schema of the sharepoint list.
        /// </summary>
        /// <param name="table">the DataTable object to change</param>
        /// <param name="connection">an open Sharepoint connection</param>
        protected void FillSchemaFromSharepoint(DataTable table, SpConnection connection)
        {
            if (table == null)
            {
                throw new ArgumentNullException("table");
            }

            ViewDef viewDef = null;
            ListDef listDef = null;

            if (this.ViewName != null)
            {
                viewDef = connection.GetViewSchema(this.ListName, this.ViewName);
                listDef = viewDef.ListDef;
            }
            else
            {
                listDef = connection.GetListSchema(this.ListName);
            }

            IList <DataColumn> primaryColumns = new List <DataColumn>();

            foreach (Field field in listDef.Fields)
            {
                DataColumn column;

                if (viewDef != null &&
                    viewDef.ViewFields.Count > 0 &&
                    !ContainsFieldRefWithName(viewDef.ViewFields, field.Name))
                {
                    continue;
                }

                if (!table.Columns.Contains(field.Name))
                {
                    column = new DataColumn();
                    table.Columns.Add(column);
                }
                else
                {
                    column = table.Columns[field.Name];
                }

                MapFromFieldToColumn(column, field);

                // sharepoint returns as primary key the ID
                // which is relevant to sharepoint list.
                if (field.IsPrimaryKey)
                {
                    primaryColumns.Add(column);
                }
            }

            bool primaryRemoved = false;

            if (DataColumns.Count > 0)
            {
                List <string> columnsToRemove = new List <string>();
                foreach (DataColumn tableColumn in table.Columns)
                {
                    if (!DataColumns.Contains(tableColumn.ColumnName))
                    {
                        columnsToRemove.Add(tableColumn.ColumnName);

                        if (primaryColumns.Contains(tableColumn))
                        {
                            primaryRemoved = true;
                        }
                    }
                }

                foreach (string tableColumn2 in columnsToRemove)
                {
                    table.Columns.Remove(tableColumn2);
                }
            }

            if (primaryColumns.Count > 0 && !primaryRemoved)
            {
                DataColumn[] primaryKey = new DataColumn[primaryColumns.Count];
                primaryColumns.CopyTo(primaryKey, 0);
                table.PrimaryKey = primaryKey;
            }

            table.TableName = this.TableName;
        }