Example #1
0
    protected void btnadtolist_Click(object sender, EventArgs e)
    {
        int       inc1 = 0;
        DataTable dsp1 = ClsIp.SelctIpControlMastertblId();

        if (dsp1.Rows.Count > 0)
        {
            if (rdipright.SelectedIndex == 0)
            {
                string         str45 = "Select IpControldetailtbl.* from IpControlMastertbl inner join IpControldetailtbl on IpControldetailtbl.IpcontrolId= IpControlMastertbl.IpcontrolId  where CID='" + Session["comid"].ToString() + "'  and Ipaddress='" + dynip + "' and IpControldetailtbl.Cidwise='True' and Userwise='False' ";
                SqlCommand     cmd45 = new SqlCommand(str45, con);
                SqlDataAdapter da    = new SqlDataAdapter(cmd45);
                DataTable      ds    = new DataTable();
                da.Fill(ds);
                if (ds.Rows.Count > 0)
                {
                    statuslable.Visible = true;
                    statuslable.Text    = "Record already exist";
                }
                else
                {
                    inc1 = ClsIp.InsertIpAddress(Convert.ToInt32(dsp1.Rows[0]["IpcontrolId"]), Convert.ToBoolean(1), Convert.ToBoolean(0), "0", dynip);
                    statuslable.Visible = true;
                    statuslable.Text    = "Record inserted successfully";
                }
            }
            else
            {
                string         str45 = "Select IpControldetailtbl.* from IpControlMastertbl inner join IpControldetailtbl on IpControldetailtbl.IpcontrolId= IpControlMastertbl.IpcontrolId  where CID='" + Session["comid"].ToString() + "'  and Ipaddress='" + dynip + "' and IpControldetailtbl.Cidwise='False' and Userwise='True' and IpControldetailtbl.UserId='" + ddluser.SelectedValue + "' ";
                SqlCommand     cmd45 = new SqlCommand(str45, con);
                SqlDataAdapter da    = new SqlDataAdapter(cmd45);
                DataTable      ds    = new DataTable();
                da.Fill(ds);

                if (ds.Rows.Count > 0)
                {
                    statuslable.Visible = true;
                    statuslable.Text    = "Record already exist";
                }
                else
                {
                    inc1 = ClsIp.InsertIpAddress(Convert.ToInt32(dsp1.Rows[0]["IpcontrolId"]), Convert.ToBoolean(0), Convert.ToBoolean(1), ddluser.SelectedValue, dynip);

                    statuslable.Visible = true;
                    statuslable.Text    = "Record inserted successfully";
                }
            }



            FillGridView1();
        }
    }
Example #2
0
    protected void btnaddn0_Click(object sender, EventArgs e)
    {
        int flag  = ret(txtIpAddress.Text);
        int flag1 = ret(txtip1.Text);
        int flag2 = ret(txtip2.Text);
        int flag3 = ret(txtip3.Text);
        int inc   = 0;

        if (flag == 0 && flag1 == 0 && flag2 == 0 && flag3 == 0)
        {
            string    Ipaddd = txtIpAddress.Text + "." + txtip1.Text + "." + txtip2.Text + "." + txtip3.Text;
            DataTable dsp    = ClsIp.SelctIpControlMastertblId();
            if (dsp.Rows.Count > 0)
            {
                if (rdipright.SelectedIndex == 0)
                {
                    inc = ClsIp.InsertIpAddress(Convert.ToInt32(dsp.Rows[0]["IpcontrolId"]), Convert.ToBoolean(1), Convert.ToBoolean(0), "0", Ipaddd);
                }
                else if (rdipright.SelectedIndex == 1)
                {
                    inc = ClsIp.InsertIpAddress(Convert.ToInt32(dsp.Rows[0]["IpcontrolId"]), Convert.ToBoolean(0), Convert.ToBoolean(1), ddluser.SelectedValue, Ipaddd);
                }
                if (inc > 0)
                {
                    SqlDataAdapter daq = new SqlDataAdapter("select * from TBLUserLoginIpRestrictionPreference where userid='" + ddluser.SelectedValue + "' and compid='" + Session["Comid"] + "'", con);
                    DataTable      dys = new DataTable();
                    daq.Fill(dys);
                    if (dys.Rows.Count > 0)
                    {
                        SqlCommand cmf = new SqlCommand("update TBLUserLoginIpRestrictionPreference set MakeIPRestriction='1' where userid='" + ddluser.SelectedValue + "' and compid='" + Session["Comid"] + "' ", con);
                        con.Open();
                        cmf.ExecuteNonQuery();
                        con.Close();
                    }
                    else
                    {
                        SqlCommand cmf = new SqlCommand("insert into  TBLUserLoginIpRestrictionPreference(compid,userid, MakeIPRestriction)values('" + Session["Comid"] + "','" + ddluser.SelectedValue + "','1') ", con);
                        con.Open();
                        cmf.ExecuteNonQuery();
                        con.Close();
                    }
                    statuslable.Visible = true;
                    statuslable.Text    = "Record inserted successfully";
                    txtIpAddress.Text   = "";
                    txtip1.Text         = "";
                    txtip2.Text         = "";
                    txtip3.Text         = "";
                    txtIpAddress.Focus();
                    FillGridView1();
                }
                else
                {
                    statuslable.Visible = true;
                    statuslable.Text    = "Record alredy existed";
                }
            }
            else
            {
                statuslable.Visible = true;
                statuslable.Text    = "Record not inserted";
            }
        }
        else
        {
            statuslable.Visible = true;
            statuslable.Text    = "Please enter IP Address range between 0-255 or *";
        }
    }