예제 #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (button1.Text == "取消(&C)")
            {
                if (MessageBox.Show("确定要中断数据转换吗?", "确定", MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.OK)
                {
                    stopConverting    = true;
                    outputBox.Enabled = true;
                    treeView1.Enabled = true;
                    status3.Text     += DateTime.Now.ToString("HH:mm:ss") + ":中断转换!\n";
                }
                return;
            }

            if (treeView1.Nodes.Count < 1)
            {
                MessageBox.Show("没有找到数据!", "错误");
                return;
            }
            if (descPath.Text.Trim() == "")
            {
                MessageBox.Show("请选择目标文件夹!", "错误");
                descPath.Focus();
                return;
            }
            if (Directory.Exists(descPath.Text) == false)
            {
                MessageBox.Show("文件夹“" + descPath.Text + "”不存在!请重新选择或创建!", "错误", MessageBoxButtons.OK);
                descPath.Focus();
                return;
            }
            if (MessageBox.Show("转换数据时将根据您的选择在“" + descPath.Text.Trim() + "”中创建多个文件,同名文件将被覆盖!\n\n确定开始转换吗?", "确定", MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) != DialogResult.OK)
            {
                return;
            }

            //转换数据
            int errorCounts = 0;

            button1.Text      = "取消(&C)";
            status.Text       = "";
            status2.Text      = "";
            status3.Text      = DateTime.Now.ToString("HH:mm:ss") + ":开始转换...\n";
            outputBox.Enabled = false;
            treeView1.Enabled = false;
            try
            {
                FxjData fxj = new FxjData();
                string[,] x;
                string s       = "";
                string sepChar = seperateChar.Text;
                for (int i = 0; i < treeView1.Nodes.Count; i++)
                {
                    if (treeView1.Nodes[i].Nodes.Count > 0)
                    {
                        string[,] codes = fxj.GetData("dm", treeView1.Nodes[i].Nodes[0].Text.Split('|')[1], 0);
                        foreach (TreeNode node in treeView1.Nodes[i].Nodes)
                        {
                            if (node.Checked)
                            {
                                status.Text   = node.Text.Split('|')[1] + node.Text.Split('|')[2];
                                status3.Text += DateTime.Now.ToString("HH:mm:ss") + ":开始转换" + status.Text + " \n";
                                Application.DoEvents();
                                switch (node.Text.Split('|')[2])
                                {
                                case "dm":
                                    StreamWriter swdm = new StreamWriter(descPath.Text + @"\" + node.Text.Split('|')[3], false);
                                    x = fxj.GetFields("dm");
                                    for (int ii = 0; ii < x.GetLength(0); ii++)
                                    {
                                        swdm.Write(x[ii, 0] + "(" + x[ii, 1] + ")" + sepChar);
                                    }
                                    swdm.WriteLine();
                                    x = fxj.GetData("dm", node.Text.Split('|')[1], 0);
                                    if (fxj.Error == 1 && errorCounts < 10)
                                    {
                                        status3.Text += DateTime.Now.ToString("HH:mm:ss") + ":" + node.Text.Split('|')[1] + "," + fxj.Msg + (errorCounts == 9 ? "\n ………………" : "") + " \n"; errorCounts++;
                                    }
                                    for (int ii = 0; ii < x.GetLength(0); ii++)
                                    {
                                        status2.Text = x[ii, 0];
                                        Application.DoEvents();
                                        if (stopConverting)
                                        {
                                            swdm.Close(); return;
                                        }
                                        for (int jj = 0; jj < x.GetLength(1); jj++)
                                        {
                                            swdm.Write(x[ii, jj] + sepChar);
                                        }
                                        swdm.WriteLine();
                                    }
                                    swdm.Close();
                                    status3.Text += DateTime.Now.ToString("HH:mm:ss") + ":生成" + node.Text.Split('|')[3] + " \n";
                                    break;

                                case "bk":
                                case "pj":
                                    StreamWriter sw0 = new StreamWriter(descPath.Text + @"\" + node.Text.Split('|')[3], false);
                                    x = fxj.GetFields(node.Text.Split('|')[2]);
                                    for (int ii = 0; ii < x.GetLength(0); ii++)
                                    {
                                        sw0.Write(x[ii, 0] + "(" + x[ii, 1] + ")" + sepChar);
                                    }
                                    sw0.WriteLine();
                                    x = fxj.GetData(node.Text.Split('|')[2], "", 0);
                                    if (fxj.Error == 1 && errorCounts < 10)
                                    {
                                        status3.Text += DateTime.Now.ToString("HH:mm:ss") + ":" + node.Text.Split('|')[2] + "," + fxj.Msg + (errorCounts == 9 ? "\n ………………" : "") + " \n"; errorCounts++;
                                    }
                                    for (int ii = 0; ii < x.GetLength(0); ii++)
                                    {
                                        status2.Text = x[ii, 0];
                                        Application.DoEvents();
                                        if (stopConverting)
                                        {
                                            sw0.Close(); return;
                                        }
                                        for (int jj = 0; jj < x.GetLength(1); jj++)
                                        {
                                            sw0.Write(x[ii, jj] + sepChar);
                                        }
                                        sw0.WriteLine();
                                    }
                                    sw0.Close();
                                    status3.Text += DateTime.Now.ToString("HH:mm:ss") + ":生成" + node.Text.Split('|')[3] + " \n";
                                    break;

                                default:
                                    StreamWriter sw = new StreamWriter(descPath.Text + @"\" + node.Text.Split('|')[3], false);
                                    x = fxj.GetFields(node.Text.Split('|')[2]);
                                    for (int ii = 0; ii < x.GetLength(0); ii++)
                                    {
                                        sw.Write(x[ii, 0] + "(" + x[ii, 1] + ")" + sepChar);
                                    }
                                    sw.WriteLine();
                                    for (int c = 0; c < codes.GetLength(0); c++)
                                    {
                                        if (fxj.GetCodeType(codes[c, 0]) != "")
                                        {
                                            status2.Text = codes[c, 0];
                                            Application.DoEvents();

                                            x = fxj.GetData(node.Text.Split('|')[2], codes[c, 0], node.Text.Split('|')[4], 0);
                                            if (fxj.Error == 1 && errorCounts < 10)
                                            {
                                                status3.Text += DateTime.Now.ToString("HH:mm:ss") + ":" + codes[c, 0] + "," + fxj.Msg + (errorCounts == 9?"\n ………………":"") + " \n"; errorCounts++;
                                            }
                                            for (int ii = 0; ii < x.GetLength(0); ii++)
                                            {
                                                if (stopConverting)
                                                {
                                                    sw.Close(); return;
                                                }
                                                s = "";
                                                for (int jj = 0; jj < x.GetLength(1); jj++)
                                                {
                                                    s += x[ii, jj] + sepChar;
                                                }
                                                sw.WriteLine(s);
                                            }
                                        }
                                    }
                                    status3.Text += DateTime.Now.ToString("HH:mm:ss") + ":生成" + node.Text.Split('|')[3] + " \n";
                                    sw.Close();
                                    break;
                                }
                            }
                        }
                    }
                }
            }//try
            catch (Exception ex)
            {
                status3.Text += "发生错误:" + ex.Message + "\n";
            }
            finally
            {
                button1.Text      = "转换(&T)";
                stopConverting    = false;
                outputBox.Enabled = true;
                treeView1.Enabled = true;
                status3.Text     += DateTime.Now.ToString("HH:mm:ss") + ":转换结束.\n";
            }
        }
예제 #2
0
파일: MainForm.cs 프로젝트: weiqk/FinData
 private void testToolStripMenuItem_Click(object sender, EventArgs e)
 {
     FinData.FxjData fxj = new FxjData();
     string[,] x = fxj.GetData("hqfq", "SZ000001", 0);
     MessageBox.Show(x[1, 1]);
 }