public Int64 Insert(farmerrates objfarmerrates)
        {
            Int64 result = 0;

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

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


                cmd.Parameters.AddWithValue("farmerid", objfarmerrates.farmerid);
                cmd.Parameters.AddWithValue("productid", objfarmerrates.productid);
                cmd.Parameters.AddWithValue("rate", objfarmerrates.rate);


                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);
        }
    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...";
            }
        }
    }