日期:2014-05-18 浏览次数:20428 次
private const string SQL_GROUP_SELECT = @" SELECT [Id],[name],[description],[groupType],[owner],[coowner], [CreatedDate],[ChangedDate],[IsGSSGroup], [AutoAcceptOUChange],[CompanyCode],[AutoExpiredDate],[ParentGroups] FROM [Group]"; private const string DefaultTableName = "Pending_Group"; private static void InitializeTable(string tableName) { PendingGroupTable.TableName = tableName; PendingGroupTable.Columns.Add("ID", typeof(string)); PendingGroupTable.Columns.Add("Name", typeof(string)); PendingGroupTable.Columns.Add("Description", typeof(string)); PendingGroupTable.Columns.Add("GroupType", typeof(int)); PendingGroupTable.Columns.Add("Owner", typeof(string)); PendingGroupTable.Columns.Add("Coowner", typeof(string)); PendingGroupTable.Columns.Add("CreatedDate", typeof(DateTime)); PendingGroupTable.Columns.Add("ChangedDate", typeof(DateTime)); PendingGroupTable.Columns.Add("IsGSSGroup", typeof(bool)); PendingGroupTable.Columns.Add("AutoAcceptOUChange", typeof(bool)); PendingGroupTable.Columns.Add("CompanyCode", typeof(string)); PendingGroupTable.Columns.Add("AutoExpiredDate", typeof(DateTime)); PendingGroupTable.Columns.Add("ParentGroups", typeof(string)); PendingGroupTable.Columns.Add("ImportStatus", typeof(string)); PendingGroupTable.PrimaryKey = new[] { PendingGroupTable.Columns["ID"] }; }
private static void UpdateToDB() { try { var conn = new SqlConnection(ConnString.ConnectionString); var daGroup = new SqlDataAdapter(SQL_GROUP_SELECT, conn) { MissingSchemaAction = MissingSchemaAction.AddWithKey, }; var scbGroup = new SqlCommandBuilder(daGroup); DataTable dtTemp = PendingGroupTable.Clone(); foreach (DataRow dr in PendingGroupTable.Rows) { if (!string.IsNullOrEmpty(dr["ImportStatus"].ToString())) { if (Equals(ImportStatus.Ready, Enum.Parse(typeof(ImportStatus), dr["ImportStatus"].ToString()))) { int colCount = dtTemp.Columns.Count; DataRow drNew = dtTemp.NewRow(); for (int i = 0; i < colCount - 1; i++) { drNew[i] = dr[i]; } dtTemp.Rows.Add(drNew); } } } dtTemp.Columns.Remove("ImportStatus"); daGroup.Fill(dtTemp); daGroup.Update(dtTemp); //PendingGroupTable.AcceptChanges(); //return true; } catch (Exception) { //return false; } pendingGroupEmployees.Update(); }