コード例 #1
0
        public void UpdateAliasMaping()
        {
            TblAliasMapping pitems;

            string localali = "", TestId = "";
            int    id_xn     = 0;
            var    dataTable = GrdAliasPara.DataSource as DataTable;

            for (int i = 0; i < dataTable.Rows.Count; i++)
            {
                DataRow dr = dataTable.Rows[i];
                object  c  = dr[TblAliasMapping.Columns.Id];
                //Kiểm tra trạng thái của dòng:
                if ((dr.RowState == DataRowState.Modified) || (dr.RowState == DataRowState.Added))
                {
                    localali = dr[TblAliasMapping.Columns.LocalAlias].ToString();
                    TestId   = dr[TblAliasMapping.Columns.TestTypeId].ToString();
                    id_xn    = Convert.ToInt32(dr[TblAliasMapping.Columns.IdHisXn].ToString());

                    if ((localali == ""))
                    {
                        SetTextForWarning(MsgEror);
                        continue;
                    }
                }
                if (dr.RowState == DataRowState.Modified)
                {
                    pitems            = new TblAliasMapping(dr[TblAliasMapping.Columns.Id]);
                    pitems.LocalAlias = localali;
                    pitems.TestTypeId = Convert.ToInt32(TestId);
                    pitems.IdHisXn    = Convert.ToInt32(id_xn);
                    AliasMappingBusiness.UpdateAliasMapping(pitems);
                    SetTextForWarning(MsgUpdate);
                }
                else if (dr.RowState == DataRowState.Added)
                {
                    pitems            = new TblAliasMapping();
                    pitems.LocalAlias = localali;
                    pitems.TestTypeId = Convert.ToInt32(TestId);
                    pitems.IdHisXn    = Convert.ToInt32(id_xn);
                    string id = AliasMappingBusiness.InsertAliasMapping(pitems);
                    if (id == "-1")
                    {
                        //MessageBox.Show("Tên thông số  " + pitems.LocalAlias + "  đã tồn tại", "Thông báo:",
                        //                MessageBoxButtons.OK,
                        //                MessageBoxIcon.Error);
                        SetTextForWarning(MsgExits);
                        dr.Delete();
                    }
                    else
                    {
                        dr[TblAliasMapping.Columns.Id] = AliasMappingBusiness.InsertAliasMapping(pitems);
                        SetTextForWarning(MsgNew);
                    }
                }
            }
            dataTable.AcceptChanges();
        }
コード例 #2
0
        private void DeleteAliasMapping()
        {
            try
            {
                DataGridViewRow currentRow = GrdAliasPara.CurrentRow;

                if (currentRow != null)
                {
                    string pid = UI.GetCellValue(currentRow.Cells[TblAliasMapping.Columns.Id]);
                    if (pid != "")
                    {
                        // int pid = Convert.ToInt32(.Value);
                        if (
                            MessageBox.Show(@"Bạn có muốn xóa ?", "Thông báo", MessageBoxButtons.YesNo,
                                            MessageBoxIcon.Question) ==
                            DialogResult.Yes)
                        {
                            AliasMappingBusiness.DeleteAliasMapping(Convert.ToInt32(pid));
                            GrdAliasPara.Rows.Remove(currentRow);
                            SetTextForWarning(MsgDelete);
                        }
                    }
                    else
                    {
                        SetTextForWarning(MsgEror);
                    }
                }
            }
            catch (Exception ex)
            {
                SetTextForWarning(MsgEror);
            }
            finally
            {
                (GrdAliasPara.DataSource as DataTable).AcceptChanges();
            }
        }
コード例 #3
0
 public void LoadAlias()
 {
     dtAlias = AliasMappingBusiness.GetAllAlias();
     GrdAliasPara.DataSource = dtAlias;
 }