Ejemplo n.º 1
0
        private void rightBtnDelete_Click(object sender, EventArgs e)
        {
            DialogResult result = MsgBox.Show("確定刪除選取資料行?", "提醒", MessageBoxButtons.YesNo);

            if (result == DialogResult.Yes)
            {
                List <UDT.Place> listDeleteData = new List <UDT.Place>();

                foreach (DataGridViewRow dgvrow in dataGridViewX1.SelectedRows)
                {
                    if (dgvrow.Tag == null)
                    {
                        dataGridViewX1.Rows.Remove(dgvrow);
                    }
                    else
                    {
                        UDT.Place data = (UDT.Place)dgvrow.Tag;
                        listDeleteData.Add(data);
                        dataGridViewX1.Rows.Remove(dgvrow);
                    }
                }

                try
                {
                    this._access.DeletedValues(listDeleteData);
                    MsgBox.Show("資料刪除成功!");
                }
                catch (Exception ex)
                {
                    MsgBox.Show(ex.Message);
                }
            }
        }
Ejemplo n.º 2
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (dgvDisplayOrder_Validate() && dgvName_Validate() && dgvZone_Validate()) // 資料驗證.
            {
                // 資料整理
                List <UDT.Place> listInsertData = new List <UDT.Place>();
                List <UDT.Place> listUpdateData = new List <UDT.Place>();

                int row = 0;
                foreach (DataGridViewRow dgvrow in dataGridViewX1.Rows)
                {
                    if (row == dataGridViewX1.Rows.Count - 1)
                    {
                        break;
                    }
                    row++;
                    if (dgvrow.Tag == null)
                    {
                        UDT.Place data = new UDT.Place();
                        fillData(data, dgvrow);

                        listInsertData.Add(data);
                    }
                    else
                    {
                        UDT.Place data = (UDT.Place)dgvrow.Tag;
                        fillData(data, dgvrow);

                        listUpdateData.Add(data);
                    }
                }

                // 資料儲存
                try
                {
                    if (listInsertData.Count > 0)
                    {
                        this._access.InsertValues(listInsertData);
                    }
                    if (listUpdateData.Count > 0)
                    {
                        this._access.UpdateValues(listUpdateData);
                    }
                    MsgBox.Show("資料儲存成功!");

                    ReloadDataGridView();
                }
                catch (Exception ex)
                {
                    MsgBox.Show(ex.Message);
                }
            }
        }
Ejemplo n.º 3
0
 private void fillData(UDT.Place data, DataGridViewRow dgvrow)
 {
     data.Enabled = bool.Parse(("" + dgvrow.Cells[0].Value) == "" ? "false" : "" + dgvrow.Cells[0].Value);
     data.Name    = "" + dgvrow.Cells[1].Value;
     if (!string.IsNullOrEmpty("" + dgvrow.Cells[2].Value))
     {
         data.DisplayOrder = int.Parse("" + dgvrow.Cells[2].Value);
     }
     data.RefAreaID = int.Parse(this._dicAreaByName[cbxArea.SelectedItem.ToString()].UID);
     if (!string.IsNullOrEmpty("" + dgvrow.Cells[3].Value))
     {
         data.Zone = int.Parse("" + dgvrow.Cells[3].Value);
     }
     data.CreatedBy  = "" + dgvrow.Cells[4].Value;
     data.CreateTime = DateTime.Parse(DateTime.Now.ToString("yyyy/MM/dd"));
 }