private async void LoadLinks() { List <CTeleportLink> linkList = await CTeleportLink.GetTeleportLinks(); HashSet <string> tpCodeNames = await CTeleport.GetTeleportCodeNames(); List <string> restrictList = new List <string>() { "None", "Level Limit", "Block Enter With Job Pet", "Need Item to Enter", "Delete Item After Enter", "Block Enter With Job Suit", "Block Enter to Thief Trade Pet" }; Globals.SetDataGridComboBoxColumn(1, tpCodeNames.ToList(), _linkgrid); Globals.SetDataGridComboBoxColumn(2, tpCodeNames.ToList(), _linkgrid); Globals.SetDataGridComboBoxColumn(4, restrictList, _linkgrid); Globals.SetDataGridComboBoxColumn(7, restrictList, _linkgrid); Globals.SetDataGridComboBoxColumn(10, restrictList, _linkgrid); Globals.SetDataGridComboBoxColumn(13, restrictList, _linkgrid); Globals.SetDataGridComboBoxColumn(16, restrictList, _linkgrid); linkList.ForEach(link => { int i = _linkgrid.Rows.Add(link.m_Service == 1, link.m_OwnerTeleport, link.m_TargetTeleport, link.m_Fee, GetRestrictDesc(link.Restrict1.m_RestrictType), link.Restrict1.m_Data1, link.Restrict1.m_Data2, GetRestrictDesc(link.Restrict2.m_RestrictType), link.Restrict2.m_Data1, link.Restrict2.m_Data2, GetRestrictDesc(link.Restrict3.m_RestrictType), link.Restrict3.m_Data1, link.Restrict3.m_Data2, GetRestrictDesc(link.Restrict4.m_RestrictType), link.Restrict4.m_Data1, link.Restrict4.m_Data2, GetRestrictDesc(link.Restrict5.m_RestrictType), link.Restrict5.m_Data1, link.Restrict5.m_Data2); _linkgrid.Rows[i].Cells[1].ReadOnly = true; _linkgrid.Rows[i].Cells[2].ReadOnly = true; _linkgrid.Rows[i].Tag = link.m_Status; }); }
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 = _linkgrid.Rows.Cast <DataGridViewRow>().ToList(); _ = rows.Concat(RemovedRows).ToList(); rows.ForEach(linkRow => { CTeleportLink link = new CTeleportLink(); link.m_Service = bool.Parse(linkRow.Cells[0].Value.ToString()) ? 1 : 0; link.m_OwnerTeleport = linkRow.Cells[1].Value.ToString(); link.m_TargetTeleport = linkRow.Cells[2].Value.ToString(); link.m_Fee = Convert.ToInt32(linkRow.Cells[3].Value.ToString()); link.m_RestrictBindMethod = 0; link.m_RunTimeTeleportMethod = 0; link.m_ChectResult = 0; link.Restrict1 = new STeleportRestrict(GetRestrictType(linkRow.Cells[4].Value.ToString()), Convert.ToInt32(linkRow.Cells[5].Value.ToString()), Convert.ToInt32(linkRow.Cells[6].Value.ToString())); link.Restrict2 = new STeleportRestrict(GetRestrictType(linkRow.Cells[7].Value.ToString()), Convert.ToInt32(linkRow.Cells[8].Value.ToString()), Convert.ToInt32(linkRow.Cells[9].Value.ToString())); link.Restrict3 = new STeleportRestrict(GetRestrictType(linkRow.Cells[10].Value.ToString()), Convert.ToInt32(linkRow.Cells[11].Value.ToString()), Convert.ToInt32(linkRow.Cells[12].Value.ToString())); link.Restrict4 = new STeleportRestrict(GetRestrictType(linkRow.Cells[13].Value.ToString()), Convert.ToInt32(linkRow.Cells[14].Value.ToString()), Convert.ToInt32(linkRow.Cells[15].Value.ToString())); link.Restrict5 = new STeleportRestrict(GetRestrictType(linkRow.Cells[16].Value.ToString()), Convert.ToInt32(linkRow.Cells[17].Value.ToString()), Convert.ToInt32(linkRow.Cells[18].Value.ToString())); link.m_Status = (EditStatus)linkRow.Tag; link.SaveToDatabase(); if ((EditStatus)linkRow.Tag != EditStatus.Removed) { linkRow.Cells[1].ReadOnly = true; linkRow.Cells[2].ReadOnly = true; linkRow.Tag = EditStatus.Notr; } }); RemovedRows.Clear(); CTeleportBase.SaveToClient("teleportlink.txt"); MessageBox.Show("Your changes is successfully saved!", "NOTICE", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
internal static async Task <List <CTeleportLink> > GetTeleportLinks() { List <CTeleportLink> list = new List <CTeleportLink>(); using (SqlConnection conn = new SqlConnection(Globals.s_SqlConnectionString)) { conn.Open(); using (SqlCommand command = new SqlCommand("SELECT T.[Service],LTRIM(RTRIM(OT.CodeName128)) as OwnerTeleport,LTRIM(RTRIM(TT.CodeName128)) as TargetTeleport, T.Fee, T.RestrictBindMethod, T.RunTimeTeleportMethod" + ", T.CheckResult, T.Restrict1, T.Data1_1, T.Data1_2, T.Restrict2, T.Data2_1, T.Data2_2, T.Restrict3, T.Data3_1, T.Data3_2" + ",T.Restrict4, T.Data4_1, T.Data4_2, T.Restrict5, T.Data5_1, T.Data5_2 from _RefTeleLink T inner join _RefTeleport OT on OT.ID = T.OwnerTeleport inner join _RefTeleport TT on TT.ID = T.TargetTeleport", conn)) { using (SqlDataReader reader = await command.ExecuteReaderAsync()) { if (reader.HasRows) { while (reader.Read()) { CTeleportLink link = new CTeleportLink(); link.m_Service = reader.GetInt32(0); link.m_OwnerTeleport = reader.GetString(1); link.m_TargetTeleport = reader.GetString(2); link.m_Fee = reader.GetInt32(3); link.m_RestrictBindMethod = reader.GetByte(4); link.m_RunTimeTeleportMethod = reader.GetByte(5); link.m_ChectResult = reader.GetByte(6); STeleportRestrict restrict1; restrict1.m_RestrictType = (STeleportRestrict.RestrictType)reader.GetInt32(7); restrict1.m_Data1 = reader.GetInt32(8); restrict1.m_Data2 = reader.GetInt32(9); link.Restrict1 = restrict1; STeleportRestrict restrict2; restrict2.m_RestrictType = (STeleportRestrict.RestrictType)reader.GetInt32(10); restrict2.m_Data1 = reader.GetInt32(11); restrict2.m_Data2 = reader.GetInt32(12); link.Restrict2 = restrict2; STeleportRestrict restrict3; restrict3.m_RestrictType = (STeleportRestrict.RestrictType)reader.GetInt32(13); restrict3.m_Data1 = reader.GetInt32(14); restrict3.m_Data2 = reader.GetInt32(15); link.Restrict3 = restrict3; STeleportRestrict restrict4; restrict4.m_RestrictType = (STeleportRestrict.RestrictType)reader.GetInt32(16); restrict4.m_Data1 = reader.GetInt32(17); restrict4.m_Data2 = reader.GetInt32(18); link.Restrict4 = restrict4; STeleportRestrict restrict5; restrict5.m_RestrictType = (STeleportRestrict.RestrictType)reader.GetInt32(19); restrict5.m_Data1 = reader.GetInt32(20); restrict5.m_Data2 = reader.GetInt32(21); link.Restrict5 = restrict5; list.Add(link); } } } } } return(list); }