public override global::System.Data.DataSet Clone() { SumQuery cln = ((SumQuery)(base.Clone())); cln.InitVars(); cln.SchemaSerializationMode = this.SchemaSerializationMode; return(cln); }
public static global::System.Xml.Schema.XmlSchemaComplexType GetTypedDataSetSchema(global::System.Xml.Schema.XmlSchemaSet xs) { SumQuery ds = new SumQuery(); global::System.Xml.Schema.XmlSchemaComplexType type = new global::System.Xml.Schema.XmlSchemaComplexType(); global::System.Xml.Schema.XmlSchemaSequence sequence = new global::System.Xml.Schema.XmlSchemaSequence(); global::System.Xml.Schema.XmlSchemaAny any = new global::System.Xml.Schema.XmlSchemaAny(); any.Namespace = ds.Namespace; sequence.Items.Add(any); type.Particle = sequence; global::System.Xml.Schema.XmlSchema dsSchema = ds.GetSchemaSerializable(); if (xs.Contains(dsSchema.TargetNamespace)) { global::System.IO.MemoryStream s1 = new global::System.IO.MemoryStream(); global::System.IO.MemoryStream s2 = new global::System.IO.MemoryStream(); try { global::System.Xml.Schema.XmlSchema schema = null; dsSchema.Write(s1); for (global::System.Collections.IEnumerator schemas = xs.Schemas(dsSchema.TargetNamespace).GetEnumerator(); schemas.MoveNext();) { schema = ((global::System.Xml.Schema.XmlSchema)(schemas.Current)); s2.SetLength(0); schema.Write(s2); if ((s1.Length == s2.Length)) { s1.Position = 0; s2.Position = 0; for (; ((s1.Position != s1.Length) && (s1.ReadByte() == s2.ReadByte()));) { ; } if ((s1.Position == s1.Length)) { return(type); } } } } finally { if ((s1 != null)) { s1.Close(); } if ((s2 != null)) { s2.Close(); } } } xs.Add(dsSchema); return(type); }
public override IEnumerable <object> Solve(TextReader inputStream) { var(sitesCount, queriesCount) = inputStream.ReadValue <int, int>(); var yCoordinates = new HashSet <int>(); var queries = new List <Query>(); var toAnswer = new Queue <SumQuery>(); var answers = new Dictionary <SumQuery, long>(); for (int i = 0; i < sitesCount; i++) { var(x, y, d, c) = inputStream.ReadValue <int, int, int, int>(); yCoordinates.Add(y); yCoordinates.Add(y + d + 1); queries.Add(new AddQuery(x, y, d, c)); queries.Add(new AddQuery(x + d + 1, y, d, -c)); } for (int i = 0; i < queriesCount; i++) { var(a, b) = inputStream.ReadValue <int, int>(); yCoordinates.Add(b); var query = new SumQuery(a, b); queries.Add(query); toAnswer.Enqueue(query); } queries.Sort(); var shrinker = new CoordinateShrinker <int>(yCoordinates); var costs = new BinaryIndexedTree(shrinker.Count); foreach (var query in queries) { var shrinkedY = shrinker.Shrink(query.Y); if (query is AddQuery addQuery) { var shrinkedYPlusD = shrinker.Shrink(addQuery.Y + addQuery.Distance + 1); costs.AddAt(shrinkedY, addQuery.Cost); costs.AddAt(shrinkedYPlusD, -addQuery.Cost); } else if (query is SumQuery sumQuery) { answers.Add(sumQuery, costs.Sum(shrinkedY + 1)); } } foreach (var query in toAnswer) { yield return(answers[query]); } }
public static global::System.Xml.Schema.XmlSchemaComplexType GetTypedTableSchema(global::System.Xml.Schema.XmlSchemaSet xs) { global::System.Xml.Schema.XmlSchemaComplexType type = new global::System.Xml.Schema.XmlSchemaComplexType(); global::System.Xml.Schema.XmlSchemaSequence sequence = new global::System.Xml.Schema.XmlSchemaSequence(); SumQuery ds = new SumQuery(); global::System.Xml.Schema.XmlSchemaAny any1 = new global::System.Xml.Schema.XmlSchemaAny(); any1.Namespace = "http://www.w3.org/2001/XMLSchema"; any1.MinOccurs = new decimal(0); any1.MaxOccurs = decimal.MaxValue; any1.ProcessContents = global::System.Xml.Schema.XmlSchemaContentProcessing.Lax; sequence.Items.Add(any1); global::System.Xml.Schema.XmlSchemaAny any2 = new global::System.Xml.Schema.XmlSchemaAny(); any2.Namespace = "urn:schemas-microsoft-com:xml-diffgram-v1"; any2.MinOccurs = new decimal(1); any2.ProcessContents = global::System.Xml.Schema.XmlSchemaContentProcessing.Lax; sequence.Items.Add(any2); global::System.Xml.Schema.XmlSchemaAttribute attribute1 = new global::System.Xml.Schema.XmlSchemaAttribute(); attribute1.Name = "namespace"; attribute1.FixedValue = ds.Namespace; type.Attributes.Add(attribute1); global::System.Xml.Schema.XmlSchemaAttribute attribute2 = new global::System.Xml.Schema.XmlSchemaAttribute(); attribute2.Name = "tableTypeName"; attribute2.FixedValue = "QueryColumnsDataTable"; type.Attributes.Add(attribute2); type.Particle = sequence; global::System.Xml.Schema.XmlSchema dsSchema = ds.GetSchemaSerializable(); if (xs.Contains(dsSchema.TargetNamespace)) { global::System.IO.MemoryStream s1 = new global::System.IO.MemoryStream(); global::System.IO.MemoryStream s2 = new global::System.IO.MemoryStream(); try { global::System.Xml.Schema.XmlSchema schema = null; dsSchema.Write(s1); for (global::System.Collections.IEnumerator schemas = xs.Schemas(dsSchema.TargetNamespace).GetEnumerator(); schemas.MoveNext();) { schema = ((global::System.Xml.Schema.XmlSchema)(schemas.Current)); s2.SetLength(0); schema.Write(s2); if ((s1.Length == s2.Length)) { s1.Position = 0; s2.Position = 0; for (; ((s1.Position != s1.Length) && (s1.ReadByte() == s2.ReadByte()));) { ; } if ((s1.Position == s1.Length)) { return(type); } } } } finally { if ((s1 != null)) { s1.Close(); } if ((s2 != null)) { s2.Close(); } } } xs.Add(dsSchema); return(type); }
private void toolStripButton2_Click(object sender, EventArgs e) { SumQuery qds; qds = new SumQuery(); SortForm DataSort = new SortForm(); //DataGridView dv = (DataGridView)DataSort.Controls["sortTableDataGridView"]; DataGridView dv = DataSort.sortTableDataGridView; dv.Columns[1].Visible = false; DataSort.Text = "分组设置"; List <string> ls = new List <string>(); ls.Add("id"); DataSort.SetSortColumns(qds.QueryColumns.Columns, ls); DataSort.ShowDialog(); string groupStr = DataSort.GetSortString(); //////////// if (null != groupStr) { string[] result = groupStr.Split(new Char[] { ',' }); string header = " select "; string ender = " group by "; string sWhere = " where ( 1 = 1) "; if (this.checkBox8.Checked) { sWhere = sWhere + " and ( a.accrual_date >= '" + dateTimePicker1.Text + "' and a.accrual_date <= '" + dateTimePicker2.Text + "') "; } //if (sWhere.Length > 3) //{ // sWhere = " where " + sWhere.Substring(0, sWhere.Length - 3); //} //else //{ // sWhere = ""; //} if (result.Length > 0) { for (int i = 0; i < result.Length; i++) { header = header + selstr(result[i]) + ","; if (i < result.Length - 1) { ender = ender + grustr(result[i]) + ","; } else { ender = ender + grustr(result[i]); } } } string body = " sum( isnull(a.principal_money,0)) as 本金, " + " sum(isnull(a.compensate_money,0)) as 还本, " + " (sum( isnull(a.principal_money,0)) - sum(isnull(a.compensate_money,0))) as 欠本," + " sum(isnull(a.accrual_money,0)) as 利息, " + " sum(isnull(a.compensate_accrual_money,0)) as 还息, " + " ( sum(isnull( a.accrual_money,0)) - sum(isnull(a.compensate_accrual_money,0))) as 欠息," + " left(max(convert(varchar(20),accrual_date,120)),10) as 计息日期" + " FROM XD_Client_Loanaccrual AS a LEFT OUTER JOIN " + " XD_Client_Loan AS b ON a.loan_id = b.Id " + " LEFT OUTER JOIN " + " YX_client AS c on b.Client_Code = c.Card_number "; //+ //" LEFT OUTER JOIN " + //" XD_client_compensate_loan AS d on a.loan_id = d.loan_id and a.accrual_date = d.compensate_date "; string sel; if (result.Length > 0) { sel = header + body + sWhere + ender; } else { sel = header + body + sWhere; } SqlDataAdapter myAdapter = new SqlDataAdapter(sel, SQLDatabase.Connectstring); //DataSet allData = new DataSet(); //myAdapter.Fill(allData); if (null != ds) { ds.Dispose(); } ds = new DataSet(); myAdapter.Fill(ds); myAdapter.Dispose(); //this.dataGridView1.DataSource = allData; this.dataGridView1.Columns.Clear(); this.dataGridView1.AutoGenerateColumns = true; dataGridView1.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.DisplayedCellsExceptHeaders; //BindingSource bindingSource1 = new BindingSource(); //DataTableReader reader = new DataTableReader(allData.Tables[0]); //this.billMainDataSet.BalanceBill.Clear(); //this.billMainDataSet.BalanceBill.Load(reader); //ds = allData; if (null != bindingSource2) { this.bindingSource2.Dispose(); } this.bindingSource2 = new BindingSource(); this.bindingSource2.DataSource = ds.Tables[0]; dataGridView1.DataSource = bindingSource2; this.bindingNavigator1.BindingSource = bindingSource2; bindingSource2.ResetBindings(true); AddSummationRow(bindingSource2, dataGridView1); } }