Example #1
0
        private void btnEdit_Click(object sender, EventArgs e)
        {
            if (lvData.SelectedItems.Count == 1)
            {
                // 傳入資料
                Forms.StudABCard_YearlyForm_03 form = new Forms.StudABCard_YearlyForm_03(_YearlyDataDict, lvData.SelectedItems[0].Text);

                if (_QuestionDataDict.ContainsKey("特殊專長"))
                {
                    form.SetFlp01Items((from data in _QuestionDataDict["特殊專長"].itemList select data.Key).ToList());
                }

                if (_QuestionDataDict.ContainsKey("休閒興趣"))
                {
                    form.SetFlp02Items((from data in _QuestionDataDict["休閒興趣"].itemList select data.Key).ToList());
                }

                if (form.ShowDialog() == DialogResult.OK)
                {
                    List <UDTYearlyDataDef> insertData = new List <UDTYearlyDataDef>();
                    List <UDTYearlyDataDef> updateData = new List <UDTYearlyDataDef>();

                    foreach (UDTYearlyDataDef data in form.GetData().Values)
                    {
                        if (string.IsNullOrEmpty(data.UID))
                        {
                            insertData.Add(data);
                        }
                        else
                        {
                            updateData.Add(data);
                        }
                    }

                    if (insertData.Count > 0)
                    {
                        UDTTransfer.ABUDTYearlyDataInsert(insertData);
                    }

                    if (updateData.Count > 0)
                    {
                        UDTTransfer.ABUDTYearlyDataUpdate(updateData);
                    }

                    _BGRun();
                }
            }
        }
        protected override void OnSaveButtonClick(EventArgs e)
        {
            dgData.EndEdit();
            SetData();
            if (_insertDataList.Count > 0)
            {
                UDTTransfer.ABUDTYearlyDataInsert(_insertDataList);
            }

            if (_updateDataList.Count > 0)
            {
                UDTTransfer.ABUDTYearlyDataUpdate(_updateDataList);
            }

            this.CancelButtonVisible = this.SaveButtonVisible = false;
            _BGRun();
        }
        /// <summary>
        /// 儲存其它資料
        /// </summary>
        private void SaveYearlyData()
        {
            List <UDTYearlyDataDef> insertDataList = new List <UDTYearlyDataDef>();
            List <UDTYearlyDataDef> updateDataList = new List <UDTYearlyDataDef>();

            foreach (DataGridViewColumn drc in dgYearly.Columns)
            {
                string name = drc.HeaderText.Replace("(元)", "");
                string key  = GroupName + "_" + name;
                if (_ColumIndexDict.ContainsKey(key))
                {
                    UDTYearlyDataDef data = drc.Tag as UDTYearlyDataDef;
                    if (data == null)
                    {
                        data           = new UDTYearlyDataDef();
                        data.StudentID = _intStudentID;
                    }
                    data.Key = key;

                    foreach (KeyValuePair <string, int> rowDa in _RowIndexDict)
                    {
                        if (rowDa.Key == "一年級")
                        {
                            if (dgYearly.Rows[rowDa.Value].Cells[drc.Index].Value != null)
                            {
                                data.G1 = dgYearly.Rows[rowDa.Value].Cells[drc.Index].Value.ToString();
                            }
                            else
                            {
                                data.G1 = "";
                            }
                        }

                        if (rowDa.Key == "二年級")
                        {
                            if (dgYearly.Rows[rowDa.Value].Cells[drc.Index].Value != null)
                            {
                                data.G2 = dgYearly.Rows[rowDa.Value].Cells[drc.Index].Value.ToString();
                            }
                            else
                            {
                                data.G2 = "";
                            }
                        }

                        if (rowDa.Key == "三年級")
                        {
                            if (dgYearly.Rows[rowDa.Value].Cells[drc.Index].Value != null)
                            {
                                data.G3 = dgYearly.Rows[rowDa.Value].Cells[drc.Index].Value.ToString();
                            }
                            else
                            {
                                data.G3 = "";
                            }
                        }

                        if (rowDa.Key == "四年級")
                        {
                            if (dgYearly.Rows[rowDa.Value].Cells[drc.Index].Value != null)
                            {
                                data.G4 = dgYearly.Rows[rowDa.Value].Cells[drc.Index].Value.ToString();
                            }
                            else
                            {
                                data.G4 = "";
                            }
                        }

                        if (rowDa.Key == "五年級")
                        {
                            if (dgYearly.Rows[rowDa.Value].Cells[drc.Index].Value != null)
                            {
                                data.G5 = dgYearly.Rows[rowDa.Value].Cells[drc.Index].Value.ToString();
                            }
                            else
                            {
                                data.G5 = "";
                            }
                        }

                        if (rowDa.Key == "六年級")
                        {
                            if (dgYearly.Rows[rowDa.Value].Cells[drc.Index].Value != null)
                            {
                                data.G6 = dgYearly.Rows[rowDa.Value].Cells[drc.Index].Value.ToString();
                            }
                            else
                            {
                                data.G6 = "";
                            }
                        }
                    }
                    if (string.IsNullOrEmpty(data.UID))
                    {
                        insertDataList.Add(data);
                    }
                    else
                    {
                        updateDataList.Add(data);
                    }
                }
            }

            if (insertDataList.Count > 0)
            {
                UDTTransfer.ABUDTYearlyDataInsert(insertDataList);
            }

            if (updateDataList.Count > 0)
            {
                UDTTransfer.ABUDTYearlyDataUpdate(updateDataList);
            }
        }