Exemplo n.º 1
0
            /// <summary>
            /// データグリッドビューの指定行のデータを取得する
            /// </summary>
            /// <param name="dgv">対象とするデータグリッドビューオブジェクト</param>
            public static Boolean GetData(DataGridView dgv, ref Entity.天候 tempC)
            {
                int    iX = 0;
                string sqlStr;

                Control.天候      Tenkou = new Control.天候();
                OleDbDataReader dR;

                sqlStr = " where 天候.日付 = '" + dgv[0, dgv.SelectedRows[iX].Index].Value.ToString() + "'";
                dR     = Tenkou.FillBy(sqlStr);

                if (dR.HasRows == true)
                {
                    while (dR.Read() == true)
                    {
                        tempC.日付  = DateTime.Parse(dR["日付"].ToString());
                        tempC.天候名 = dR["天候"].ToString() + "";
                    }
                }
                else
                {
                    dR.Close();
                    Tenkou.Close();
                    return(false);
                }

                dR.Close();
                Tenkou.Close();
                return(true);
            }
Exemplo n.º 2
0
        //登録データチェック
        private Boolean fDataCheck()
        {
            try
            {
                //登録モードのとき、コードをチェック
                if (fMode.Mode == 0)
                {
                    //// 数字か?
                    //if (txtDATE.Text == null)
                    //{
                    //    this.txtDATE.Focus();
                    //    throw new Exception("コードは数字で入力してください");
                    //}

                    //str = this.txtDATE.Text;

                    //if (double.TryParse(str, System.Globalization.NumberStyles.Any, System.Globalization.NumberFormatInfo.InvariantInfo, out d))
                    //{
                    //}
                    //else
                    //{
                    //    this.txtDATE.Focus();
                    //    throw new Exception("コードは数字で入力してください");
                    //}

                    //// 未入力またはスペースのみは不可
                    //if ((this.txtDATE.Text).Trim().Length < 1)
                    //{
                    //    this.txtDATE.Focus();
                    //    throw new Exception("コードを入力してください");
                    //}

                    ////ゼロは不可
                    //if (Convert.ToInt32(this.txtDATE.Text.ToString()) == 0)
                    //{
                    //    this.txtDATE.Focus();
                    //    throw new Exception("ゼロは登録できません");
                    //}

                    ////登録済みコードか調べる
                    //string sqlStr;
                    //Control.所属 Shozoku = new Control.所属();
                    //OleDbDataReader dr;

                    //sqlStr = " where ID = " + txtDATE.Text.ToString();
                    //dr = Shozoku.FillBy(sqlStr);

                    //if (dr.HasRows == true)
                    //{
                    //    txtDATE.Focus();
                    //    dr.Close();
                    //    Shozoku.Close();
                    //    throw new Exception("既に登録済みのコードです");
                    //}

                    //dr.Close();
                    //Shozoku.Close();
                }

                //名称チェック
                if (comboBox1.Text.Trim().Length < 1)
                {
                    comboBox1.Focus();
                    throw new Exception("天候を入力してください");
                }

                //所属クラスにデータセット
                cMaster.日付  = dateTimePicker1.Value;
                cMaster.天候名 = comboBox1.Text.ToString();

                if (fMode.Mode == 0)
                {
                    cMaster.登録年月日 = DateTime.Today;
                }
                cMaster.更年月日 = DateTime.Today;

                //登録済みか?
                OleDbDataReader dR;
                Control.天候      cTenkou = new Control.天候();
                dR = cTenkou.FillBy("where 日付 = '" + dateTimePicker1.Text + "'");

                if (dR.HasRows == true)
                {
                    fMode.Mode = 1;
                }
                else
                {
                    fMode.Mode = 0;
                }

                dR.Close();
                cTenkou.Close();

                return(true);
            }

            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, MESSAGE_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return(false);
            }
        }
