예제 #1
0
    protected void btnDepositSubmit_Click(object sender, EventArgs e)
    {
        try
        {
            objBal = new ClsBAL();

            ListItem value = ddlAgents.Items.FindByText(txtAgents.Text.ToString());

            if (value == null)
            {
                ddlAgents.SelectedIndex = 0;
                lblMsg.InnerHtml = "The Agent Username does not exists.";

                txtAgentName.Focus();
                txtAgentName.Text = "";
            }
            else
            {
                if (Session["Role"].ToString() == "Admin")
                {
                    ddlAgents.SelectedItem.Value = value.Value;
                    string msg = objBal.AddAgentDeposit(Convert.ToInt32(ddlAgents.SelectedItem.Value.ToString())
                        , Convert.ToDouble(txtAmount.Text.ToString()), txtDepositDetails.Text.Trim().ToString(), Convert.ToInt32(Session["UserID"].ToString())
                        , rbtnType.SelectedItem.Text.ToString(), txtTransactionNo.Text.Trim().ToString(), txtReason.Text.Trim());

                    BindDeposits();
                    DeductAgentBalance(Convert.ToInt32(ddlAgents.SelectedItem.Value), Convert.ToDouble(0.00),
                                Convert.ToInt32(Userid), rbtnType.SelectedItem.Text.ToString(), Convert.ToDouble(txtAmount.Text.ToString()),
                                Convert.ToDouble(0.00), Convert.ToInt32(0.00));

                    System.Data.DataSet ds = objBal.GetAgentById(Convert.ToInt32(ddlAgents.SelectedItem.Value.ToString()));

                    string body = "Dear " + ds.Tables[0].Rows[0]["UserName"].ToString() + ", <br/> " + "Rs. " + txtAmount.Text.ToString() + "/- amount has been credited in your account. <br/><br/> Thanks, <br/>Love Journey Team";
                    bool res = Mailsender.SendEmail(ds.Tables[0].Rows[0]["EmailId"].ToString(), "", "", "Deposit Details", body);

                    lblMsg.InnerHtml = msg;
                    BindDeposits(); txtAmount.Text = txtDepositDetails.Text = txtTransactionNo.Text = txtReason.Text = ""; rbtnType.SelectedIndex = -1;
                }
                else if (Session["Role"].ToString() == "Distributor")
                {
                    if (Convert.ToDouble(Session["Balance"].ToString()) >= Convert.ToDouble(txtAmount.Text.ToString()))
                    {
                        ddlAgents.SelectedItem.Value = value.Value;
                        string msg = objBal.AddAgentDeposit(Convert.ToInt32(ddlAgents.SelectedItem.Value.ToString())
                            , Convert.ToDouble(txtAmount.Text.ToString()), txtDepositDetails.Text.Trim().ToString(), Convert.ToInt32(Session["UserID"].ToString())
                            , rbtnType.SelectedItem.Text.ToString(), txtTransactionNo.Text.Trim().ToString(), txtReason.Text.Trim());

                        BindDeposits();
                        DeductAgentBalance(Convert.ToInt32(ddlAgents.SelectedItem.Value), Convert.ToDouble(0.00),
                                    Convert.ToInt32(Userid), rbtnType.SelectedItem.Text.ToString(), Convert.ToDouble(txtAmount.Text.ToString()),
                                    Convert.ToDouble(0.00), Convert.ToInt32(0.00));

                        lblMsg.InnerHtml = msg;

                        if (msg == "Inserted Successfully.")
                        {
                            objBal.deductDistributorbalance(Convert.ToInt32(Session["UserID"].ToString()), Convert.ToDouble(txtAmount.Text.ToString()), "Deduct");

                            ClsBAL objBAL = new ClsBAL();
                            System.Data.DataSet dataset = objBAL.GetAgentByUserId(Convert.ToInt32(Session["UserID"].ToString()));
                            Session["Balance"] = dataset.Tables[0].Rows[0]["Balance"].ToString();

                            Label balance = (Label)this.Master.FindControl("lblDbBal");
                            balance.Text = "Your balance is : " + " " + Session["Balance"].ToString();

                        }

                        System.Data.DataSet ds = objBal.GetAgentById(Convert.ToInt32(ddlAgents.SelectedItem.Value.ToString()));

                        string body = "Dear " + ds.Tables[0].Rows[0]["UserName"].ToString() + ", <br/> " + "Rs. " + txtAmount.Text.ToString() + "/- amount has been credited in your account. <br/><br/> Thanks, <br/>Love Journey Team";
                        bool res = Mailsender.SendEmail(ds.Tables[0].Rows[0]["EmailId"].ToString(), "", "", "Deposit Details", body);

                        BindDeposits(); txtAmount.Text = txtDepositDetails.Text = txtTransactionNo.Text = txtReason.Text = ""; rbtnType.SelectedIndex = -1;
                    }
                    else
                    {
                        lblMsg.InnerHtml = "Your balance should be greater than the adding amount.";
                    }
                }
            }
        }
        catch (Exception ex)
        {
            lblMsg.InnerHtml = ex.Message;

        }
    }
예제 #2
0
 DataSet GetAgentById(int id)
 {
     try
     {
         objBal = new ClsBAL();
         return objBal.GetAgentById(id);
     }
     catch (Exception ex)
     {
         lblMsg.InnerHtml = ex.Message;
         throw;
     }
 }