Esempio n. 1
0
        private void Main_Load(object sender, EventArgs e)
        {
            Checkit();
            VisibleFalseLabel();
            LblCart.Visible      = true;
            LblCartInfo.Visible  = true;
            LblLiveInfo.Visible  = true;
            LblUsingUser.Visible = true;
            picBoxCheck1.Visible = true;
            //picBoxCheck2.Visible = true;
            dataGridView1.Visible   = true;
            btnCart.BackgroundImage = Image.FromFile("menuCart2.jpg");
            pictureBox2.BackColor   = Color.FromArgb(234, 234, 234);
            dataGridView1.AlternatingRowsDefaultCellStyle.BackColor = Color.AliceBlue;
            dataGridView2.AlternatingRowsDefaultCellStyle.BackColor = Color.AliceBlue;
            dataGridView3.AlternatingRowsDefaultCellStyle.BackColor = Color.AliceBlue;

            dataGridView1.RowHeadersVisible = false;
            dataGridView2.RowHeadersVisible = false;
            dataGridView3.RowHeadersVisible = false;

            //this.FormBorderStyle = FormBorderStyle.FixedSingle;

            //쓰레드 시작
            fThreadStart();

            //오늘 날짜
            int    nowYear   = DateTime.Now.Year;               //오늘 년
            int    nowMonth  = DateTime.Now.Month;              //오늘 월
            string nowWeek   = DTPlast1.Value.ToString("dddd"); //오늘 요일
            int    nowHour   = DateTime.Now.Hour;               //오늘 시
            int    nowMinute = DateTime.Now.Minute;             //오늘 분
            int    firstDay  = DateTime.Now.Day - 7;            //일주일 전 날짜
            int    lastDay   = DateTime.Now.Day;                //오늘 날짜

            //총매출액 그래프 날짜
            DTPfirst1.Value = new DateTime(nowYear, nowMonth, firstDay);
            DTPlast1.Value  = new DateTime(nowYear, nowMonth, lastDay);
            //상품별 매출액 그래프 날짜
            DTPfirst2.Value = new DateTime(nowYear, nowMonth, firstDay);
            DTPlast2.Value  = new DateTime(nowYear, nowMonth, lastDay);

            int firstyear1  = DTPfirst1.Value.Year;
            int firstmonth1 = DTPfirst1.Value.Month;
            int firstday1   = DTPfirst1.Value.Day;
            int lastyear1   = DTPlast1.Value.Year;
            int lastmonth1  = DTPlast1.Value.Month;
            int lastday1    = DTPlast1.Value.Day;
            int firstyear2  = DTPfirst2.Value.Year;
            int firstmonth2 = DTPfirst2.Value.Month;
            int firstday2   = DTPfirst2.Value.Day;
            int lastyear2   = DTPlast2.Value.Year;
            int lastmonth2  = DTPlast2.Value.Month;
            int lastday2    = DTPlast2.Value.Day;

            //총매출액 그래프
            string          Querysale = "SELECT date_format(buydate, '%m-%d') AS date, sum(price) FROM `order` WHERE buydate BETWEEN date('" + firstyear1 + "-" + firstmonth1 + "-" + firstday1 + "') AND date('" + lastyear1 + "-" + lastmonth1 + "-" + lastday1 + "') GROUP BY buydate";
            string          constring = "datasource=localhost; database=smartcart; username=root; password=apmsetup;";
            MySqlConnection consaleDB = new MySqlConnection(constring);
            MySqlCommand    cmdsaleDB = new MySqlCommand(Querysale, consaleDB);
            MySqlDataReader myreadersale;

            consaleDB.Open();
            myreadersale = cmdsaleDB.ExecuteReader();
            chartSum.Series.Clear();
            chartSum.Series.Add("price");
            try
            {
                while (myreadersale.Read())
                {
                    string date = myreadersale.GetString("date");
                    chartSum.Series["price"].Points.AddXY(date, myreadersale.GetString("sum(price)"));
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            consaleDB.Close();

            //상품별 매출액 그래프
            ArrayList ProdList = new ArrayList();

            chartProd.Series.Clear();
            string          QueryPdMenu1 = "SELECT name FROM `product`";
            MySqlConnection conPdmenuDB1 = new MySqlConnection(constring);
            MySqlCommand    cmdPdmenuDB1 = new MySqlCommand(QueryPdMenu1, conPdmenuDB1);
            MySqlDataReader myreaderPdmenu1;

            try
            {
                conPdmenuDB1.Open();
                myreaderPdmenu1 = cmdPdmenuDB1.ExecuteReader();
                while (myreaderPdmenu1.Read())
                {
                    string sName   = myreaderPdmenu1.GetString("name");
                    Series series1 = chartProd.Series.Add(sName);
                    ProdList.Add(sName);
                }
                conPdmenuDB1.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

            //string QueryPdMenu2 = "SELECT product FROM `order`";
            //MySqlConnection conPdMenuDB2 = new MySqlConnection(constring);
            //MySqlCommand cmdPdmenuDB2 = new MySqlCommand(QueryPdMenu2, conPdMenuDB2);
            //MySqlDataReader myreaderPdmenu2;
            //try
            //{
            //    conPdMenuDB2.Open();
            //    myreaderPdmenu2 = cmdPdmenuDB2.ExecuteReader();
            //    while (myreaderPdmenu2.Read())
            //    {
            //        string sName = myreaderPdmenu2.GetString("product");
            //        for (int i = 0; i < ProdList.Count; i++)
            //        {
            //            if (!sName.Equals((string)ProdList[i]))
            //            {
            //                ProdList.Add(sName);
            //            }
            //        }
            //    }
            //    conPdMenuDB2.Close();
            //}
            //catch (Exception ex)
            //{
            //    MessageBox.Show(ex.Message + "오오");
            //}

            ArrayList QueryPdCnt = new ArrayList();

            for (int i = 0; i < ProdList.Count; i++)
            {
                QueryPdCnt.Add($"SELECT date_format(buydate, '%m-%d') AS date, count(product) FROM `order` WHERE product = '{ProdList[i]}' AND buydate BETWEEN date('{firstyear2}-{firstmonth2}-{firstday2}') AND date('{lastyear2}-{lastmonth2}-{lastday2}') GROUP BY buydate");
                MySqlConnection conPdCntDB = new MySqlConnection(constring);
                MySqlCommand    cmdPdCntDB = new MySqlCommand((string)QueryPdCnt[i], conPdCntDB);
                MySqlDataReader myreader;
                try
                {
                    conPdCntDB.Open();
                    myreader = cmdPdCntDB.ExecuteReader();
                    while (myreader.Read())
                    {
                        string sCount = myreader.GetString("count(product)");
                        string sDay   = myreader.GetString("date");
                        chartProd.Series[(string)ProdList[i]].Points.AddXY(sDay, sCount);
                    }
                    conPdCntDB.Close();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message + ProdList.Count + "라라");
                }
            }

            //실시간 시간
            LblNowDate.Text = "" + nowYear + "년 " + nowMonth + "월 " + lastDay + "일 " + nowWeek + " " + nowHour + "시 " + nowMinute + "분";

            //로그인 창 띄우기
            loginForm = new Login();
            loginForm.loginEventHandler += new EventHandler(LoginSuccess);
            switch (loginForm.ShowDialog())
            {
            case DialogResult.OK:
                loginForm.Close();
                break;

            case DialogResult.Cancel:
                Dispose();
                break;
            }

            //DataGridView1에 Cart 실시간 현황 테이블 생성
            string    sql = "SELECT * FROM `cart`";
            DataTable dt  = db.GetDBTable(sql);

            dataGridView1.DataSource = dt;

            dataGridView1.Columns["cartNumber"].HeaderText = "카트 번호";
            dataGridView1.Columns["cartName"].HeaderText   = "카트 이름";
            dataGridView1.Columns["usingName"].HeaderText  = "사용자 정보";

            dataGridView1.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
            dataGridView2.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
            dataGridView3.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;

            //db 행 색깔,폰트 색깔
            dataGridView1.EnableHeadersVisualStyles = false;
            dataGridView1.ColumnHeadersDefaultCellStyle.BackColor = Color.CornflowerBlue;
            dataGridView1.ColumnHeadersDefaultCellStyle.ForeColor = Color.White;
            dataGridView2.EnableHeadersVisualStyles = false;
            dataGridView2.ColumnHeadersDefaultCellStyle.BackColor = Color.CornflowerBlue;
            dataGridView2.ColumnHeadersDefaultCellStyle.ForeColor = Color.White;
            dataGridView3.EnableHeadersVisualStyles = false;
            dataGridView3.ColumnHeadersDefaultCellStyle.BackColor = Color.CornflowerBlue;
            dataGridView3.ColumnHeadersDefaultCellStyle.ForeColor = Color.White;

            dataGridView1.ClearSelection();
            dataGridView2.ClearSelection();
            dataGridView3.ClearSelection();
        }
Esempio n. 2
0
        private void Main_Load(object sender, EventArgs e)
        {
            Checkit();
            VisibleFalseLabel();
            LblCart.Visible         = true;
            LblCartInfo.Visible     = true;
            LblLiveInfo.Visible     = true;
            LblUsingUser.Visible    = true;
            picBoxCheck1.Visible    = true;
            picBoxCheck2.Visible    = true;
            dataGridView1.Visible   = true;
            btnCart.BackgroundImage = Image.FromFile("menuCart2.jpg");
            pictureBox2.BackColor   = Color.FromArgb(234, 234, 234);

            dataGridView1.RowHeadersVisible = false;
            dataGridView2.RowHeadersVisible = false;
            dataGridView3.RowHeadersVisible = false;


            //오늘 날짜
            int    nowYear   = DateTime.Now.Year;               //오늘 년
            int    nowMonth  = DateTime.Now.Month;              //오늘 월
            string nowWeek   = DTPlast1.Value.ToString("dddd"); //오늘 요일
            int    nowHour   = DateTime.Now.Hour;               //오늘 시
            int    nowMinute = DateTime.Now.Minute;             //오늘 분
            int    firstDay  = DateTime.Now.Day - 7;            //일주일 전 날짜
            int    lastDay   = DateTime.Now.Day;                //오늘 날짜

            //총매출액 그래프 날짜
            DTPfirst1.Value = new DateTime(nowYear, nowMonth, firstDay);
            DTPlast1.Value  = new DateTime(nowYear, nowMonth, lastDay);
            //상품별 매출액 그래프 날짜
            DTPfirst2.Value = new DateTime(nowYear, nowMonth, firstDay);
            DTPlast2.Value  = new DateTime(nowYear, nowMonth, lastDay);

            int firstyear  = DTPfirst1.Value.Year;
            int firstmonth = DTPfirst1.Value.Month;
            int firstday   = DTPfirst1.Value.Day;
            int lastyear   = DTPlast1.Value.Year;
            int lastmonth  = DTPlast1.Value.Month;
            int lastday    = DTPlast1.Value.Day;

            //총매출액 그래프
            string          Querysale = "  select date_format(buydate, '%m-%d') as date, sum(price) from `order` where buydate between date('" + firstyear + "-" + firstmonth + "-" + firstday + "') AND date('" + lastyear + "-" + lastmonth + "-" + lastday + "') group by buydate";
            string          constring = "server=localhost; database=smartcart; uid=root; password=apmsetup;";
            MySqlConnection consaleDB = new MySqlConnection(constring);
            MySqlCommand    cmdsaleDB = new MySqlCommand(Querysale, consaleDB);
            MySqlDataReader myreadersale;

            consaleDB.Open();
            myreadersale = cmdsaleDB.ExecuteReader();
            chartSum.Series.Clear();
            Series series = chartSum.Series.Add("price");

            try
            {
                while (myreadersale.Read())
                {
                    string date = myreadersale.GetString("date");
                    chartSum.Series["price"].Points.AddXY(date, myreadersale.GetString("sum(price)"));
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            consaleDB.Close();

            //실시간 시간
            LblNowDate.Text = "" + nowYear + "년 " + nowMonth + "월 " + lastDay + "일 " + nowWeek + " " + nowHour + "시 " + nowMinute + "분";

            //로그인 창 띄우기
            loginForm = new Login();
            loginForm.loginEventHandler += new EventHandler(LoginSuccess);
            switch (loginForm.ShowDialog())
            {
            case DialogResult.OK:
                loginForm.Close();
                break;

            case DialogResult.Cancel:
                Dispose();
                break;
            }

            //DataGridView1에 Cart 실시간 현황 테이블 생성
            string    sql = "SELECT * FROM `cart`";
            DataTable dt  = db.GetDBTable(sql);

            dataGridView1.DataSource = dt;

            dataGridView1.Columns["cartNumber"].HeaderText = "카트 번호";
            dataGridView1.Columns["cartName"].HeaderText   = "카트 이름";
            dataGridView1.Columns["usingName"].HeaderText  = "사용자 정보";

            dataGridView1.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
            dataGridView2.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
            dataGridView3.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
        }