frmmonthreport.cs

来自「关于医院进销存的系统」· CS 代码 · 共 78 行

CS
78
字号
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;

namespace YYJXC
{
    public partial class frmMonthReport : Form
    {
        public frmMonthReport()
        {
            InitializeComponent();
        }
        private DataSet ds = new DataSet();
        private void MyDataTiem()
        {
            string year = DateTime.Now.Year.ToString() + "年";
            string month = DateTime.Now.Month.ToString() + "月";
            for (int i = 0; i < cbYear.Items.Count; i++)
            {
                if (cbYear.Items[i].ToString() == year)
                {
                    cbYear.SelectedIndex = i;
                    break;
                }
            }
            for (int i = 1; i < cbMonth.Items.Count; i++)
            {
                if (cbMonth.Items[i].ToString() == month)
                {
                    cbMonth.SelectedIndex = i;
                }
            }
        }

        private void ShowData(string year,string month)
        {
            string Lyear = year.Substring(0, 4);
            string Lmonth = month.Substring(0, month.Length - 1);
            int maxDay = DateTime.DaysInMonth(int.Parse(Lyear), int.Parse(Lmonth));
            DataView dv = new DataView(ds.Tables[0]);
            dv.RowFilter = "日期 >= '" + Lyear + "-" + Lmonth + "-1' and 日期 <= '" + Lyear + "-" + Lmonth + "-" + maxDay.ToString() + "'";
            dv.Sort = "日期";
            dataGridView1.DataSource = dv;
        }
        private void frmMonthReport_Load(object sender, EventArgs e)
        {
            this.WindowState = FormWindowState.Maximized;
            for (int i = 2000; i < 2051; i++)
            {
                cbYear.Items.Add(i.ToString() + "年");
            }
            for (int i = 1; i < 13; i++)
            {
                cbMonth.Items.Add(i.ToString() + "月");
            }
            MyDataTiem();
            SqlConnection Conn = new SqlConnection("server=" + CLoad.ReadServer() + ";pwd=" + CLoad.ReadPwd() + ";uid=sa;database=YYJXC");
            SqlDataAdapter da = new SqlDataAdapter("select 销售单据号,品种数,数量,金额,折扣,税率,应收,实收,未收,收款方式,经手人,日期 from tb_sell_main", Conn);
            da.Fill(ds, "tb_sell_main");
            ShowData(cbYear.Text, cbMonth.Text);
        }

        private void button1_Click(object sender, EventArgs e)
        {
            ShowData(cbYear.Text, cbMonth.Text);
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?