Code

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Collections;
namespace ApplicationCaipiao
{
    public partial class Form1 : Form
    {
        DataBaseDao Dao = null;
        int Number = 0;
        public Form1()
        {
            InitializeComponent();
            Dao = new DataBaseDao();
            comboBox1.SelectedIndex = 0;
        }

        private void textEdit5_EditValueChanged(object sender, EventArgs e)
        {

        }

        private void simpleButton1_Click(object sender, EventArgs e)
        {
           //
           ArrayList list = new ArrayList();
           if (!string.IsNullOrEmpty(txt1.Text))
               list.Add(txt1.Text.Trim());
            if (!string.IsNullOrEmpty(txt2.Text))
               list.Add(txt2.Text.Trim());
           if (!string.IsNullOrEmpty(txt3.Text))
               list.Add(txt3.Text.Trim());
           if (!string.IsNullOrEmpty(txt4.Text))
               list.Add(txt4.Text.Trim());
           if (!string.IsNullOrEmpty(txt5.Text))
               list.Add(txt5.Text.Trim());
           if (!string.IsNullOrEmpty(txt6.Text))
               list.Add(txt6.Text.Trim());
           if (!string.IsNullOrEmpty(txt7.Text))
               list.Add(txt7.Text.Trim());
           string strCol = string.Empty;
           string strValue = string.Empty;
           foreach (object s in list)
           {
               strValue +=  s.ToString() + ",";
               strCol += "["+s.ToString() + "],";
           }
           Dao.OperateDB("insert into caipiao(Type," + strCol.Substring(0, strCol.Length - 1) + ")values(" + comboBox1.Text + "," + strValue.Substring(0, strValue.Length - 1) + ")");
           txt1.Text = txt2.Text = txt3.Text = txt4.Text = txt5.Text = txt6.Text = txt7.Text = string.Empty;

        }

        private void simpleButton3_Click(object sender, EventArgs e)
        {
            DataTable TmeTable = new DataTable();
            TmeTable.Columns.Add("Num", typeof(int));
            TmeTable.Columns.Add("Value", typeof(int));
            string strCol = string.Empty;
            if (comboBox1.Text == "1")
            {
                for (int i = 1; i <= 26; i++)
                {
                    strCol += "[" + i.ToString() + "],";
                    DataRow dr = TmeTable.NewRow();
                    dr["Num"] = i;
                    DataTable tb = Dao.getTable("Select [" + i + "] from caipiao where Type=" + comboBox1.Text + " and [" + i + "]=" + i);
                    dr["Value"] = tb.Rows.Count;
                    TmeTable.Rows.Add(dr);
                }

                DataTable _dtTable = Dao.getTable("Select ID," + strCol.Substring(0, strCol.Length - 1) + " from caipiao where Type=" + comboBox1.Text+" order by ID ASC");
                labelControl4.Text ="一共录入了["+ _dtTable.Rows.Count.ToString()+"]期";
                gridControl2.DataSource = _dtTable;

            }

            else if (comboBox1.Text == "2")
            {
                for (int i = 1; i <= 33; i++)
                {
                    DataRow dr = TmeTable.NewRow();
                    dr["Num"] = i;
                    DataTable tb = Dao.getTable("Select [" + i + "] from caipiao where Type=" + comboBox1.Text + " and [" + i + "]=" + i);
                    dr["Value"] = tb.Rows.Count;
                    TmeTable.Rows.Add(dr);
                }
            }


            else if (comboBox1.Text == "3")
            {
                for (int i = 1; i <= 36; i++)
                {
                    DataRow dr = TmeTable.NewRow();
                    dr["Num"] = i;
                    DataTable tb = Dao.getTable("Select [" + i + "] from caipiao where Type=" + comboBox1.Text + " and [" + i + "]=" + i);
                    dr["Value"] = tb.Rows.Count;
                    TmeTable.Rows.Add(dr);
                }
            }

            this.gridControl1.DataSource = TmeTable;
            string strNumber = string.Empty;
            if (!string.IsNullOrEmpty(this.textEdit2.Text))
            {
              DataRow[]  drRows= TmeTable.Select("Value=" + textEdit2.Text);
              foreach (DataRow row in drRows)
              {
                  strNumber += row["Num"].ToString() + "---";
              }
              textEdit8.Text = strNumber;
            }
            this.gridView2.BestFitColumns();
        }

        private void Form1_KeyUp(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                simpleButton1_Click(null, null);
            }
        }

        private void simpleButton4_Click(object sender, EventArgs e)
        {
         
           Dao.OperateDB("Delete from  caipiao where  ID="+ this.gridView2.GetFocusedRowCellValue("ID").ToString());
           simpleButton3_Click(null, null);
        }

        private void simpleButton5_Click(object sender, EventArgs e)
        {
            Number = 0;
            DataTable _dtTable = null;
            string strCol = string.Empty;
           
            if (comboBox1.Text == "1")
            {
                for (int i = 1; i <= 26; i++)
                {
                    strCol += "[" + i.ToString() + "],";
                }

               _dtTable = Dao.getTable("Select " + strCol.Substring(0, strCol.Length - 1) + " from caipiao where Type=" + comboBox1.Text + " and ID="+this.gridView2.GetFocusedRowCellValue("ID").ToString()+" order by ID ASC");
              
               for (int i = 1; i <= 26; i++)
               {
                   if (_dtTable.Rows[0][i.ToString()].ToString() != "")
                   {
                      Number+= Convert.ToInt32(_dtTable.Rows[0][i.ToString()].ToString());
                   }
               }

               this.textEdit3.Text = Number.ToString();
            }

            else if (comboBox1.Text == "2")
            {
                for (int i = 1; i <= 33; i++)
                {
                    strCol += "[" + i.ToString() + "],";
                }
            }


            else if (comboBox1.Text == "3")
            {
                for (int i = 1; i <= 36; i++)
                {
                    strCol += "[" + i.ToString() + "],";
                }
            }
        }

        private void simpleButton6_Click(object sender, EventArgs e)
        {
            string strrl = string.Empty;
            int Danshu = 70 - Number;
            strrl += Danshu.ToString() + "---";
            int LinMa = 27 - (70 - Number);
            strrl += LinMa.ToString() + "---";
            int LinMA1=Danshu-1;
            int LinMA2=Danshu+1;
            strrl += LinMA1.ToString() + "---" + LinMA2 + "---";
            this.textEdit4.Text = strrl;
        }

 


    }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值