コード例 #1
0
        /// <summary>
        /// 設定儲存資料
        /// </summary>
        private void SetData()
        {
            // 刪除舊資料
            _deleteMultipleRecordList = _dataMDict.Values.ToList();
            UDTTransfer.ABUDTMultipleRecordDelete(_deleteMultipleRecordList);
            _InsertMultipleRecordDict.Clear();

            // 儲存資料
            for (int idx = 0; idx < 4; idx++)
            {
                FlowLayoutPanel flp     = _flpList[idx];
                string          KeyName = _KeyNameList[idx];

                foreach (Control cr in flp.Controls)
                {
                    if (cr is CheckBox)
                    {
                        CheckBox cb = cr as CheckBox;
                        if (cb.Checked)
                        {
                            UDTMultipleRecordDef data1 = new UDTMultipleRecordDef();
                            data1.StudentID = _intStudentID;
                            data1.Key       = GroupName + "_" + KeyName;
                            data1.Data      = cb.Name;
                            data1.Remark    = "";

                            // 處理備註資料
                            foreach (Control t in flp.Controls)
                            {
                                if (t is TextBox)
                                {
                                    if (t.Name == cb.Name)
                                    {
                                        data1.Remark = t.Text;
                                    }
                                }
                            }

                            string insertKey = data1.Key + "_" + cb.Name;
                            if (!_InsertMultipleRecordDict.ContainsKey(insertKey))
                            {
                                _InsertMultipleRecordDict.Add(insertKey, data1);
                            }
                        }
                    }
                }
            }

            // 新增至 UDT
            if (_InsertMultipleRecordDict.Count > 0)
            {
                UDTTransfer.ABUDTMultipleRecordInsert(_InsertMultipleRecordDict.Values.ToList());
            }

            // 讀存資料
            List <UDTPriorityDataDef> insertData = new List <UDTPriorityDataDef>();
            List <UDTPriorityDataDef> updateData = new List <UDTPriorityDataDef>();

            // 將來就業
            UDTPriorityDataDef p1 = dgPriority.Columns[1].Tag as UDTPriorityDataDef;

            if (p1 == null)
            {
                p1           = new UDTPriorityDataDef();
                p1.Key       = GroupName + "_" + _keyName5;
                p1.StudentID = _intStudentID;
            }
            if (dgPriority.Rows[0].Cells[1].Value != null)
            {
                p1.P1 = dgPriority.Rows[0].Cells[1].Value.ToString();
            }
            else
            {
                p1.P1 = "";
            }
            if (dgPriority.Rows[1].Cells[1].Value != null)
            {
                p1.P2 = dgPriority.Rows[1].Cells[1].Value.ToString();
            }
            else
            {
                p1.P2 = "";
            }
            if (dgPriority.Rows[2].Cells[1].Value != null)
            {
                p1.P3 = dgPriority.Rows[2].Cells[1].Value.ToString();
            }
            else
            {
                p1.P3 = "";
            }

            if (string.IsNullOrEmpty(p1.UID))
            {
                insertData.Add(p1);
            }
            else
            {
                updateData.Add(p1);
            }

            // 就業地區
            UDTPriorityDataDef p2 = dgPriority.Columns[2].Tag as UDTPriorityDataDef;

            if (p2 == null)
            {
                p2           = new UDTPriorityDataDef();
                p2.Key       = GroupName + "_" + _keyName6;
                p2.StudentID = _intStudentID;
            }
            if (dgPriority.Rows[0].Cells[2].Value != null)
            {
                p2.P1 = dgPriority.Rows[0].Cells[2].Value.ToString();
            }
            else
            {
                p2.P1 = "";
            }
            if (dgPriority.Rows[1].Cells[2].Value != null)
            {
                p2.P2 = dgPriority.Rows[1].Cells[2].Value.ToString();
            }
            else
            {
                p2.P2 = "";
            }
            if (dgPriority.Rows[2].Cells[2].Value != null)
            {
                p2.P3 = dgPriority.Rows[2].Cells[2].Value.ToString();
            }
            else
            {
                p2.P3 = "";
            }

            if (string.IsNullOrEmpty(p2.UID))
            {
                insertData.Add(p2);
            }
            else
            {
                updateData.Add(p2);
            }

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

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