Esempio n. 1
0
        /*
         * public DataTable SelectAll_Admin()
         * {
         *  DataSet ds = new DataSet();
         *  SqlDataAdapter da;
         *  try
         *  {
         *      SqlCommand cmd = new SqlCommand();
         *      cmd.CommandText = "articlestock_SelectAllAdmin";
         *      cmd.CommandType = CommandType.StoredProcedure;
         *      cmd.Connection = ConnectionString;
         *      ConnectionString.Open();
         *      da = new SqlDataAdapter(cmd);
         *      da.Fill(ds);
         *  }
         *  catch (Exception ex)
         *  {
         *      ErrHandler.writeError(ex.Message, ex.StackTrace);
         *      return null;
         *  }
         *  finally
         *  {
         *      ConnectionString.Close();
         *  }
         *  return ds.Tables[0];
         * }
         *
         * public DataTable SelectAll()
         * {
         *  DataSet ds = new DataSet();
         *  SqlDataAdapter da;
         *  try
         *  {
         *      SqlCommand cmd = new SqlCommand();
         *      cmd.CommandText = "articlestock_SelectAll";
         *      cmd.CommandType = CommandType.StoredProcedure;
         *      cmd.Connection = ConnectionString;
         *      ConnectionString.Open();
         *      da = new SqlDataAdapter(cmd);
         *      da.Fill(ds);
         *  }
         *  catch (Exception ex)
         *  {
         *      ErrHandler.writeError(ex.Message, ex.StackTrace);
         *      return null;
         *  }
         *  finally
         *  {
         *      ConnectionString.Close();
         *  }
         *  return ds.Tables[0];
         * }
         *
         * public articlestock SelectById(Int64 bankid)
         * {
         *  SqlDataAdapter da;
         *  DataSet ds = new DataSet();
         *  articlestock objarticlestock = new articlestock();
         *  try
         *  {
         *      SqlCommand cmd = new SqlCommand();
         *      cmd.CommandText = "articlestock_SelectById";
         *      cmd.CommandType = CommandType.StoredProcedure;
         *      cmd.Connection = ConnectionString;
         *      cmd.Parameters.AddWithValue("@bankid", bankid);
         *      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)
         *                  {
         *                      {
         *
         *                          objarticlestock.bankid = Convert.ToInt32(ds.Tables[0].Rows[0]["bankid"]);
         *                          objarticlestock.bankname = Convert.ToString(ds.Tables[0].Rows[0]["bankname"]);
         *                          objarticlestock.bankifsccode = Convert.ToString(ds.Tables[0].Rows[0]["bankifsccode"]);
         *                          objarticlestock.bankbranch = Convert.ToString(ds.Tables[0].Rows[0]["bankbranch"]);
         *                          objarticlestock.accountno = Convert.ToString(ds.Tables[0].Rows[0]["accountno"]);
         *                          objarticlestock.accountholdername = Convert.ToString(ds.Tables[0].Rows[0]["accountholdername"]);
         *                          objarticlestock.balance = Convert.ToDecimal(ds.Tables[0].Rows[0]["balance"]);
         *
         *                      }
         *                  }
         *              }
         *          }
         *      }
         *  }
         *  catch (Exception ex)
         *  {
         *      ErrHandler.writeError(ex.Message, ex.StackTrace);
         *      return null;
         *  }
         *  finally
         *  {
         *      ConnectionString.Close();
         *  }
         *  return objarticlestock;
         * }
         *
         */

        public Int64 InsertUpdate(articlestock objarticlestock)
        {
            //id, pid, sizeid, colorid, quantity

            Int64 result = 0;

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

                SqlParameter param = new SqlParameter();
                param.ParameterName = "@id";
                param.Value         = objarticlestock.id;
                param.SqlDbType     = SqlDbType.Int;
                param.Direction     = ParameterDirection.InputOutput;
                cmd.Parameters.Add(param);
                cmd.Parameters.AddWithValue("@pid", objarticlestock.pid);
                cmd.Parameters.AddWithValue("@sizeid", objarticlestock.sizeid);
                cmd.Parameters.AddWithValue("@colorid", objarticlestock.colorid);
                cmd.Parameters.AddWithValue("@quantity", objarticlestock.quantity);

                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 ddlCategory_SelectedIndexChanged(object sender, EventArgs e)
     * {
     *  Int64 id = Int64.Parse(ddlCategory.SelectedValue.ToString());
     *  try
     *  {
     *      product objProduct = new product();
     *      Cls_product_b clsProduct = new Cls_product_b();
     *      dtProduct = clsProduct.Product_WSSelectAllProductUsingCategoryId(id);
     *      if (dtProduct != null)
     *      {
     *          if (dtProduct.Rows.Count > 0)
     *          {
     *              //ddlProduct.DataSource = dtProduct;
     *              //ddlProduct.DataTextField = "productname";
     *              //ddlProduct.DataValueField = "pid";
     *              //ddlProduct.DataBind();
     *              //System.Web.UI.WebControls.ListItem objListItem = new System.Web.UI.WebControls.ListItem("--Select Product(s)--", "0");
     *              //ddlProduct.Items.Insert(0, objListItem);
     *          }
     *      }
     *
     *  }
     *  catch (Exception ex)
     *  {
     *      ErrHandler.writeError(ex.Message, ex.StackTrace);
     *      //return null;
     *  }
     *  finally { con.Close(); }
     *
     * }
     *
     * protected void btnAdd_Click(object sender, EventArgs e)
     * {
     *  DataTable dtProduct = new DataTable();
     *  dtProduct = GetProducts();
     *
     *  if (ViewState["Products"] != null)
     *  {
     *      dtProduct = (DataTable)ViewState["Products"];
     *
     *
     *      Repeater1.DataSource = dtProduct;
     *      Repeater1.DataBind();
     *      Repeater1.Visible = true;
     *  }
     *  else
     *  {
     *      Repeater1.DataSource = null;
     *      Repeater1.DataBind();
     *      Repeater1.Visible = false;
     *  }
     *
     *  // ddlProductName.SelectedItem = string.Empty;
     *  //ddlCategory.SelectedIndex = 0;
     *  //ddlProduct.SelectedIndex = 0;
     *
     *  txtquantity.Text = "0";
     * }
     *
     *
     *
     * private DataTable GetProducts()
     * {
     *
     *  DataTable dtProduct = null;
     *  if (ViewState["SrNo"] != null)
     *  {
     *      int SrNo = Convert.ToInt32((ViewState["SrNo"]));
     *      SrNo++;
     *      ViewState["SrNo"] = SrNo;
     *  }
     *  else
     *  {
     *      ViewState["SrNo"] = 1;
     *  }
     *
     *  if (ViewState["Products"] == null)
     *  {
     *
     *      // [ProdId],[ProdName],[ProdBrand] ,[ProdSize]
     *
     *      dtProduct = new DataTable("Products");
     *      dtProduct.Columns.Add(new DataColumn("SrNo", typeof(int)));
     *      dtProduct.Columns.Add(new DataColumn("CatId", typeof(int)));
     *      dtProduct.Columns.Add(new DataColumn("CategoryName", typeof(string)));
     *      dtProduct.Columns.Add(new DataColumn("ProdId", typeof(int)));
     *      dtProduct.Columns.Add(new DataColumn("ProductName", typeof(string)));
     *      dtProduct.Columns.Add(new DataColumn("Quantity", typeof(string)));
     *
     *      ViewState["Products"] = dtProduct;
     *  }
     *  else
     *  {
     *      dtProduct = (DataTable)ViewState["Products"];
     *  }
     *  DataRow dtRow = dtProduct.NewRow();
     *
     *  dtRow["SrNo"] = ViewState["SrNo"];
     *  //dtRow["ProductName"] = ddlProduct.SelectedItem.ToString();
     *  //dtRow["ProdId"] = ddlProduct.SelectedValue;
     *  dtRow["CategoryName"] = ddlCategory.SelectedItem.ToString();
     *  dtRow["CatId"] = ddlCategory.SelectedValue;
     *  dtRow["Quantity"] = txtquantity.Text.Trim();
     *  dtProduct.Rows.Add(dtRow);
     *  ViewState["Products"] = dtProduct;
     *  return dtProduct;
     * }
     *
     *
     *
     * protected void Remove_Product(object sender, EventArgs e)
     * {
     *  try
     *  {
     *      //  con.Open();
     *
     *      //GridViewRow gr = (GridViewRow)(sender as Control).Parent.Parent;
     *      //int ind = gr.RowIndex;
     *      //string pid = (gvproduct.Rows[ind].Cells[0].Text);
     *      int prodid;
     *      Button button = (sender as Button);
     *      //Get the command argument
     *      string commandArgument = button.CommandArgument;
     *
     *
     *      prodid = int.Parse(commandArgument);
     *
     *      DataTable dtProduct = new DataTable();
     *
     *      if (ViewState["Products"] == null)
     *      {
     *
     *          // [ProdId],[ProdName],[ProdBrand] ,[ProdSize]
     *
     *          dtProduct = new DataTable("Products");
     *          dtProduct.Columns.Add(new DataColumn("SrNo", typeof(int)));
     *          dtProduct.Columns.Add(new DataColumn("ProductName", typeof(string)));
     *          dtProduct.Columns.Add(new DataColumn("CategoryName", typeof(string)));
     *          dtProduct.Columns.Add(new DataColumn("Quantity", typeof(string)));
     *
     *          ViewState["Products"] = dtProduct;
     *      }
     *      else
     *      {
     *          dtProduct = (DataTable)ViewState["Products"];
     *      }
     *
     *
     *      // dtProduct = (DataTable)ViewState["Products"];
     *
     *      DataRow[] drr = dtProduct.Select("SrNo=' " + prodid + " ' ");
     *      foreach (var row in drr)
     *          row.Delete();
     *
     *      // dtProduct.Rows.RemoveAt(prodid);
     *
     *      dtProduct.AcceptChanges();
     *      Repeater1.DataSource = dtProduct;
     *      Repeater1.DataBind();
     *      //ddlProduct.SelectedIndex = 0;
     *      ddlCategory.SelectedIndex = 0;
     *      txtquantity.Text = "0";
     *      //if (Request.QueryString["id"] != null)
     *      //{
     *      //    Int64 OrderID = Convert.ToInt64(ocommon.Decrypt(Request.QueryString["id"].ToString(), true));
     *      //    string s = "delete from Ordersystem_orderproducts where oid=" + OrderID + " and pid=" + pid + "";
     *      //    SqlCommand cmd = new SqlCommand(s, con);
     *      //    int t = cmd.ExecuteNonQuery();
     *
     *
     *      //}
     *      //ScriptManager.RegisterStartupScript(this, GetType(), "alertmsg", "alert('Product Remove Successfully');", true);
     *      //con.Close();
     *
     *      ScriptManager.RegisterStartupScript(this, GetType(), "alertmsg", "alert('Product Removed Successfully');", true);
     *
     *  }
     *  catch (Exception p)
     *  { }
     *  finally
     *  {
     *      //con.Close();
     *  }
     * }
     *
     */

    protected void btnSave_Click(object sender, EventArgs e)
    {
        Int64     Result = 0, Result1 = 0, Result2 = 0;
        DataTable dtProduct = new DataTable();

        //Response.Write(hf1.Value);

        //String valuesColor = hfcolorid.Value, valuesSize = hfsizeid.Value;


        SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["cnstring"].ConnectionString);
        //id, worksheetno, employeeid, totalpairs, vshape, silai, factorysecond, isdeleted, createddate

        articleproduction objarticleproduction = new articleproduction();

        objarticleproduction.worksheetno = Convert.ToInt64(txtworksheetno.Text);
        objarticleproduction.employeeid  = Convert.ToInt64(hfemployeeid.Value);
        if (cbvshape.Checked)
        {
            objarticleproduction.vshape = Convert.ToInt64(txttotalpairs.Text);
        }
        else if (cbsilai.Checked)
        {
            objarticleproduction.silai = Convert.ToInt64(txttotalpairs.Text);
        }
        else
        {
            objarticleproduction.totalpairs = Convert.ToInt64(txttotalpairs.Text);
        }

        objarticleproduction.factorysecond = Convert.ToInt64(txtfactorysecond.Text);


        Result = (new Cls_articleproduction_b().Insert(objarticleproduction));
        if (Result > 0)
        {
            //if (ViewState["Products"] != null)
            //    dtProduct = (DataTable)ViewState["Products"];

            //id, pid, sizeid, colorid, quantity

            Label        id = new Label(); TextBox quantity = new TextBox();
            articlestock objPod = new articlestock();
            foreach (RepeaterItem item in Repeater1.Items)
            {
                if (item.ItemType == ListItemType.Item || item.ItemType == ListItemType.AlternatingItem)
                {
                    id       = (Label)item.FindControl("lblid");
                    quantity = (TextBox)item.FindControl("txtquantity");
                }
                objPod.pid      = Convert.ToInt64(txtpid.Text);
                objPod.sizeid   = Convert.ToInt64(id.Text);
                objPod.colorid  = Convert.ToInt64(txtcolorid.Text);
                objPod.quantity = Convert.ToDecimal(quantity.Text);

                Result1 = (new Cls_articlestock_b().InsertUpdate(objPod));

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

            articleloosepairs objarticle = new articleloosepairs();
            objarticle.pid         = Convert.ToInt64(txtpid.Text);
            objarticle.sizegroupid = Convert.ToInt64(txtsizegroupid.Text);
            objarticle.colorid     = Convert.ToInt64(txtcolorid.Text);
            objarticle.quantity    = Convert.ToDecimal(txtloosepair.Text);

            Result2 = (new Cls_articleloosepairs_b().InsertUpdate(objarticle));

            Response.Redirect(Page.ResolveUrl("~/manageworksheets.aspx?mode=a"));
        }
        else
        {
        }
    }