private void PostData() { if (dgrid.Rows.Count > 0) { if (postmdt.Rows.Count > 0) { postmdt.Rows.Clear(); postddt.Rows.Clear(); } //主单 postmdt.Rows.Add(); if (string.IsNullOrEmpty(dgrid.Rows[0].Cells["FMNo"].Value.ToString())) { postmdt.Rows[0]["FNo"] = Guid.NewGuid().ToString(); } else { postmdt.Rows[0]["FNo"] = dgrid.Rows[0].Cells["FMNo"].Value; } postmdt.Rows[0]["FTitle"] = dgrid.Rows[0].Cells["FTitle"].Value; postddt.Rows.Add(); for (int i = 0; i < dgrid.RowCount; i++) { postddt.Rows[0]["FMNo"] = postmdt.Rows[0]["FNo"]; postddt.Rows[0]["FLine" + (i + 1).ToString()] = dgrid.Rows[i].Cells["FLine"].Value; } int retvalue = TxtDA.Update(postmdt, "TPoetry", postddt, "TPoetryDetail", true); if (retvalue > 0) { MessageBox.Show("保存成功!", "提示:"); } else { MessageBox.Show("保存失败!", "提示:"); } } }
private void InitDatatable(string title) { if (!poedt.Columns.Contains("FTitle")) { poedt.Columns.Add("FTitle", typeof(string)); poedt.Columns.Add("FLine", typeof(string)); poedt.Columns.Add("FMNo", typeof(string)); } else { poedt.Rows.Clear(); } pdt = TxtDA.GetPoetryTable(title); if (pdt != null && pdt.Rows.Count > 0) { for (int i = 0; i < pdt.Columns.Count; i++) { if (i == 0) { poedt.Rows.Add(); poedt.Rows[0]["FTitle"] = pdt.Rows[0]["FTitle"]; poedt.Rows[0]["FLine"] = pdt.Rows[0]["FLine1"]; poedt.Rows[0]["FMNo"] = pdt.Rows[0]["FMNo"]; i++; } else { if (i < 9) { poedt.Rows.Add(); poedt.Rows[i - 1]["FLine"] = pdt.Rows[0]["FLine" + i.ToString()]; } } } dgrid.DataSource = poedt; } }