Ejemplo n.º 1
0
        private void button3_Click(object sender, EventArgs e)
        {
            try
            {
                if (String.IsNullOrEmpty(cmbxTableNames.Text))
                {
                    MessageBox.Show("未加载任何数据表!");
                    return;
                }
                if (String.IsNullOrEmpty(cmbxXField.Text) || String.IsNullOrEmpty(cmbxYField.Text))
                {
                    MessageBox.Show("自变量和因变量不能为空");
                    return;
                }


                //根据选择的自变量因变量字段,及行范围,新生成表
                DataTable     sourceDt   = dataGridView1.DataSource as DataTable;
                List <string> fieldNames = new List <string>()
                {
                    cmbxXField.Text, cmbxYField.Text
                };
                List <string> fieldNames1 = new List <string>()
                {
                    cmbxXField.Text, cmbxZField.Text
                };
                int       startRowNum = Convert.ToInt32(txbxStartRowNum.Text) - 1; //DataTable的行号从0开始
                int       endRowNum   = Convert.ToInt32(txbxEndRowNum.Text) - 1;
                DataTable resultDt    = DataTableImp.GetTableByFieldNamesAndRowNumRange(sourceDt, fieldNames, fieldNames1, startRowNum, endRowNum);


                SaveFileDialog saveFileDlg = new System.Windows.Forms.SaveFileDialog();
                saveFileDlg.Title    = "导出统计表";
                saveFileDlg.Filter   = "Excel文件|*.xls;*.xlsx";
                saveFileDlg.FileName = cmbxValueDescribe.Text;

                string excelFile;
                if (saveFileDlg.ShowDialog() == DialogResult.OK)
                {
                    excelFile = saveFileDlg.FileName;

                    if (ExcelFileOperate.SaveDataTableToXls(resultDt, excelFile))
                    {
                        MessageBox.Show("数据导出成功!保存到" + excelFile);
                    }
                    else
                    {
                        MessageBox.Show("导出失败!");
                    }
                }
            }
            catch (System.Exception ex)
            {
                MessageBox.Show("统计表导出失败!");
                return;
            }
        }
Ejemplo n.º 2
0
        private void btnChart_Click(object sender, EventArgs e)
        {
            if (String.IsNullOrEmpty(cmbxTableNames1.Text))
            {
                MessageBox.Show("未加载任何数据表!");
                return;
            }
            if (String.IsNullOrEmpty(cmbxXField1.Text) || String.IsNullOrEmpty(cmbxYField1.Text) || String.IsNullOrEmpty(cmbxYField2.Text) || String.IsNullOrEmpty(cmbxYField3.Text) || String.IsNullOrEmpty(cmbxYField4.Text))
            {
                MessageBox.Show("自变量和因变量不能为空");
                return;
            }

            //判断因变量字段是否是值字段,或者是否能强制转换成值
            DataTable      sourceDt    = dataGridView2.DataSource as DataTable;
            FieldValueType yFieldType1 = DataTableImp.GetFieldType(sourceDt, cmbxYField1.Text);
            FieldValueType yFieldType2 = DataTableImp.GetFieldType(sourceDt, cmbxYField2.Text);
            FieldValueType yFieldType3 = DataTableImp.GetFieldType(sourceDt, cmbxYField3.Text);
            FieldValueType yFieldType4 = DataTableImp.GetFieldType(sourceDt, cmbxYField4.Text);

            if (yFieldType1 == FieldValueType.非值文本 || yFieldType2 == FieldValueType.非值文本 || yFieldType3 == FieldValueType.非值文本 || yFieldType4 == FieldValueType.非值文本)
            {
                MessageBox.Show("因变量字段不可为非数值字段!");
                return;
            }
            List <string> fieldNames1 = new List <string>()
            {
                cmbxXField1.Text, cmbxYField1.Text
            };
            List <string> fieldNames2 = new List <string>()
            {
                cmbxXField1.Text, cmbxYField2.Text
            };
            List <string> fieldNames3 = new List <string>()
            {
                cmbxXField1.Text, cmbxYField3.Text
            };
            List <string> fieldNames4 = new List <string>()
            {
                cmbxXField1.Text, cmbxYField4.Text
            };
            int       startRowNum = Convert.ToInt32(txbxStartRowNum1.Text) - 1; //DataTable的行号从0开始
            int       endRowNum   = Convert.ToInt32(txbxEndRowNum1.Text) - 1;
            DataTable tempDt      = DataTableImp.GetTableByFieldNamesAndRowNumRange2(sourceDt, fieldNames1, fieldNames2, fieldNames3, fieldNames4, startRowNum, endRowNum);
            //再进行因变量字段值的值类型转换
            DataTable resultDt = DataTableImp.ConvertFieldToType2(tempDt, cmbxYField1.Text, cmbxYField2.Text, cmbxYField3.Text, cmbxYField4.Text, yFieldType1, yFieldType2, yFieldType3, yFieldType4);
            LineChart linefrm  = new LineChart(resultDt, cmbxXField1.Text, cmbxYField1.Text, cmbxYField2.Text, cmbxYField3.Text, cmbxYField4.Text, cmbxValueDescribe01.Text, cmbxValueDescribe02.Text, cmbxValueDescribe03.Text, cmbxValueDescribe04.Text);

            linefrm.ShowDialog();
        }
Ejemplo n.º 3
0
        private void button2_Click(object sender, EventArgs e)
        {
            if (String.IsNullOrEmpty(cmbxTableNames.Text))
            {
                MessageBox.Show("未加载任何数据表!");
                return;
            }
            if (String.IsNullOrEmpty(cmbxXField.Text) || String.IsNullOrEmpty(cmbxYField.Text))
            {
                MessageBox.Show("自变量和因变量不能为空");
                return;
            }

            //判断因变量字段是否是值字段,或者是否能强制转换成值
            DataTable      sourceDt   = dataGridView1.DataSource as DataTable;
            FieldValueType yFieldType = DataTableImp.GetFieldType(sourceDt, cmbxYField.Text);
            FieldValueType zFieldType = DataTableImp.GetFieldType(sourceDt, cmbxZField.Text);

            if (yFieldType == FieldValueType.非值文本 || zFieldType == FieldValueType.非值文本)
            {
                MessageBox.Show("因变量字段不可为非数值字段!");
                return;
            }
            //if (zFieldType == FieldValueType.非值文本)
            //{
            //    MessageBox.Show("因变量字段不可为非数值字段!");
            //    return;
            //}

            //根据选择的自变量因变量字段,及行范围,新生成表
            List <string> fieldNames = new List <string>()
            {
                cmbxXField.Text, cmbxYField.Text
            };
            List <string> fieldNames1 = new List <string>()
            {
                cmbxXField.Text, cmbxZField.Text
            };
            int startRowNum = Convert.ToInt32(txbxStartRowNum.Text) - 1; //DataTable的行号从0开始
            int endRowNum   = Convert.ToInt32(txbxEndRowNum.Text) - 1;
            //先进行行列筛选
            DataTable tempDt = DataTableImp.GetTableByFieldNamesAndRowNumRange(sourceDt, fieldNames, fieldNames1, startRowNum, endRowNum);
            //再进行因变量字段值的值类型转换
            DataTable    resultDt = DataTableImp.ConvertFieldToType(tempDt, cmbxYField.Text, cmbxZField.Text, yFieldType, zFieldType);
            ColumnChart1 chartFrm = new ColumnChart1(resultDt, cmbxXField.Text, cmbxYField.Text, cmbxZField.Text, cmbxValueDescribe.Text, cmbxValueDescribe1.Text);

            chartFrm.ShowDialog();
        }