Example #1
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            this.DialogResult = System.Windows.Forms.DialogResult.OK;

            SetData();

            List <UDTSiblingDef> dataList = new List <UDTSiblingDef>();

            dataList.Add(_data);
            if (string.IsNullOrEmpty(_data.UID))
            {
                UDTTransfer.ABUDTSiblingInsert(dataList);
            }
            else
            {
                UDTTransfer.ABUDTSiblingUpdate(dataList);
            }

            this.Close();
        }
        /// <summary>
        /// 儲存兄弟姊妹
        /// </summary>
        private void SaveSiblingData()
        {
            List <UDTSiblingDef> insertData = new List <UDTSiblingDef>();
            List <UDTSiblingDef> updateData = new List <UDTSiblingDef>();

            foreach (DataGridViewRow dr in dgSibling.Rows)
            {
                if (dr.IsNewRow)
                {
                    continue;
                }
                UDTSiblingDef data = dr.Tag as UDTSiblingDef;
                if (data == null)
                {
                    data           = new UDTSiblingDef();
                    data.StudentID = _intStudentID;
                }

                // 稱謂
                if (dr.Cells[0].Value == null)
                {
                    data.Title = "";
                }
                else
                {
                    data.Title = dr.Cells[0].Value.ToString();
                }

                // 姓名
                if (dr.Cells[1].Value == null)
                {
                    data.Name = "";
                }
                else
                {
                    data.Name = dr.Cells[1].Value.ToString();
                }


                // 畢業學校
                if (dr.Cells[2].Value == null)
                {
                    data.SchoolName = "";
                }
                else
                {
                    data.SchoolName = dr.Cells[2].Value.ToString();
                }

                // 出生年
                if (dr.Cells[3].Value == null)
                {
                    data.BirthYear = null;
                }
                else
                {
                    int sy;
                    if (int.TryParse(dr.Cells[3].Value.ToString(), out sy))
                    {
                        data.BirthYear = sy;
                    }
                    else
                    {
                        data.BirthYear = null;
                    }
                }

                // 備註
                if (dr.Cells[4].Value == null)
                {
                    data.Remark = "";
                }
                else
                {
                    data.Remark = dr.Cells[4].Value.ToString();
                }

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

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

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