private async void LoadTeleports() { List <COptionalTeleport> tpList = await COptionalTeleport.GetCOptionalTeleports(); tpList.ForEach(tp => { if (cTpGrid.InvokeRequired) { cTpGrid.BeginInvoke((Action)(() => AddRowToGrid(tp))); } else { AddRowToGrid(tp); } }); }
private void cSaveButton_Click(object sender, EventArgs e) { if (MessageBox.Show("Are you sure that you want to save changes to database?", "WARNING!", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { List <DataGridViewRow> rows = cTpGrid.Rows.Cast <DataGridViewRow>().ToList(); _ = rows.Concat(RemovedRows).ToList(); rows.ForEach(row => { COptionalTeleport tp = new COptionalTeleport(); tp.m_Service = bool.Parse(row.Cells[0].Value.ToString()) ? (byte)1 : (byte)0; tp.m_ID = Convert.ToInt32(row.Cells[1].Value); tp.m_ObjName128 = row.Cells[2].Value.ToString(); tp.m_ZoneName128 = row.Cells[3].Value.ToString(); tp.m_GenRegionID = Convert.ToInt16(row.Cells[4].Value); tp.m_GenPos_X = Convert.ToInt16(row.Cells[5].Value); tp.m_GenPos_Y = Convert.ToInt16(row.Cells[6].Value); tp.m_GenPos_Z = Convert.ToInt16(row.Cells[7].Value); tp.m_GenWorldID = (short)Globals.GameWorldIDList[row.Cells[8].Value.ToString()]; tp.m_RegionIDGroup = Convert.ToInt32(row.Cells[9].Value); tp.m_MapPoint = bool.Parse(row.Cells[10].Value.ToString()) ? (byte)1 : (byte)0; tp.m_LevelMin = Convert.ToInt16(row.Cells[11].Value); tp.m_LevelMax = Convert.ToInt16(row.Cells[12].Value); tp.m_Status = (EditStatus)row.Tag; if (tp.m_Status == EditStatus.New) { tp.m_ID = row.Index; } tp.SaveToDatabase(); if ((EditStatus)row.Tag != EditStatus.Removed) { row.Tag = EditStatus.Notr; row.Cells[1].Value = tp.m_ID; } }); RemovedRows.Clear(); CTeleportBase.SaveToClient("refoptionalteleport.txt"); MessageBox.Show("Your changes is successfully saved!", "NOTICE", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
private void AddRowToGrid(COptionalTeleport tp) { int idx = cTpGrid.Rows.Add(); DataGridViewRow row = cTpGrid.Rows[idx]; row.Cells[0].Value = tp.m_Service == 1; row.Cells[1].Value = tp.m_ID; row.Cells[2].Value = tp.m_ObjName128; row.Cells[3].Value = tp.m_ZoneName128; row.Cells[4].Value = tp.m_GenRegionID; row.Cells[5].Value = tp.m_GenPos_X; row.Cells[6].Value = tp.m_GenPos_Y; row.Cells[7].Value = tp.m_GenPos_Z; row.Cells[8].Value = Globals.GameWorldList[tp.m_GenWorldID]; row.Cells[9].Value = tp.m_RegionIDGroup; row.Cells[10].Value = tp.m_MapPoint == 1; row.Cells[11].Value = tp.m_LevelMin; row.Cells[12].Value = tp.m_LevelMax; row.Tag = tp.m_Status; }
internal static async Task <List <COptionalTeleport> > GetCOptionalTeleports() { List <COptionalTeleport> list = new List <COptionalTeleport>(); using (SqlConnection conn = new SqlConnection(Globals.s_SqlConnectionString)) { conn.Open(); using (SqlCommand comm = new SqlCommand("select [Service],ID,ObjName128,ZoneName128,RegionID,Pos_X,Pos_Y,Pos_Z,WorldID,RegionIDGroup,MapPoint,LevelMin,LevelMax from _RefOptionalTeleport", conn)) { using (SqlDataReader reader = await comm.ExecuteReaderAsync()) { if (reader.HasRows) { while (reader.Read()) { COptionalTeleport tp = new COptionalTeleport(); tp.m_Service = reader.GetInt32(0); tp.m_ID = reader.GetInt32(1); tp.m_ObjName128 = reader.GetString(2); tp.m_ZoneName128 = reader.GetString(3); tp.m_GenRegionID = reader.GetInt16(4); tp.m_GenPos_X = reader.GetInt16(5); tp.m_GenPos_Y = reader.GetInt16(6); tp.m_GenPos_Z = reader.GetInt16(7); tp.m_GenWorldID = reader.GetInt16(8); tp.m_RegionIDGroup = reader.GetInt32(9); tp.m_MapPoint = reader.GetByte(10); tp.m_LevelMin = reader.GetInt16(11); tp.m_LevelMax = reader.GetInt16(12); list.Add(tp); } } } } } return(list); }