Example #1
0
 private void Sheet_CellKeyUp(object sender, unvell.ReoGrid.Events.CellKeyDownEventArgs e)
 {
     if (e.KeyCode == unvell.ReoGrid.Interaction.KeyCode.Delete)
     {
         // DeleteキーでCellDataChangedが発生しないので
         unvell.ReoGrid.Events.CellEventArgs eventArgs = new unvell.ReoGrid.Events.CellEventArgs(worksheet.GetCell(worksheet.FocusPos));
         Sheet_CellDataChanged(sender, eventArgs);
     }
 }
Example #2
0
        private void Sheet_CellDataChanged(object sender, unvell.ReoGrid.Events.CellEventArgs e)
        {
            // ===================================================================
            // 入力可能なセルか判断する
            // ===================================================================

            if (!CanCellInput(e.Cell))
            {
                return;
            }

            // ===================================================================
            // セル名を取得する
            // ===================================================================

            string[] splitedNames = worksheet.GetNameByRange(e.Cell.Address).Split('_');

            Dictionary <CellNameParts, string> names = new Dictionary <CellNameParts, string>();

            names.Add(CellNameParts.AccountTitle, splitedNames[0]);
            names.Add(CellNameParts.PlanResult, splitedNames[1]);
            names.Add(CellNameParts.BusinessYearColumn, splitedNames[2]);

            // ===================================================================
            // セルの入力値によって入力されたセルの色を変える
            // ===================================================================

            switch (names[CellNameParts.AccountTitle])
            {
            case "売上総利益":
            case "営業利益":
            case "経常利益":

                Decimal calValue = 0;
                Decimal newValue = ConvertCell(e.Cell.Data);

                switch (names[CellNameParts.AccountTitle])
                {
                case "売上総利益":

                    calValue = Calculate売上総利益(names[CellNameParts.PlanResult], names[CellNameParts.BusinessYearColumn]);
                    break;

                case "営業利益":

                    calValue = Calculate営業利益(names[CellNameParts.PlanResult], names[CellNameParts.BusinessYearColumn]);
                    break;

                case "経常利益":

                    calValue = Calculate経常利益(names[CellNameParts.PlanResult], names[CellNameParts.BusinessYearColumn]);
                    break;
                }

                e.Cell.Style.BackColor = (calValue == newValue) ? CELL_BACK_COLOR_EDIT_ABLE : CELL_BACK_COLOR_EDIT_ONLY;

                break;
            }

            // ===================================================================
            // 他のセルの値を再計算する
            // ===================================================================

            switch (names[CellNameParts.AccountTitle])
            {
            case "売上":
            case "売上原価":
            case "売上総利益":
            case "販管費":
            case "営業利益":
            case "営業外収益":
            case "営業外費用":
            case "経常利益":
            case "特別利益":
            case "特別損失":
            case "税引前当期純利益":
            case "法人税等":
            case "当期純利益":

                // セルに値を設定する間、本イベントを発生しないようにする(セルに値を設定するたびに本イベントが発生する)
                worksheet.CellDataChanged -= Sheet_CellDataChanged;

                string tail = "_" + names[CellNameParts.PlanResult] + "_" + names[CellNameParts.BusinessYearColumn];

                if (worksheet.GetCell("売上総利益" + tail).Style.BackColor != CELL_BACK_COLOR_EDIT_ONLY)
                {
                    worksheet["売上総利益" + tail] = Calculate売上総利益(names[CellNameParts.PlanResult], names[CellNameParts.BusinessYearColumn]);
                }
                if (worksheet.GetCell("営業利益" + tail).Style.BackColor != CELL_BACK_COLOR_EDIT_ONLY)
                {
                    worksheet["営業利益" + tail] = Calculate営業利益(names[CellNameParts.PlanResult], names[CellNameParts.BusinessYearColumn]);
                }
                if (worksheet.GetCell("経常利益" + tail).Style.BackColor != CELL_BACK_COLOR_EDIT_ONLY)
                {
                    worksheet["経常利益" + tail] = Calculate経常利益(names[CellNameParts.PlanResult], names[CellNameParts.BusinessYearColumn]);
                }
                if (worksheet.GetCell("税引前当期純利益" + tail).Style.BackColor != CELL_BACK_COLOR_EDIT_ONLY)
                {
                    worksheet["税引前当期純利益" + tail] = Calculate税引前当期純利益(names[CellNameParts.PlanResult], names[CellNameParts.BusinessYearColumn]);
                }
                if (worksheet.GetCell("当期純利益" + tail).Style.BackColor != CELL_BACK_COLOR_EDIT_ONLY)
                {
                    worksheet["当期純利益" + tail] = Calculate当期純利益(names[CellNameParts.PlanResult], names[CellNameParts.BusinessYearColumn]);
                }

                // セルに値を設定し終わったので、本イベントを発生するようにする
                worksheet.CellDataChanged += Sheet_CellDataChanged;

                break;

            default:
                break;
            }
        }
Example #3
0
 private void Worksheet_CellDataChanged(object sender, unvell.ReoGrid.Events.CellEventArgs e)
 {
 }