Exemplo n.º 3
0
        private void btnUpdate_Click(object sender, EventArgs e)
        {
            try
            {
                if (fDataCheck() == true)
                {
                    Control.天候 cTenkou = new Control.天候();

                    switch (fMode.Mode)
                    {
                    case 0:     //新規登録
                        if (MessageBox.Show("新規登録します。よろしいですか?", "登録確認", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
                        {
                            cTenkou.Close();
                            return;
                        }

                        if (cTenkou.DataInsert(cMaster) == true)
                        {
                            MessageBox.Show("新規登録されました", MESSAGE_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                        else
                        {
                            MessageBox.Show("新規登録に失敗しました", MESSAGE_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Stop);
                        }

                        break;

                    case 1:     //更新
                        if (MessageBox.Show("更新します。よろしいですか?", "更新確認", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
                        {
                            cTenkou.Close();
                            return;
                        }

                        if (cTenkou.DataUpdate(cMaster) == true)
                        {
                            MessageBox.Show("更新されました", MESSAGE_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                        else
                        {
                            MessageBox.Show("更新に失敗しました", MESSAGE_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Stop);
                        }

                        break;
                    }

                    cTenkou.Close();

                    //日付別天候表示
                    GridviewSet.ShowData(dataGridView1, int.Parse(txtYear.Text), int.Parse(txtMonth.Text));

                    //天候コンボリロード
                    Utility.ComboTenkou.load(comboBox1);

                    comboBox1.Text = "";

                    //DispClear();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message.ToString(), "更新処理", MessageBoxButtons.OK, MessageBoxIcon.Stop);
            }
        }
Exemplo n.º 4
0
            public static void ShowData(DataGridView tempDGV, int tempYear, int tempMonth)
            {
                string   sqlSTRING = "";
                string   rDate;
                int      iDay, iX, c1, c2;
                DateTime sDate;

                try
                {
                    //天候データのデータリーダーを取得する
                    OleDbDataReader dR;
                    Control.天候      dCon = new Control.天候();

                    tempDGV.RowCount = 0;

                    iDay = 0;
                    iX   = 0;

                    while (true)
                    {
                        iDay++;

                        rDate = tempYear.ToString() + "/" + tempMonth.ToString() + "/" + iDay.ToString();

                        if (DateTime.TryParse(rDate, out sDate) == true)
                        {
                            if (iX < 16)
                            {
                                tempDGV.Rows.Add();
                                c1 = 0;
                                c2 = 1;
                            }
                            else
                            {
                                c1 = 2;
                                c2 = 3;
                            }


                            tempDGV[c1, iX % 16].Value = rDate + "(" + ("日月火水木金土").Substring(int.Parse(sDate.DayOfWeek.ToString("d")), 1) + ")";
                            tempDGV[c2, iX % 16].Value = "";

                            sqlSTRING = "where 日付 = '" + rDate + "'";

                            dR = dCon.FillBy(sqlSTRING);

                            while (dR.Read())
                            {
                                tempDGV[c2, iX % 16].Value = dR["天候"].ToString();
                            }

                            dR.Close();
                        }
                        else
                        {
                            break;
                        }

                        iX++;
                    }

                    dCon.Close();

                    tempDGV.CurrentCell = null;
                }
                catch (Exception e)
                {
                    MessageBox.Show(e.Message, "エラー", MessageBoxButtons.OK);
                }
            }
Exemplo n.º 5
0
            public static void ShowData(DataGridView tempDGV, int temptYear, int temptMonth, int tempzYear, int tempzMonth, int tempofficeID)
            {
                string   sqlSTRING = "";
                DateTime sDate;

                const int GYOSU = 32;

                try
                {
                    Control.DataControl sdcon = new Control.DataControl();
                    OleDbConnection     cn    = new OleDbConnection();
                    cn = sdcon.GetConnection();

                    //データリーダーを取得する
                    OleDbDataReader dR;

                    sqlSTRING += "select 配布日,事業所ID,count(distinct 配布員ID) AS 配布員数,SUM(売上) AS 売上, ";
                    sqlSTRING += "SUM(原価) AS 原価, SUM(売上) - SUM(原価) AS 収支 ";
                    sqlSTRING += "from ";
                    sqlSTRING += "(SELECT TOP (100) PERCENT 配布指示.配布日, 配布指示.配布員ID,";
                    sqlSTRING += "事業所.ID AS 事業所ID,受注.単価,配布エリア.配布単価,";
                    sqlSTRING += "配布エリア.実配布枚数,配布エリア.予定枚数,";
                    sqlSTRING += "受注.単価 * 配布エリア.予定枚数 AS 売上,";
                    sqlSTRING += "配布エリア.配布単価 * 配布エリア.実配布枚数 AS 原価 ";
                    sqlSTRING += "from 配布指示 INNER JOIN 配布エリア ";
                    sqlSTRING += "ON 配布指示.ID = 配布エリア.配布指示ID INNER JOIN 受注 ";
                    sqlSTRING += "ON 配布エリア.受注ID = 受注.ID INNER JOIN 配布員 ";
                    sqlSTRING += "ON 配布指示.配布員ID = 配布員.ID LEFT OUTER JOIN 事業所 ";
                    sqlSTRING += "ON 配布員.事業所コード = 事業所.ID ";
                    sqlSTRING += "where ";
                    sqlSTRING += "(YEAR(配布指示.配布日) = ?) AND (MONTH(配布指示.配布日) = ?) AND ";
                    sqlSTRING += "(事業所.ID = ?) OR ";
                    sqlSTRING += "(YEAR(配布指示.配布日) = ?) AND (MONTH(配布指示.配布日) = ?) AND ";
                    sqlSTRING += "(事業所.ID = ?) ";
                    sqlSTRING += "order by 配布指示.配布日, 配布指示.配布員ID) AS sel_tbl ";
                    sqlSTRING += "group by 配布日, 事業所ID";

                    OleDbCommand SCom = new OleDbCommand();

                    SCom.CommandText = sqlSTRING;

                    SCom.Parameters.AddWithValue("@year1", temptYear);
                    SCom.Parameters.AddWithValue("@month1", temptMonth);
                    SCom.Parameters.AddWithValue("@officeID1", tempofficeID);

                    SCom.Parameters.AddWithValue("@year2", tempzYear);
                    SCom.Parameters.AddWithValue("@month2", tempzMonth);
                    SCom.Parameters.AddWithValue("@officeID2", tempofficeID);

                    SCom.Connection = cn;

                    dR = SCom.ExecuteReader();

                    //グリッドビューに表示する
                    int    iX       = 0;
                    double gzUri    = 0;
                    double gtUri    = 0;
                    double gzShushi = 0;
                    double gtShushi = 0;
                    double gzNin    = 0;
                    double gtNin    = 0;

                    //グリッド作成
                    tempDGV.RowCount = GYOSU;

                    //初期化(ゼロセット)
                    foreach (DataGridViewRow iRow in tempDGV.Rows)
                    {
                        foreach (DataGridViewColumn iColumn in tempDGV.Columns)
                        {
                            if (iColumn.Index == 1)
                            {
                                tempDGV[iColumn.Index, iRow.Index].Value = "";
                            }
                            else
                            {
                                tempDGV[iColumn.Index, iRow.Index].Value = (double)(0);
                            }
                        }
                    }

                    //日付をセット
                    for (int i = 0; i < GYOSU; i++)
                    {
                        int    rDay;
                        string rDate;

                        rDay = i + 1;

                        //対象日付
                        rDate = temptYear.ToString() + "/" + temptMonth.ToString() + "/" + rDay.ToString();

                        if (DateTime.TryParse(rDate, out sDate) == true)
                        {
                            //日付
                            tempDGV[0, i].Value = rDay.ToString("00");

                            //天候
                            OleDbDataReader dRt;
                            Control.天候      sTenkou = new Control.天候();
                            dRt = sTenkou.FillBy("where 日付 = '" + sDate.ToShortDateString() + "'");

                            while (dRt.Read())
                            {
                                tempDGV[1, i].Value = dRt["天候"].ToString() + "";
                            }

                            dRt.Close();
                            sTenkou.Close();
                        }
                    }

                    //データ表示
                    while (dR.Read())
                    {
                        iX = DateTime.Parse(dR["配布日"].ToString()).Day - 1;

                        tempDGV[0, iX].Value = DateTime.Parse(dR["配布日"].ToString()).Day; //日付

                        //前月or当月の判断
                        if (DateTime.Parse(dR["配布日"].ToString()).Month == temptMonth)                                           //当月
                        {
                            tempDGV[3, iX].Value  = double.Parse(dR["売上"].ToString(), System.Globalization.NumberStyles.Any);   //売上
                            tempDGV[7, iX].Value  = double.Parse(dR["収支"].ToString(), System.Globalization.NumberStyles.Any);   //収支
                            tempDGV[11, iX].Value = double.Parse(dR["配布員数"].ToString(), System.Globalization.NumberStyles.Any); //配布員数

                            //合計
                            gtUri    += double.Parse(dR["売上"].ToString(), System.Globalization.NumberStyles.Any);               //売上
                            gtShushi += double.Parse(dR["収支"].ToString(), System.Globalization.NumberStyles.Any);               //収支
                            gtNin    += double.Parse(dR["配布員数"].ToString(), System.Globalization.NumberStyles.Any);             //配布員数
                        }
                        else                                                                                                    //前月
                        {
                            tempDGV[2, iX].Value  = double.Parse(dR["売上"].ToString(), System.Globalization.NumberStyles.Any);   //売上
                            tempDGV[6, iX].Value  = double.Parse(dR["収支"].ToString(), System.Globalization.NumberStyles.Any);   //収支
                            tempDGV[10, iX].Value = double.Parse(dR["配布員数"].ToString(), System.Globalization.NumberStyles.Any); //収支

                            //合計
                            gzUri    += double.Parse(dR["売上"].ToString(), System.Globalization.NumberStyles.Any);   //売上
                            gzShushi += double.Parse(dR["収支"].ToString(), System.Globalization.NumberStyles.Any);   //収支
                            gzNin    += double.Parse(dR["配布員数"].ToString(), System.Globalization.NumberStyles.Any); //配布員数
                        }
                    }

                    //合計行
                    if (tempDGV.RowCount == 0)
                    {
                        MessageBox.Show("該当するデータがありませんでした", MESSAGE_CAPTION);
                    }
                    else
                    {
                        tempDGV[0, GYOSU - 1].Value  = "計";
                        tempDGV[2, GYOSU - 1].Value  = gzUri;
                        tempDGV[3, GYOSU - 1].Value  = gtUri;
                        tempDGV[6, GYOSU - 1].Value  = gzShushi;
                        tempDGV[7, GYOSU - 1].Value  = gtShushi;
                        tempDGV[10, GYOSU - 1].Value = gzNin;
                        tempDGV[11, GYOSU - 1].Value = gtNin;
                    }

                    //if (tempDGV.RowCount <= 25)
                    //{
                    //    tempDGV.Columns[2].Width = 318;
                    //}
                    //else
                    //{
                    //    tempDGV.Columns[2].Width = 301;
                    //}

                    dR.Close();
                    sdcon.Close();
                    cn.Close();

                    tempDGV.CurrentCell = null;
                }
                catch (Exception e)
                {
                    MessageBox.Show(e.Message, "エラー", MessageBoxButtons.OK);
                }
            }