private int GetChildrenCount() { int cc = 0; var quote = new QuoteChildren(_quoteRevID); DataTable tbl = quote.ItemList("Q", true); if (tbl != null) { cc = tbl.Rows.Count; } return(cc); }
public void Generate() { var qc = new QuoteChildren(_quoteRevID); DataTable tbl = qc.ItemList("Q", true); if (tbl == null) { return; } // //2. Define the destination: InvoiceItem var connectionSQL = new SqlConnection(SalesCenterConfiguration.ConnectionString); const string sqlSelectString2 = "SELECT * FROM [Invoice_Item] WHERE ([quoteItemID] = 0) "; var selectCommand2 = new SqlCommand(sqlSelectString2, connectionSQL); var adapter2 = new SqlDataAdapter(selectCommand2); var ds2 = new DataSet(); ds2.Tables.Clear(); try { connectionSQL.Open(); adapter2.Fill(ds2, "t2"); foreach (DataRow row in tbl.Rows) { DataRow rowNew = ds2.Tables["t2"].NewRow(); int itemIndex = ds2.Tables["t2"].Columns.Count; int i = 0; for (i = 1; i <= itemIndex - 1; i++) { rowNew[i] = row[i]; } rowNew["qiItemTitle"] = VbHtml.MyHtmlDecode(rowNew["qiItemTitle"]); string copyDetails = SalesCenterConfiguration.CopyDetailsToInvoice; if (copyDetails.Trim().ToLower() == "yes") { object s1 = rowNew["qiDescription"]; rowNew["qiDescription"] = VbHtml.MyHtmlDecode(rowNew["qiDescription"]); object s2 = rowNew["qiDescription"]; object s3 = s2; } else { rowNew["qiDescription"] = DBNull.Value; } rowNew["quoteRevID"] = _invoiceID; rowNew["recordType"] = "I"; ds2.Tables["t2"].Rows.Add(rowNew); } //4. Write ds2, back to DB var cb = new SqlCommandBuilder(adapter2); adapter2 = cb.DataAdapter; adapter2.Update(ds2, "t2"); } catch (SqlException ex) { string errorLog = ex.Message; } finally { connectionSQL.Close(); } }