コード例 #1
0
ファイル: MainForm.cs プロジェクト: Nazir/EqGate-2008
        private void FillListView(ListView lv, int Count, string api, string ToFile, bool AppendResult)
        {
            if (Count < 1)
            {
                return;
            }

            /*
             * if ((EQGateDLL.RequestOutput.Length / Count) < EQGateAPI.EQGateClassAPI.GetFieldsSize(api, ""))
             * {
             *  MessageBox.Show("Размер выходных данных меньше общего размера API!", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
             *  return;
             * }
             * // */
            //
            toolStripProgressBar.Value   = 0;
            toolStripProgressBar.Maximum = toolStripProgressBar.Step * Count;
            toolStripProgressBar.Visible = true;
            if (EQGateDLL.RequestOutput.Length == 0)
            {
                return;
            }
            if ((!AppendResult) && (File.Exists(ToFile)))
            {
                File.Delete(ToFile);
            }

            string temp = String.Empty;


            int FieldsCount = 0;

            FieldsCount = EQGateAPI.EQGateClassAPI.GetFieldsCount(api, "");

            if (lv.Columns.Count < FieldsCount)
            {
                lv.Columns.Clear();
                for (int iCounter = 0; iCounter < FieldsCount; iCounter++)
                {
                    ColumnHeader columnHeader = new ColumnHeader();
                    columnHeader.Text  = EQGateAPI.EQGateClassAPI.GetFieldValue(api, "", iCounter, "description", "");
                    columnHeader.Width = Convert.ToInt32(EQGateAPI.EQGateClassAPI.GetFieldValue(api, "", iCounter, "width", ""));

                    // Add the column headers to listView_Events.
                    lv.Columns.AddRange(new ColumnHeader[] { columnHeader });
                }
            }

            //int ListCount = ( sb_mcs.ToString(5, 4) as int );
            string ResultFileDivider = "^";

            //Divider = "|";

            using (StreamWriter sw = new StreamWriter(ToFile, AppendResult, Encoding.GetEncoding(866)))
            {
                for (int iCounter = 0; iCounter < Count; iCounter++)
                {
                    string        Size = String.Empty;
                    StringBuilder sb   = new StringBuilder();
                    ListViewItem  item = new ListViewItem();
                    for (int i = 0; i < FieldsCount; i++)
                    {
                        Size = EQGateAPI.EQGateClassAPI.GetFieldValue(api, "", i, "size", "");
                        temp = EQGateDLL.GetRequestOutputItem(Convert.ToInt32(Convert.ToDouble(Size)));
                        temp = temp.Replace(ResultFileDivider, " ");
                        if (EQGateAPI.EQGateClassAPI.GetFieldValue(api, "", i, "type", "") == "A")
                        {
                            sb.Append(temp.Trim());
                        }
                        if (EQGateAPI.EQGateClassAPI.GetFieldValue(api, "", i, "type", "") == "D")
                        {
                            sb.Append(EQGateDLL.ConvertDateToFormat(temp, ""));
                        }
                        if (EQGateAPI.EQGateClassAPI.GetFieldValue(api, "", i, "type", "") == "U")
                        {
                            sb.Append(EQGateDLL.ConvertToCurrency(temp, "U", Size));
                        }
                        if (EQGateAPI.EQGateClassAPI.GetFieldValue(api, "", i, "type", "") == "S")
                        {
                            sb.Append(EQGateDLL.ConvertToCurrency(temp, "S", Size));
                        }
                        if (EQGateAPI.EQGateClassAPI.GetFieldValue(api, "", i, "type", "") == "B")
                        {
                            if (temp == "Y")
                            {
                                sb.Append("Истина");
                            }
                            if (temp == "N")
                            {
                                sb.Append("Ложь");
                            }
                        }
                        if (i == 0)
                        {
                            item.Text = temp;
                        }
                        else
                        {
                            item.SubItems.Add(temp);
                        }
                        //sb.Append(temp);
                        sb.Append(ResultFileDivider);
                    }
                    lv.Items.AddRange(new ListViewItem[] { item });
                    sw.Write(sb.ToString());
                    //toolStripProgressBar.Value += 1;
                    sw.Write("\r\n");
                }
            }

            /*
             * if (File.Exists(ToFile + ".tmp"))
             * {
             *  File.Copy(ToFile + ".tmp", ToFile, true);
             *  File.Delete(ToFile + ".tmp");
             * } //*/
            //toolStripProgressBar.Visible = false;
        }