public static void Mainly() { MyRow row = new MyRow(); row.Add(new MyElement("Gumby")); row.Add(new MyElement("Pokey")); Console.WriteLine("Initial value"); Console.WriteLine("{0}", row); // write to binary, read it back using (Stream streamWrite = File.Create("MyRow.bin")) { BinaryFormatter binaryWrite = new BinaryFormatter(); binaryWrite.Serialize(streamWrite, row); } MyRow rowBinary = null; using (Stream streamRead = File.OpenRead("MyRow.bin")) { BinaryFormatter binaryRead = new BinaryFormatter(); rowBinary = (MyRow)binaryRead.Deserialize(streamRead); } Console.WriteLine("Values after binary serialization"); Console.WriteLine("{0}", rowBinary); }
/// <summary> /// (基于MyDataTable的列结构)创建1个空行 /// </summary> public MyRow NewRow() { MyRow row = new MyRow(); foreach (var ColumnName in ColumnNames) { row.Add(ColumnName, null); } return(row); }
public static void Main() { MyRow row = new MyRow(); row.Add(new MyElement("Gumby")); row.Add(new MyElement("Pokey")); Console.WriteLine("Initial value"); Console.WriteLine("{0}", row); // write to binary, read it back Stream streamWrite = File.Create("MyRow.bin"); BinaryFormatter binaryWrite = new BinaryFormatter(); binaryWrite.Serialize(streamWrite, row); streamWrite.Close(); Stream streamRead = File.OpenRead("MyRow.bin"); BinaryFormatter binaryRead = new BinaryFormatter(); MyRow rowBinary = (MyRow)binaryRead.Deserialize(streamRead); streamRead.Close(); Console.WriteLine("Values after binary serialization"); Console.WriteLine("{0}", rowBinary); // write to SOAP (XML), read it back streamWrite = File.Create("MyRow.xml"); SoapFormatter soapWrite = new SoapFormatter(); soapWrite.Serialize(streamWrite, row); streamWrite.Close(); streamRead = File.OpenRead("MyRow.xml"); SoapFormatter soapRead = new SoapFormatter(); MyRow rowSoap = (MyRow)soapRead.Deserialize(streamRead); streamRead.Close(); Console.WriteLine("Values after SOAP serialization"); Console.WriteLine("{0}", rowSoap); }
/// <summary> /// 获取某行(行索引) /// </summary> /// <param name="RowIndex">Index of the row.</param> /// <returns>MyRow.</returns> public MyRow GetRow(int RowIndex) { MyRow row = new MyRow(); //提取某行的所有列,构成MyRow foreach (var ColumnName in ColumnNames) { row.Add(ColumnName, this[RowIndex, ColumnName]); } return(row); }
private void Form1_Load(object sender, EventArgs e) { MyRows result = new MyRows(); for (int i = 0; i < Items.Count; i++) { result.Fields.Add(Items[i].Name); } result.Fields.Add("Сума"); List <KeyValuePair <string, IComparer> > gridHeaders = new List <KeyValuePair <string, IComparer> >(); for (int i = 0; i < result.Fields.Count; i++) { gridHeaders.Add(new KeyValuePair <string, IComparer>(result.Fields[i], null)); } Fill fill = new Fill(result.Fields); string bVariantCount = ""; for (int i = 0; i < Items.Count; i++) { bVariantCount += "1"; } int count = Convert.ToInt32(bVariantCount, 2); for (int i = 0; i <= count; i++) { //https://stackoverflow.com/questions/6758196/convert-int-to-a-bit-array-in-net string s = Convert.ToString(i, 2); //Convert to binary in a string int[] bits = s.PadLeft(Items.Count, '0') // Add 0's from left .Select(c => int.Parse(c.ToString())) // convert each char to int .ToArray(); // Convert IEnumerable from select to Array MyRow row = new MyRow(); double sum = 0; int trueCount = 0; for (int j = 0; j < Items.Count; j++) { double price; int cell = bits[j]; if (cell != 0) { trueCount++; price = Items[j].Price; } else { price = 0; } price = (cell == 0 ? 0 : Items[j].Price); sum += price; row.Add(result.Fields[j], price); } row.Add("Сума", sum); if (trueItemsCount == 0 || trueCount == trueItemsCount) { result.Rows.Add(row); } } tssl_Count.Text = result.Rows.Count.ToString(); fill.GridFill(sg_Result, result.Rows, null, gridHeaders); }