Esempio n. 1
0
    protected void btnInsert_Click(object sender, EventArgs e)
    {
        tProductsTableAdapter sda = new tProductsTableAdapter();
        DstProducts           ds  = new DstProducts();
        string ImgExtention       = "";

        if (FileUpload1.HasFile)
        {
            ImgExtention = System.IO.Path.GetExtension(FileUpload1.FileName);
        }
        string FileNme = "";

        if (ImgExtention != "")
        {
            FileNme = GetNameForFile();
        }
        if (dg.SelectedIndex > -1 && txtName.Text.Trim() != "")
        {
            bool Success = sda.FillByCode(ds.tProducts, int.Parse(ddlGroups.SelectedValue.ToString())) > 0;
            if (Success)
            {
                ds.tProducts.Rows[0][ds.tProducts.fCodeGroupColumn] = ddlGroups.SelectedValue.ToString();
                ds.tProducts.Rows[0][ds.tProducts.fNameColumn]      = txtName.Text.Trim();
                ds.tProducts.Rows[0][ds.tProducts.fDescColumn]      = txtDesc.Text.Trim();
                ds.tProducts.Rows[0][ds.tProducts.fPriceColumn]     = txtPrice.Text.Trim();
                if (FileUpload1.HasFile)
                {
                    ImageUpload(FileNme, ImgExtention);
                    ds.tProducts.Rows[0][ds.tProducts.fImageNameColumn] = "IMG/" + FileNme.Trim() + ImgExtention;
                }
                sda.Update(ds.tProducts);
                Label6.Text = "ویرایش محصول با موفقیت در سیستم ذخیره گردید";
            }
        }
        else
        {
            DataRow MyRow = ds.tProducts.NewRow();

            MyRow[ds.tProducts.fCodeGroupColumn] = ddlGroups.SelectedValue.ToString();
            MyRow[ds.tProducts.fNameColumn]      = txtName.Text.Trim();
            MyRow[ds.tProducts.fPriceColumn]     = txtPrice.Text.Trim();
            MyRow[ds.tProducts.fDescColumn]      = txtDesc.Text.Trim();
            if (FileUpload1.HasFile)
            {
                ImageUpload(FileNme, ImgExtention);
                MyRow[ds.tProducts.fImageNameColumn] = "IMG/" + FileNme.Trim() + ImgExtention;
            }
            ds.tProducts.Rows.Add(MyRow);
            sda.Update(ds.tProducts);

            Label6.Text = "اطلاعات محصول جدید با موفقیت در سیستم ذخیره گردید";
        }
        ClearTextBox();
        //BindGrid();
        dg.SelectedIndex = -1;
    }
Esempio n. 2
0
    private void BindGrid()
    {
        tProductsTableAdapter sda = new tProductsTableAdapter();
        DstProducts           ds  = new DstProducts();
        string ss = ddlGroups.SelectedValue.ToString();

        sda.FillByCodeGroup(ds.tProducts, int.Parse(ddlGroups.SelectedValue.ToString()));
        dg.DataSource = ds.tProducts;
        dg.DataBind();
    }