private void item_click(object sender, EventArgs e)
        {
            if (_RunningItem == null)
            {
                _RunningItem = new ButtonItem();
            }

            ButtonItem item = sender as ButtonItem;

            //判斷切換的item是否相同
            if (!_RunningItem.Equals(item))
            {
                //切換前將dgv.rows存到tag中
                _RunningItem.Tag = new ButtonTag(dgv);
                //切換
                _RunningItem = item;
                string subject = item.Text;

                dgv.Rows.Clear();

                //item.Tag == ""代表此item未被編輯過,做初始設定
                if (item.Tag + "" == "")
                {
                    foreach (XmlElement conduct in _doc.SelectNodes("//Conduct[@Subject=" + Tool.XPathLiteral(subject) + "]"))
                    {
                        string group = conduct.GetAttribute("Group");

                        foreach (XmlElement itemx in conduct.SelectNodes("Item"))
                        {
                            string          title = itemx.GetAttribute("Title");
                            DataGridViewRow row   = new DataGridViewRow();
                            row.CreateCells(dgv, group, title);
                            dgv.Rows.Add(row);
                        }
                    }
                }
                else
                {
                    //tag!=""就讀取tag
                    ButtonTag tag = item.Tag as ButtonTag;
                    foreach (DataGridViewRow row in tag.Rows)
                    {
                        dgv.Rows.Add(row);
                    }
                }
            }
        }
Esempio n. 2
0
        /*
         * Slightly customized version of childButtonItem_Click from PrometheusGUI.cs;
         * check there for more information about this function - mainly it helps swap
         * button info around.
         */
        private void childButtonXItem_Click(object sender, System.EventArgs e)
        {
            ButtonItem child = (sender as ButtonItem);

            if (child == null)
            {
                return;
            }

            ButtonItem parent = (child.Parent as ButtonItem);

            if (parent == null)
            {
                return;
            }

            /* Update the Text property on the parent button to reflect selected button.
             *
             * If the child's Tag object is null or the parent's Text property is an empty string, do nothing.
             */
            if (!child.Tag.Equals(null) && !parent.Text.Equals(string.Empty))
            {
                parent.Text = child.Tag.ToString();
            }

            // Mirror Tag property from child to parent.
            parent.Tag = child.Tag;

            // Update the image on the parent button.
            if (child.Image != null)
            {
                if (parent.Image != null)
                {
                    parent.Image = child.Image;
                }
            }

            // Custom PerformLayout() calls needed
            if (parent.Equals(btnxReferenceAction))
            {
                btnxReferenceAction.PerformLayout();
            }
        }
        private void Item_click(object sender, EventArgs e)
        {
            bool       alarm = false;
            ButtonItem item  = sender as ButtonItem;

            //切換不同item
            if (!_RunningItem.Equals(item))
            {
                if (lblSave.Visible)
                {
                    if (MessageBox.Show("資料未儲存,確定切換?", "ischool", MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.No)
                    {
                        _RunningItem.RaiseClick();
                        return;
                    }
                }

                _dirtyCellList.Clear();
                lblSave.Visible  = false;
                _RunningItem     = item;
                groupPanel1.Text = item.Text;

                ConductRecord record = item.Tag as ConductRecord;

                txtComment.Text = record.Comment;

                dgv.Rows.Clear();

                XmlDocument doc = new XmlDocument();
                if (!string.IsNullOrWhiteSpace(record.Conduct))
                {
                    doc.LoadXml(record.Conduct);
                }

                //Console.Write(doc.OuterXml);

                //讀取缺席天數
                //intInput.Value = 0;
                //if (intInput.Enabled)
                //{
                //    XmlElement absence = doc.SelectSingleNode("//Conducts/Absence") as XmlElement;
                //    if(absence != null)
                //    {
                //        int i = 0;
                //        int.TryParse(absence.InnerText, out i);
                //        intInput.Value = i;
                //    }
                //}
                //intInput.Tag = intInput.Value;

                //Check alarm
                foreach (XmlElement first in doc.SelectNodes("//Conduct[@Group]"))
                {
                    string group = first.GetAttribute("Group");
                    foreach (XmlElement second in first.SelectNodes("Item"))
                    {
                        string title = second.GetAttribute("Title");
                        string key   = group + "_" + title;

                        if (!_conductTemplate.Contains(key))
                        {
                            alarm = true;
                        }
                    }
                }

                //巡迴所有需要呈現的conductItem
                foreach (string str in _conductTemplate)
                {
                    string group = str.Split('_')[0];
                    string title = str.Split('_')[1];
                    string grade = "";

                    XmlElement elem = doc.SelectSingleNode("//Conduct[@Group=" + Tool.XPathLiteral(group) + "]/Item[@Title=" + Tool.XPathLiteral(title) + "]") as XmlElement;

                    if (elem != null)
                    {
                        grade = elem.GetAttribute("Grade");
                    }

                    DataGridViewRow row = new DataGridViewRow();
                    row.CreateCells(dgv, group, title, grade);
                    dgv.Rows.Add(row);
                }

                //備份編輯前資料
                foreach (DataGridViewRow row in dgv.Rows)
                {
                    foreach (DataGridViewCell cell in row.Cells)
                    {
                        cell.Tag = cell.Value;
                    }
                }

                txtComment.Tag = txtComment.Text;

                if (alarm)
                {
                    MessageBox.Show("此學生資料有其他的Conduct紀錄,儲存後可能會造成資料遺失");
                }
            }
        }