public farmermaster SelectById(Int64 id)
        {
            SqlDataAdapter da;
            DataSet        ds = new DataSet();
            farmermaster   objfarmermaster = new farmermaster();

            try
            {
                SqlCommand cmd = new SqlCommand();
                cmd.CommandText = "farmermaster_SelectById";
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Connection  = ConnectionString;
                cmd.Parameters.AddWithValue("@id", id);
                ConnectionString.Open();
                da = new SqlDataAdapter(cmd);
                da.Fill(ds);

                if (ds != null)
                {
                    if (ds.Tables.Count > 0)
                    {
                        if (ds.Tables[0] != null)
                        {
                            if (ds.Tables[0].Rows.Count > 0)
                            {
                                {
                                    //id, name, img, faddress, mobileno, mobile2, fpassword, milkrate, emailid, bankname, accountno, ifsc, deviceid, countryid, stateid, cityid, isdeleted, isactive

                                    objfarmermaster.id       = Convert.ToInt64(ds.Tables[0].Rows[0]["id"]);
                                    objfarmermaster.name     = Convert.ToString(ds.Tables[0].Rows[0]["name"]);
                                    objfarmermaster.img      = Convert.ToString(ds.Tables[0].Rows[0]["img"]);
                                    objfarmermaster.address  = Convert.ToString(ds.Tables[0].Rows[0]["faddress"]);
                                    objfarmermaster.mobileno = Convert.ToString(ds.Tables[0].Rows[0]["mobileno"]);
                                    //objfarmermaster.mobile2= Convert.ToString(ds.Tables[0].Rows[0]["mobile2"]);
                                    objfarmermaster.password  = Convert.ToString(ds.Tables[0].Rows[0]["fpassword"]);
                                    objfarmermaster.email     = Convert.ToString(ds.Tables[0].Rows[0]["emailid"]);
                                    objfarmermaster.bankname  = Convert.ToString(ds.Tables[0].Rows[0]["bankname"]);
                                    objfarmermaster.accountno = Convert.ToString(ds.Tables[0].Rows[0]["accountno"]);
                                    objfarmermaster.ifsc      = Convert.ToString(ds.Tables[0].Rows[0]["ifsc"]);
                                    objfarmermaster.milkrate  = Convert.ToDecimal(ds.Tables[0].Rows[0]["milkrate"]);
                                    objfarmermaster.countryid = Convert.ToInt64(ds.Tables[0].Rows[0]["countryid"]);
                                    objfarmermaster.stateid   = Convert.ToInt64(ds.Tables[0].Rows[0]["stateid"]);
                                    objfarmermaster.cityid    = Convert.ToInt64(ds.Tables[0].Rows[0]["cityid"]);
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                ErrHandler.writeError(ex.Message, ex.StackTrace);
                return(null);
            }
            finally
            {
                ConnectionString.Close();
            }
            return(objfarmermaster);
        }
        public Int64 Insert(farmermaster objfarmermaster)
        {
            Int64 result = 0;

            try
            {
                SqlCommand cmd = new SqlCommand();
                cmd.CommandText = "farmermaster_Insert";
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Connection  = ConnectionString;

                SqlParameter param = new SqlParameter();
                param.ParameterName = "@id";
                param.Value         = objfarmermaster.id;
                param.SqlDbType     = SqlDbType.BigInt;
                param.Direction     = ParameterDirection.InputOutput;
                cmd.Parameters.Add(param);


                cmd.Parameters.AddWithValue("name", objfarmermaster.name);
                cmd.Parameters.AddWithValue("img", objfarmermaster.img);
                cmd.Parameters.AddWithValue("faddress", objfarmermaster.address);
                cmd.Parameters.AddWithValue("mobileno", objfarmermaster.mobileno);
                //cmd.Parameters.AddWithValue("mobile2",objfarmermaster.mobile2);
                cmd.Parameters.AddWithValue("fpassword", objfarmermaster.password);
                cmd.Parameters.AddWithValue("emailid", objfarmermaster.email);
                cmd.Parameters.AddWithValue("bankname", objfarmermaster.bankname);
                cmd.Parameters.AddWithValue("accountno", objfarmermaster.accountno);
                cmd.Parameters.AddWithValue("ifsc", objfarmermaster.ifsc);
                cmd.Parameters.AddWithValue("milkrate", objfarmermaster.milkrate);
                cmd.Parameters.AddWithValue("countryid", objfarmermaster.countryid);
                cmd.Parameters.AddWithValue("stateid", objfarmermaster.stateid);
                cmd.Parameters.AddWithValue("cityid", objfarmermaster.cityid);


                ConnectionString.Open();
                cmd.ExecuteNonQuery();
                result = Convert.ToInt64(param.Value);
            }
            catch (Exception ex)
            {
                ErrHandler.writeError(ex.Message, ex.StackTrace);
                return(result);
            }
            finally
            {
                ConnectionString.Close();
            }
            return(result);
        }
    //private void BindBank()
    //{
    //    DataTable dtBank = (new Cls_bankmaster_b().SelectAll());
    //    if (dtBank != null)
    //    {
    //        if (dtBank.Rows.Count > 0)
    //        {
    //            ddlBank.DataSource = dtBank;
    //            ddlBank.DataTextField = "bankname";
    //            ddlBank.DataValueField = "bankid";
    //            ddlBank.DataBind();
    //            ListItem objListItem = new ListItem("--Select Bank--", "0");
    //            ddlBank.Items.Insert(0, objListItem);
    //        }
    //    }
    //}

    public void BindFarmer(Int64 id)
    {
        farmermaster objfarmer = (new Cls_farmermaster_b().SelectById(id));

        if (objfarmer != null)
        {
            txtname.Text      = objfarmer.name;
            txtaddress.Text   = objfarmer.address;
            txtmobileno.Text  = objfarmer.mobileno;
            txtpassword.Text  = objfarmer.password;
            txtmilkrate.Text  = objfarmer.milkrate.ToString();
            txtemailid.Text   = objfarmer.email;
            txtbank.Text      = objfarmer.bankname;
            txtaccountno.Text = objfarmer.accountno;
            txtifsc.Text      = objfarmer.ifsc;

            if (!string.IsNullOrEmpty(objfarmer.img))
            {
                imgfarmer.Visible      = true;
                ViewState["fileName"]  = objfarmer.img;
                imgfarmer.ImageUrl     = FarmerFrontPath + objfarmer.img;
                btnImageUpload.Visible = false;
                btnRemove.Visible      = true;
            }
            else
            {
                btnImageUpload.Visible = true;
            }
        }

        DataTable dtProductRates = (new Cls_farmerrates_b().SelectByFarmerId(id));

        if (dtProductRates != null)
        {
            ViewState["Products"] = dtProductRates;
            ViewState["id"]       = dtProductRates.Select().Length;
            Repeater1.DataSource  = dtProductRates;
            Repeater1.DataBind();
            Repeater1.Visible = true;
        }
        else
        {
            Repeater1.DataSource = null;
            Repeater1.DataBind();
            Repeater1.Visible = false;
        }
    }
    protected void btnSave_Click(object sender, EventArgs e)
    {
        Int64        Result = 0, Result1 = 0;
        farmermaster objfarmer = new farmermaster();

        objfarmer.name      = txtname.Text;
        objfarmer.address   = txtaddress.Text;
        objfarmer.mobileno  = txtmobileno.Text;
        objfarmer.password  = txtpassword.Text;
        objfarmer.milkrate  = Convert.ToDecimal(txtmilkrate.Text);
        objfarmer.email     = txtemailid.Text;
        objfarmer.bankname  = txtbank.Text;
        objfarmer.accountno = txtaccountno.Text;
        objfarmer.ifsc      = txtifsc.Text;

        if (ViewState["fileName"] != null)
        {
            objfarmer.img = ViewState["fileName"].ToString();
        }
        if (Request.QueryString["id"] != null)
        {
            objfarmer.id = Convert.ToInt64(ocommon.Decrypt(Request.QueryString["id"].ToString(), true));
            Result       = (new Cls_farmermaster_b().Update(objfarmer));
            if (Result > 0)
            {
                con.Open();
                if (ViewState["Products"] != null)
                {
                    dtProduct = (DataTable)ViewState["Products"];
                }
                farmerrates objrates = new farmerrates();
                foreach (DataRow row in dtProduct.Rows)
                {
                    //id,worksheetid,particularsid,employeeid,workdate,quantity,remark
                    objrates.id        = Convert.ToInt64(row["id"]);
                    objrates.farmerid  = objfarmer.id;
                    objrates.productid = Convert.ToInt64(row["productid"]);
                    objrates.rate      = Convert.ToInt64(row["rate"]);

                    Result1 = (new Cls_farmerrates_b().Update(objrates));

                    //if (Result1 > 0)
                    // flag = true;
                }

                con.Close();

                Response.Redirect(Page.ResolveUrl("~/managefarmers.aspx?mode=u"));
            }
            else
            {
                Clear();
                spnMessgae.Style.Add("color", "red");
                spnMessgae.InnerText = "Farmer Updation Failed...";
                BindFarmer(Convert.ToInt64(ocommon.Decrypt(Request.QueryString["id"].ToString(), true)));
            }
        }
        else
        {
            Result = (new Cls_farmermaster_b().Insert(objfarmer));
            if (Result > 0)
            {
                con.Open();
                if (ViewState["Products"] != null)
                {
                    dtProduct = (DataTable)ViewState["Products"];
                }
                farmerrates objrates = new farmerrates();
                foreach (DataRow row in dtProduct.Rows)
                {
                    //id,worksheetid,particularsid,employeeid,workdate,quantity,remark

                    objrates.farmerid  = Result;
                    objrates.productid = Convert.ToInt64(row["productid"]);
                    objrates.rate      = Convert.ToInt64(row["rate"]);

                    Result1 = (new Cls_farmerrates_b().Insert(objrates));

                    //if (Result1 > 0)
                    // flag = true;
                }

                con.Close();

                Response.Redirect(Page.ResolveUrl("~/managefarmers.aspx?mode=i"));
            }
            else
            {
                Clear();
                spnMessgae.Style.Add("color", "red");
                spnMessgae.InnerText = "Failed To Save The Information...";
            }
        }
    }