private void OnAdd() { if (cboService.SelectedValue == null || cboService.Text.Trim() == string.Empty) { return; } string serviceGUID = cboService.SelectedValue.ToString(); DataTable dt = dgDichVuCon.DataSource as DataTable; dlgServices dlg = new dlgServices(serviceGUID, dt); if (dlg.ShowDialog(this) == System.Windows.Forms.DialogResult.OK) { List <DataRow> serviceList = dlg.Services; foreach (DataRow row in serviceList) { DataRow newRow = dt.NewRow(); newRow["Checked"] = false; newRow["ServiceGUID"] = row["ServiceGUID"]; newRow["Code"] = row["Code"]; newRow["Name"] = row["Name"]; newRow["EnglishName"] = row["EnglishName"]; dt.Rows.Add(newRow); } } }
private void OnAddService() { dlgServices dlg = new dlgServices(_member.ConstractGUID, _member.CompanyMemberGUID, _member.AddedServices, _member.DeletedServiceRows); if (dlg.ShowDialog(this) == System.Windows.Forms.DialogResult.OK) { List <DataRow> checkedRows = dlg.Services; DataTable dataSource = dgService.DataSource as DataTable; if (dataSource == null) { dataSource = checkedRows[0].Table.Clone(); dgService.DataSource = dataSource; } foreach (DataRow row in checkedRows) { string serviceGUID = row["ServiceGUID"].ToString(); DataRow[] rows = dataSource.Select(string.Format("ServiceGUID='{0}'", serviceGUID)); if (rows == null || rows.Length <= 0) { DataRow newRow = dataSource.NewRow(); newRow["Checked"] = false; newRow["ServiceGUID"] = serviceGUID; newRow["Code"] = row["Code"]; newRow["Name"] = row["Name"]; newRow["Price"] = row["Price"]; dataSource.Rows.Add(newRow); if (!_member.AddedServices.Contains(serviceGUID)) { _member.AddedServices.Add(serviceGUID); } _member.DeletedServices.Remove(serviceGUID); foreach (DataRow r in _member.DeletedServiceRows) { if (r["ServiceGUID"].ToString() == serviceGUID) { _member.DeletedServiceRows.Remove(r); break; } } } } } }