using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;

public partial class User_Setmarkup : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Page.Session["agid"] == null)
            {
                Response.Redirect("~/login.aspx");
            }
            else
            {
                get_markup();
            }
        }
    }
    protected void btnsetmarkup_Click(object sender, EventArgs e)
    {
        try
        {
            if (txtmarkup.Text != "")
            {
                if (Convert.ToInt32(txtmarkup.Text) >= 0)
                {
                    if (Convert.ToInt32(txtmarkup.Text) <= Convert.ToInt32(2000))
                    {
                       
                                updatequery();
                           

                    }
                    else
                    {
                        ScriptManager.RegisterStartupScript(this, this.GetType(), "alertBox", "alert('Markup value can not be more than Rs.2000');", true);
                      
                    }
                }
                else
                {
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "alertBox", "alert('Mark up can not be in negative.');", true);
                  
                }

            }
            else
            {
                ScriptManager.RegisterStartupScript(this, this.GetType(), "alertBox", "alert('Please insert markup.');", true);
              
            }
        }
        catch (Exception ex)
        {
            string str = ex.Message;
        }
        finally
        {

        }
    }
    protected void insertquery()
    {
        try
        {
            SqlParameter[] puneet = new SqlParameter[]
            {
                new SqlParameter("@ds_id",Convert.ToString(Session["distributor"])),
                new SqlParameter("@agent_id",Convert.ToString(Session["agid"])),
                new SqlParameter("@markupval",Convert.ToDouble(txtmarkup.Text.Trim()))
            };
            int i = SqlHelper.ExecuteNonQuery(SqlHelper.mainConnectionString, CommandType.StoredProcedure, "setmarkinsert_air_pk", puneet);
            ScriptManager.RegisterStartupScript(this, this.GetType(), "alertBox", "alert('Markup Set Successfully.');", true);
           
        }
        catch (Exception ex)
        {
            string str = ex.Message;
        }
        finally
        {

        }

    }
    protected void updatequery()
    {
        try
        {
            SqlParameter[] puneet = new SqlParameter[]
            {
                new SqlParameter("@agent_id",Convert.ToString(Session["agid"])),
                new SqlParameter("@markup",Convert.ToDouble(txtmarkup.Text.Trim())),
                new SqlParameter("@service","flight")
            };
            int k = SqlHelper.ExecuteNonQuery(SqlHelper.mainConnectionString, CommandType.StoredProcedure, "setAgentMarkup", puneet);
            ScriptManager.RegisterStartupScript(this, this.GetType(), "alertBox", "alert('Markup Set Successfully.');", true);
            //lblerror.Text = "Markup Set Successfully";
            //lblerror.ForeColor = Color.Blue;
        }
        catch (Exception ex)
        {
            string str = ex.Message;
        }
        finally
        {

        }
    }
    public void get_markup()
    {
        try
        {
            DataSet ds;
            SqlParameter[] puneet = new SqlParameter[]
        {
            new SqlParameter("@agent_id",Convert.ToString(Session["agid"]))
            
        };

            ds = SqlHelper.GetDataSet(SqlHelper.mainConnectionString, CommandType.StoredProcedure, "getmarkup_new", puneet);
            if (ds.Tables[0].Rows.Count > 0)
            {
                string mark = ds.Tables[0].Rows[0]["agent_markup"].ToString();
                txtmarkup.Text = Convert.ToDecimal(mark).ToString("f0");
            }
            else
            {
                txtmarkup.Text = "0";
            }
        }
        catch (Exception ex)
        {
        }
    }

    protected void btngo_Click(object sender, EventArgs e)
    {
        Response.Redirect("index.aspx", false);
    }
}
