private void FillAgents() { AgentMaster oAgentMaster = new AgentMaster(); AgentDTO[] oAgentData = oAgentMaster.GetData(); ListItemCollection li = new ListItemCollection(); ListItem l = new ListItem("Choose Agent", "0"); ddlAgent.Items.Insert(0, l); if (oAgentData != null) { for (int i = 0; i < oAgentData.Length; i++) { l = new ListItem(oAgentData[i].AgentName.ToString(), oAgentData[i].AgentId.ToString()); ddlAgent.Items.Insert(i + 1, l); } } }
protected void btnGenarateToken_Click(object sender, EventArgs e) { lblError.Text = ""; AgentMaster oAgentMaster = new AgentMaster(); AgentDTO[] oAgentData = oAgentMaster.GetData(Convert.ToInt32(ddlAgent.SelectedValue)); string AgentCode = oAgentData[0].AgentCode.ToString(); string AgentPassword = oAgentData[0].Password.ToString(); if (AgentCode != "" && AgentPassword != "") { string Token = Convert.ToBase64String(ASCIIEncoding.ASCII.GetBytes(AgentCode + ":" + AgentPassword)); // byte[] byt = Encoding.ASCII.GetBytes(Token); // byte[] data1 = Convert.FromBase64String(Token); //string value = Encoding.ASCII.GetString(byt); AgentDTO oAgentSaveData = new AgentDTO(); oAgentSaveData.AgentId = Convert.ToInt32(ddlAgent.SelectedValue); oAgentSaveData.TokenNo = Token; bool Agent = oAgentMaster.ApiAuthInsert(oAgentSaveData); if (Agent) { lblError.Text = "Token Genarate Successfully"; } else { lblError.Text = "This Agent Is Already Genarate Token"; } } else { lblError.Text = "This Agent Can't Genarate Token,Password or AgentCode Missing"; } BindGrid(); }