protected void LinkButton6_Click(object sender, EventArgs e)
    {
        DataTable dt = (DataTable)Cache["SentTBL"];
        if (dt.Rows.Count != 0)
        {
            ArrayList al = new ArrayList();
            int msgCount = Convert.ToInt16(new main_class().get_value_from_setting("messagecount"));
            main_class mc = new main_class();
            foreach (DataRow dr in dt.Rows)
            {
                al.Add(mc.GetAMessageCount(dr["متن"].ToString()));
            }

            int recieversCount = 0;
            int sentCount = 0;
            int TotalCount = 0;
            double sentCost = 0;
            double currentCredit = 0.0;
            double FarsiCost = 0;
            double EnglishCost = 0;

            foreach (DataRow dr in new MainDataModuleTableAdapters.tbl_sms_billingTableAdapter().GetDataBy1(
                Convert.ToInt32(Session["owner"].ToString())).Rows)
            {
                FarsiCost = Convert.ToDouble(dr["sb_FarsiSMSPrice"].ToString());
                EnglishCost = Convert.ToDouble(dr["sb_EngSMSPrice"].ToString());
            }

            foreach (main_class.MessageProperties mp in al)
            {
                sentCount = 0;
                recieversCount = recieversCount + 1;
                sentCount = mp.howManyMessage;
                if (mp.isFarsi) { sentCost = sentCost + ((FarsiCost)*sentCount); }
                else { sentCost += ((EnglishCost) * sentCount); }
                TotalCount += sentCount;
            }

            currentCredit = (double)new MainDataModuleTableAdapters.tbl_sms_billingTableAdapter().GetLastCredit(Convert.ToInt32(Session["owner"].ToString()));

            lbl_recievers_count.Text = recieversCount.ToString();
            lbl_sent_count.Text = TotalCount.ToString();
            lbl_sent_cost.Text = sentCost.ToString();
            lbl_customer_current_credit.Text = (currentCredit-sentCost).ToString();

            if (sentCost > currentCredit)
            {
                pnl_NotEnoughCredit.Visible = true;
                pnl_OkSend.Visible = false;
                lbl_customer_current_credit.ForeColor = Color.Red;
            }
            else
            {
                pnl_NotEnoughCredit.Visible = false;
                pnl_OkSend.Visible = true;
                lbl_customer_current_credit.ForeColor = Color.Green;
            }
        }
        else
        {
            err1.Text = "هیچ پیامی برای ارسال وجود ندارد لطفا لیست انتخابی مراحل قبل را چک کنید";
        }
    }
    protected void LinkButton6_Click(object sender, EventArgs e)
    {
        int groupid = Convert.ToInt32(Convert.ToInt32((sender as LinkButton).ToolTip));
        int sessionid = Convert.ToInt32(Convert.ToInt32((Session["owner"].ToString())));

        new tbl_sms_sendTableAdapter().DeleteSMSGroup(groupid, sessionid);
        new tbl_sms_send_groupsTableAdapter().DeleteByID(groupid, sessionid);

        DataTable dt = new MainDataModuleTableAdapters.tbl_sms_sendTableAdapter().GetDataByGroupID(groupid, sessionid) ;

        ArrayList al = new ArrayList();
        int msgCount = Convert.ToInt16(new main_class().get_value_from_setting("messagecount"));
        main_class mc = new main_class();
        foreach (DataRow dr in dt.Rows)
        {
            al.Add(mc.GetAMessageCount(dr["s_body"].ToString()));
        }

        int recieversCount = 0;
        int sentCount = 0;
        double sentCost = 0;
        double currentCredit = 0.0;
        double FarsiCost = 0;
        double EnglishCost = 0;

        foreach (DataRow dr in new MainDataModuleTableAdapters.tbl_sms_billingTableAdapter().GetDataBy1(
            Convert.ToInt32(Session["owner"].ToString())).Rows)
        {
            FarsiCost = Convert.ToDouble(dr["sb_FarsiSMSPrice"].ToString());
            EnglishCost = Convert.ToDouble(dr["sb_EngSMSPrice"].ToString());
        }

        foreach (main_class.MessageProperties mp in al)
        {
            recieversCount = recieversCount + 1;
            sentCount = sentCount + mp.howManyMessage;
            if (mp.isFarsi) { sentCost = sentCost + FarsiCost; }
            else { sentCost = sentCost + EnglishCost; }
        }

        new tbl_sms_billing_addcreditTableAdapter().Insert(sessionid,sentCost,DateTime.Now,"برگشت پیام های حذف شده به کد "+groupid.ToString());

        gr_group_list.DataBind();
    }