示例#1
0
        // 班級升級
        private void UpgradeDGClassItem(UpgradeType ut)
        {
            // 對所選擇的 Row 判斷
            foreach (DataGridViewRow dgv in dgClassUpgrade.SelectedRows)
            {
                int defGrYear, upgradeGrYear, defClassYear;

                string ClassName = "", newClassName = "", ClassNamingRule = "";
                ClassName       = dgv.Cells[2].Value.ToString();
                ClassNamingRule = "" + dgv.Cells[6].Value;

                if (ut == UpgradeType.升級)
                {
                    bool checkNew = true;

                    if (dgv.Cells[5].Value != null)
                    {
                        if (dgv.Cells[5].Value.ToString() == "升級")
                        {
                            dgv.Cells[3].Value = "";
                            dgv.Cells[4].Value = "";
                            dgv.Cells[5].Value = "";
                            foreach (DataGridViewCell dd in dgv.Cells)
                            {
                                dd.Style.BackColor = Color.White;
                            }
                            checkNew = false;
                        }
                    }

                    if (checkNew == true)
                    {
                        int.TryParse(dgv.Cells[1].Value.ToString(), out defGrYear);
                        string strUpgradeGrYear;
                        upgradeGrYear      = defGrYear + 1;
                        dgv.Cells[3].Value = strUpgradeGrYear = upgradeGrYear.ToString();

                        // 檢查是否有命名規則
                        bool checkClassNamingRule = UpgradeClassDAL.ValidateNamingRule(ClassNamingRule);

                        if (checkClassNamingRule == true)
                        {
                            // 使用預設命名規則
                            newClassName       = UpgradeClassDAL.ParseClassName(ClassNamingRule, upgradeGrYear);
                            dgv.Cells[4].Value = newClassName;
                        }
                        else
                        {
                            // 沒有命名規則
                            newClassName = ClassName;
                            if (upgradeGrYear > 10)
                            {
                                newClassName = strUpgradeGrYear + ClassName.Substring(2, (ClassName.Length - 2));
                            }
                            else
                            {
                                newClassName = strUpgradeGrYear + ClassName.Substring(1, (ClassName.Length - 1));
                            }

                            dgv.Cells[4].Value = newClassName;
                        }
                        dgv.Cells[5].Value = "升級";
                        foreach (DataGridViewCell dd in dgv.Cells)
                        {
                            dd.Style.BackColor = Color.Yellow;
                        }
                    }
                }

                if (ut == UpgradeType.畢業)
                {
                    bool checkNew = true;

                    if (dgv.Cells[5].Value != null)
                    {
                        if (dgv.Cells[5].Value.ToString() == "畢業")
                        {
                            dgv.Cells[3].Value = "";
                            dgv.Cells[4].Value = "";
                            dgv.Cells[5].Value = "";
                            foreach (DataGridViewCell dd in dgv.Cells)
                            {
                                dd.Style.BackColor = Color.White;
                            }
                            checkNew = false;
                        }
                    }

                    if (checkNew == true)
                    {
                        dgv.Cells[3].Value = "";
                        dgv.Cells[4].Value = txtSchoolYear.Text + ClassName;
                        dgv.Cells[5].Value = "畢業";
                        foreach (DataGridViewCell dd in dgv.Cells)
                        {
                            dd.Style.BackColor = Color.LightCyan;
                        }
                    }
                }

                if (ut == UpgradeType.恢復)
                {
                    dgv.Cells[3].Value = "";
                    dgv.Cells[4].Value = "";
                    dgv.Cells[5].Value = "";
                    foreach (DataGridViewCell dd in dgv.Cells)
                    {
                        dd.Style.BackColor = Color.White;
                    }
                }
            }
        }