protected override void OnSaveData() { if (!string.IsNullOrEmpty(error_privider.GetError(this.dgvDataAllow))) { MessageBox.Show("請修正錯誤再儲存。"); return; } if (this.Record == null) this.Record = new UDT.CSCourseExt(); this.Record.CourseID = int.Parse(PrimaryKey); this.Record.NotOpening = this.chkNotOpening.Checked; /// 選課條件-Allow與Deny擇一儲存 /// <Identities> /// <Allow> /// <Identity EnrollYear=”101” DeptID=”568” ClassID=”” /> /// <Identity EnrollYear=”” DeptID=”” ClassID=”587” /> /// <Identity EnrollYear=”100” DeptID=”” ClassID=”” /> /// </Allow> /// <Deny> /// <Identity EnrollYear=”101” DeptID=”568” ClassID=”” /> /// <Identity EnrollYear=”” DeptID=”” ClassID=”587” /> /// <Identity EnrollYear=”100” DeptID=”” ClassID=”” /> /// </Deny> /// </Identities> StringBuilder identity_allow = new StringBuilder(); StringBuilder identity_deny = new StringBuilder(); if (this.chkAllow.Checked) { foreach (DataGridViewRow row in this.dgvDataAllow.Rows) { if (row.IsNewRow) continue; identity_allow.Append(string.Format("<Identity EnrollYear=\"{0}\" DeptID=\"{1}\" ClassID=\"{2}\" />", row.Cells[0].Value + "", row.Cells[1].Value + "", row.Cells[2].Value + "")); } } if (this.chkDeny.Checked) { foreach (DataGridViewRow row in this.dgvDataDeny.Rows) { if (row.IsNewRow) continue; identity_deny.Append(string.Format("<Identity EnrollYear=\"{0}\" DeptID=\"{1}\" ClassID=\"{2}\" />", row.Cells[0].Value + "", row.Cells[1].Value + "", row.Cells[2].Value + "")); } } string identity = string.Empty; if (identity_allow.Length > 0) identity = "<Allow>" + identity_allow.ToString() + "</Allow>"; if (identity_deny.Length > 0) identity += "<Deny>" + identity_deny.ToString() + "</Deny>"; this.Record.Identity = "<Identities>" + identity + "</Identities>"; this.Record.Save(); ResetDirtyStatus(); }
protected override void OnPrimaryKeyChangedAsync() { List<UDT.CSCourseExt> course_exts = Access.Select<UDT.CSCourseExt>(string.Format("ref_course_id={0}", PrimaryKey)); if (course_exts.Count > 0) Record = course_exts[0]; else Record = null; }