Esempio n. 1
0
        protected void fillallvalue()
        {
            datawithminats();

            int indiaunits = 0;
            int othersunits = 0;
            BILLDAL bal = new BILLDAL();
            DataTable dtrowdata = bal.country_name();
             dt = bal.tarifupload(ddltariff.SelectedItem.ToString());

            DataRow[] dr_lunits = dt.Select("CHARGESTYPE = 'FREE VALUE'", "");
            decimal freeval = 0;
            string strmin = "";
            string cnty = "";
            if (dr_lunits.Length > 0)
            {
                foreach (var item in dr_lunits)
                {
                    freeval = Convert.ToDecimal(item["VALUE"]);
                    strmin = item["A"].ToString();
                    cnty = item["COUNTRY_TO"].ToString().ToUpper();
                }
            }
            string col = "";
            for (int i = 0; i < (GridView1.Rows.Count); i++)
            {
                TextBox txt_dr = (TextBox)GridView1.Rows[i].FindControl("txtrate");
                Label txtlblunits = (Label)GridView1.Rows[i].FindControl("lblunits");
                Label txtllbldcost = (Label)GridView1.Rows[i].FindControl("lbldcost");

                Label txtnum = (Label)GridView1.Rows[i].FindControl("lblnum");

                if (Information.IsNumeric(txt_dr.Text) == true)
                {
                    string str_rate = "";
                    string strnumv = txtnum.Text.Substring(0, 2);
                    DataRow[] dr = dtrowdata.Select("isdcode = '" + strnumv + "'", "");

                    if (dr.Length == 0)
                    {
                        //check for size=28 in DataRow[]

                        col += strnumv+ ";";
                      //  col += strnumv + ";";
                      // col[0] = strnumv;

                        Label2.Visible = true;
                        Label2.Text = "Country codes not available in Database ";
                        txtnum.ForeColor = System.Drawing.Color.Red;

                    }
                    string strcut = "";
                    foreach (var item in dr)
                    {
                        strcut = item["country"].ToString().Replace('+', ' ').TrimStart().Trim();
                        break;
                    }
                    if (strcut == ddlcountry.SelectedItem.ToString())
                    {
                        DataRow[] dr_l = dt.Select("CHARGESTYPE = 'LOCAL OUTGOING CALL'", "");
                        if (dr_l.Length > 0)
                        {
                            if (strmin.ToUpper() == "MINUTES")
                            {
                                if (cnty == "OTHER")
                                {
                                    othersunits = Convert.ToInt32(txtlblunits.Text) + othersunits;
                                    if (othersunits > freeval)
                                    {
                                        str_rate = dr_l[0]["VALUE"].ToString();
                                    }
                                    else
                                    {
                                        str_rate = "0";
                                    }
                                }
                                else
                                {
                                    foreach (var item in dr_l)
                                    {
                                        str_rate = dr_l[0]["VALUE"].ToString();
                                        break;
                                    }
                                }

                            }
                            else
                            {
                                str_rate = dr_l[0]["VALUE"].ToString();
                            }
                        }
                    }
                    else if (strcut.ToUpper() == "INDIA")
                    {

                        DataRow[] dr_l = dt.Select("CHARGESTYPE = 'INDIA OUTGOING CALL'", "");
                        if (dr_l.Length > 0)
                        {
                            if (strmin.ToUpper() == "MINUTES")
                            {
                                if (cnty == "OTHER")
                                {
                                    othersunits = Convert.ToInt32(txtlblunits.Text) + othersunits;
                                    if (othersunits > freeval)
                                    {
                                        str_rate = dr_l[0]["VALUE"].ToString();
                                    }
                                }
                                else
                                {
                                    indiaunits = Convert.ToInt32(txtlblunits.Text) + indiaunits;
                                    if (indiaunits > freeval)
                                    {
                                        str_rate = dr_l[0]["VALUE"].ToString();
                                    }
                                    else
                                    {
                                        str_rate = "0";
                                    }
                                }
                            }
                            else
                            {
                                str_rate = dr_l[0]["VALUE"].ToString();
                            }
                        }

                        else
                        {
                            DataRow[] dr_l41 = dt.Select("CHARGESTYPE = 'OTHER COUNTRIES OUTGOING CALL' and country_to = '" + strcut + "' ", "");
                            if (dr_l.Length > 0)
                            {
                                if (strmin.ToUpper() == "MINUTES")
                                {
                                    if (cnty == "OTHER")
                                    {
                                        othersunits = Convert.ToInt32(txtlblunits.Text) + othersunits;
                                        if (othersunits > freeval)
                                        {
                                            str_rate = dr_l41[0]["VALUE"].ToString();
                                        }
                                        else
                                        {
                                            str_rate = "0";
                                        }
                                    }
                                    else
                                    {
                                        foreach (var item in dr_l)
                                        {
                                            str_rate = dr_l41[0]["VALUE"].ToString();
                                            break;
                                        }
                                    }

                                }
                                else
                                {
                                    str_rate = dr_l41[0]["VALUE"].ToString();
                                }
                            }
                            else
                            {
                                DataRow[] dr_oth = dt.Select("CHARGESTYPE = 'OTHER COUNTRIES OUTGOING CALL' and country_to = 'Other' ", "");
                                if (dr_oth.Length > 0)
                                {
                                    if (strmin.ToUpper() == "MINUTES")
                                    {
                                        if (cnty == "OTHER")
                                        {
                                            othersunits = Convert.ToInt32(txtlblunits.Text) + othersunits;
                                            if (othersunits > freeval)
                                            {
                                                str_rate = dr_oth[0]["VALUE"].ToString();
                                            }
                                            else
                                            {
                                                str_rate = "0";
                                            }
                                        }
                                        else
                                        {
                                            foreach (var item in dr_l)
                                            {
                                                str_rate = dr_oth[0]["VALUE"].ToString();
                                                break;
                                            }
                                        }

                                    }
                                    else
                                    {
                                        str_rate = dr_oth[0]["VALUE"].ToString();
                                    }
                                }
                            }

                        }
                    }
                    else
                    {
                        DataRow[] dr_l = dt.Select("CHARGESTYPE = 'OTHER COUNTRIES OUTGOING CALL' and country_to = '" + strcut + "' ", "");
                        if (dr_l.Length > 0)
                        {
                            if (strmin.ToUpper() == "MINUTES")
                            {
                                othersunits = Convert.ToInt32(txtlblunits.Text) + othersunits;
                                if (othersunits > freeval)
                                {
                                    foreach (var item in dr_l)
                                    {
                                        str_rate = item["VALUE"].ToString();
                                        break;
                                    }
                                }
                                else
                                {
                                    foreach (var item in dr_l)
                                    {
                                        str_rate = "0";  //item["VALUE"].ToString();
                                        break;
                                    }
                                }

                            }
                            else
                            {
                                str_rate = dr_l[0]["VALUE"].ToString();
                            }
                        }
                        else
                        {
                            DataRow[] dr_oth = dt.Select("CHARGESTYPE = 'OTHER COUNTRIES OUTGOING CALL' and country_to = 'Other' ", "");
                            if (dr_oth.Length > 0)
                            {
                                if (strmin.ToUpper() == "MINUTES")
                                {
                                    if (cnty == "OTHER")
                                    {
                                        othersunits = Convert.ToInt32(txtlblunits.Text) + othersunits;
                                        if (othersunits > freeval)
                                        {
                                            str_rate = dr_oth[0]["VALUE"].ToString();
                                        }
                                        else
                                        {
                                            str_rate = "0";
                                        }
                                    }
                                    else
                                    {
                                        str_rate = dr_oth[0]["VALUE"].ToString();
                                    }

                                }
                                else
                                {
                                    str_rate = dr_oth[0]["VALUE"].ToString();
                                }
                            }
                        }
                    }

                    //   DataRow[] drtp = TARIFDATA.Select("CHARGESTYPE = 'OTHER COUNTRIES OUTGOING CALL'");

                    txt_dr.Text = str_rate == "" ? "0" : str_rate; // dt.Rows[0]["LOCALOUTGOINGCALL"].ToString();

                    decimal dval = Convert.ToDecimal(txtlblunits.Text) * Convert.ToDecimal(str_rate == "" ? "0" : str_rate);
                    txtllbldcost.Text = dval.ToString();
                }
                Label txt_dv = (Label)GridView1.Rows[i].FindControl("lbldtime");

                Label txt_dtime = (Label)GridView1.Rows[i].FindControl("LabelDATE");

                Label txt_orgin = (Label)GridView1.Rows[i].FindControl("LabelORIGIN");

                Label txt_daytime = (Label)GridView1.Rows[i].FindControl("LabelDAYDATE");

                if (txt_dv.Text == "SMS" && txt_dv != null || txt_dtime.Text == "SMS" && txt_dtime != null || txt_orgin.Text == "SMS" && txt_orgin != null || txt_daytime.Text == "SMS" && txt_daytime != null)
                {
                    for (int ct = i; ct < (GridView1.Rows.Count); ct++)
                    {
                        i++;
                        TextBox txtr = (TextBox)GridView1.Rows[ct].FindControl("txtrate");
                        if (Information.IsNumeric(txtr.Text) == true)
                        {

                            //==============================================================================
                            Label txt_num = (Label)GridView1.Rows[ct].FindControl("lblnum");
                            string str_te = "";
                            string strnumv = txt_num.Text.Substring(0, 2);

                            string str_rate = "";

                            DataRow[] dr = dtrowdata.Select("isdcode = '" + strnumv + "'", "");
                            string strcut = "";
                            foreach (var item in dr)
                            {
                                strcut = item["country"].ToString();
                                break;
                            }
                            if (strcut == ddlcountry.SelectedItem.ToString())
                            {
                                DataRow[] dr_l = dt.Select("CHARGESTYPE = 'LOCAL SMS'", "");
                                foreach (var item in dr_l)
                                {
                                    str_rate = item["VALUE"].ToString();
                                    break;
                                }
                            }
                            else
                            {
                                DataRow[] dr_l = dt.Select("CHARGESTYPE = 'INTL SMS'", "");
                                foreach (var item in dr_l)
                                {
                                    str_rate = item["VALUE"].ToString();
                                    break;
                                }

                            }
                            //==============================================================================
                            Label txtlbl_units = (Label)GridView1.Rows[ct].FindControl("lblunits");
                            Label txtllbl_dcost = (Label)GridView1.Rows[ct].FindControl("lbldcost");
                            txtr.Text = str_rate == "" ? "0" : str_rate; // dt.Rows[0]["LOCALSMS"].ToString();
                            decimal dval = Convert.ToDecimal(txtlbl_units.Text) * Convert.ToDecimal(str_rate == "" ? "0" : str_rate);
                            txtllbl_dcost.Text = dval.ToString();
                        }
                    }

                }

                if (txt_dv.Text == "DATA" && txt_dv != null || txt_dtime.Text == "DATA PAY PER USE" && txt_dtime != null || txt_orgin.Text == "DATA" && txt_orgin != null || txt_daytime.Text == "SMS" && txt_daytime != null)
                {
                    for (int ct = i; ct < (GridView1.Rows.Count); ct++)
                    {
                        i++;
                        TextBox txtr = (TextBox)GridView1.Rows[ct].FindControl("txtrate");
                        if (Information.IsNumeric(txtr.Text) == true)
                        {
                            //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                            //==============================================================================
                            //Label txt_num = (Label)GridView1.Rows[ct].FindControl("lblnum");
                            //string str_te = "";
                            //string strnumv = txt_num.Text.Substring(0, 2);

                            string str_rate = "";

                            //DataRow[] dr = dtrowdata.Select("isdcode = '" + strnumv + "'", "");
                            string strcut = "";
                            //foreach (var item in dr)
                            //{
                            //    strcut = item["country"].ToString();
                            //    break;
                            //}

                            string rateval = "";
                            if (strcut != ddlcountry.SelectedItem.ToString())
                            {
                                Label units = (Label)GridView1.Rows[ct].FindControl("lblunits");
                                string[] stmbcharges = DropDownListBoltion.SelectedItem.ToString().Split(' ');

                                string mbdata = "";
                                if (stmbcharges[1] == "GB")
                                {
                                    mbdata = (Convert.ToDecimal(stmbcharges[0]) * 1024).ToString();
                                }
                                else
                                    mbdata= stmbcharges[0].ToString();

                                if (Convert.ToDecimal(units.Text) > Convert.ToDecimal(mbdata))
                                {
                                    decimal _ddata = 0;
                                    decimal _dvalue = 0;
                                    DataRow[] dr_l = dt.Select("CHARGESTYPE = 'DATA PAY PER USE'", "");
                                    if (dr_l.Length > 0)
                                    {
                                        _dvalue = Convert.ToDecimal( dr_l[0]["VALUE"]);

                                    }
                                    _ddata = Convert.ToDecimal(units.Text) - Convert.ToDecimal(stmbcharges[0]);
                                    rateval = _dvalue.ToString();
                                    str_rate = (_dvalue * _ddata).ToString();

                                }
                                else
                                {

                                    rateval = "0";
                                    str_rate = "0";
                                }
                            }

                            //==============================================================================
                            Label txtlbl_units = (Label)GridView1.Rows[ct].FindControl("lblunits");
                            Label txtllbl_dcost = (Label)GridView1.Rows[ct].FindControl("lbldcost");
                            txtr.Text = rateval == "" ?  "0" : rateval; // dt.Rows[0]["LOCALSMS"].ToString();
                         //  decimal dval = Convert.ToDecimal(str_rate) * Convert.ToDecimal(str_rate == "" ? "0" : str_rate);
                            txtllbl_dcost.Text = str_rate;

                        }
                    }

                }

            }
        }