Пример #1
0
        protected void btnEditSystem_Click(object sender, EventArgs e)
        {
            int val;

            if (int.TryParse(sysID.Text, out val))
            {
                try
                {
                    connection.Open();
                    SqlCommand command = new SqlCommand("Sp_UpdateSystems", connection);
                    command.CommandType = CommandType.StoredProcedure;

                    command.Parameters.AddWithValue("@p_Name", sysName.Text.ToString());
                    command.Parameters.AddWithValue("@p_Description", sysDesc.Text.ToString());
                    command.Parameters.AddWithValue("@p_SystemID", val);
                    command.Parameters.AddWithValue("@p_SystemAddress", sysAddress.Text.ToString());
                    command.Parameters.AddWithValue("@p_SystemPhone", sysPhone.Text.ToString());
                    command.Parameters.AddWithValue("@p_SystemFax", sysFax.Text.ToString());
                    command.Parameters.AddWithValue("@p_PharmacyID", pharmacyID.Text.ToString());
                    command.ExecuteNonQuery();
                    WebMessageBoxUtil.Show("System successfully updated");
                }
                catch (Exception exp) { }
                finally
                {
                    connection.Close();
                    btnCancelSystem_Click(sender, e);
                }
            }
        }
Пример #2
0
        protected void btnDeleteSystem_Click(object sender, EventArgs e)
        {
            int val;

            if (int.TryParse(sysID.Text, out val))
            {
                try
                {
                    connection.Open();
                    SqlCommand command = new SqlCommand("Sp_DeleteSystem", connection);
                    command.CommandType = CommandType.StoredProcedure;

                    command.Parameters.AddWithValue("@p_SystemID", val);


                    command.ExecuteNonQuery();
                    WebMessageBoxUtil.Show("System successfully deleted");
                }
                catch (Exception exp) { }
                finally
                {
                    connection.Close();
                    btnCancelSystem_Click(sender, e);
                    bindValues();
                }
            }
        }
Пример #3
0
        public void Add(Vendor vendor, SqlConnection connection)
        {
            try
            {
                connection.Open();
                SqlCommand command = new SqlCommand("Sp_AddNewVendor", connection);
                command.CommandType = CommandType.StoredProcedure;
                command.Parameters.AddWithValue("@p_SupName", vendor.SupName);
                command.Parameters.AddWithValue("@p_Address", vendor.address);
                command.Parameters.AddWithValue("@p_City", vendor.city);
                command.Parameters.AddWithValue("@p_State", vendor.State);
                command.Parameters.AddWithValue("@p_Country", vendor.Country);
                command.Parameters.AddWithValue("@p_Pincode ", vendor.Pincode);
                command.Parameters.AddWithValue("@p_Phone", vendor.Phone);
                command.Parameters.AddWithValue("@p_Fax", vendor.Fax);
                command.Parameters.AddWithValue("@p_Mobile", vendor.Mobile);
                command.Parameters.AddWithValue("@p_Pager", vendor.Pager);
                command.Parameters.AddWithValue("@p_Email", vendor.Email);
                command.Parameters.AddWithValue("@p_ConPerson", vendor.ConPerson);
                command.Parameters.AddWithValue("@p_Discount", vendor.Discount);
                command.Parameters.AddWithValue("@p_Credit", vendor.Credit);
                command.Parameters.AddWithValue("@p_LineID", 1);

                command.ExecuteNonQuery();
                WebMessageBoxUtil.Show("Vendor Successfully Added ");
            }
            catch (Exception ex)
            {
            }
            finally
            {
                connection.Close();
            }
        }
Пример #4
0
        protected void btnAddSystem_Click(object sender, EventArgs e)
        {
            try
            {
                connection.Open();
                SqlCommand command = new SqlCommand("Sp_AddNewSystem", connection);
                command.CommandType = CommandType.StoredProcedure;

                command.Parameters.AddWithValue("@p_Name", sysName.Text.ToString());
                command.Parameters.AddWithValue("@p_Description", sysDesc.Text.ToString());
                command.Parameters.AddWithValue("@p_SystemRoleName", Session["SysToAdd"].ToString());
                command.Parameters.AddWithValue("@p_SystemAddress", sysAddress.Text.ToString());
                command.Parameters.AddWithValue("@p_SystemPhone", sysPhone.Text.ToString());
                command.Parameters.AddWithValue("@p_SystemFax", sysFax.Text.ToString());
                command.Parameters.AddWithValue("@p_PharmacyID", pharmacyID.Text.ToString());
                command.ExecuteNonQuery();
                WebMessageBoxUtil.Show("System successfully added");
            }
            catch (Exception exp) { }
            finally
            {
                connection.Close();
                btnCancelSystem_Click(sender, e);
            }
        }
 protected void btnDeleteProduct_Click(object sender, EventArgs e)
 {
     //Print Message First
     #region Delete Product
     try
     {
         connection.Open();
         SqlCommand command = new SqlCommand("Update tbl_ProductMaster set Status = 0 where ProductID = '" + Int32.Parse(Session["ProductID"].ToString()) + "'", connection);
         command.ExecuteNonQuery();
         WebMessageBoxUtil.Show("SuccessFully Deleted");
         SelectProduct.SelectedIndex = 0;
         BarCodeSerial.Text          = "";
         GreenRainCode.Text          = "";
         ProductName.Text            = "";
         ProductDept.SelectedIndex   = 0;
         ProductCat.SelectedIndex    = 0;
         ProductSubCat.SelectedIndex = 0;
         ProductType.SelectedIndex   = 0;
         ProdcutBrand.Text           = "";
         ProdcutDesc.Text            = "";
         ProductSale.Text            = "";
         ProductCost.Text            = "";
         ProductDiscount.Text        = "";
     }
     catch (Exception ex)
     {
     }
     finally
     {
         connection.Close();
     }
     #endregion
 }
Пример #6
0
        protected void CategoryDisplayGrid_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            try
            {
                if (e.CommandName.Equals("Add"))
                {
                    CategoryBLL categoryManager = new CategoryBLL();
                    TextBox     txtname         = (TextBox)CategoryDisplayGrid.FooterRow.FindControl("txtAddname");
                    // TextBox txtDepId = (TextBox)CategoryDisplayGrid.FooterRow.FindControl("txtAddDepID");
                    string   depName       = (CategoryDisplayGrid.FooterRow.FindControl("ddlAddDepName") as DropDownList).SelectedItem.Value;
                    Category categoryToAdd = new Category();
                    categoryToAdd.Name = txtname.Text;
                    int res;
                    if (int.TryParse(depName, out res))
                    {
                        categoryToAdd.DepartmentID = res;

                        categoryManager.Add(categoryToAdd);
                    }
                    else
                    {
                        WebMessageBoxUtil.Show("Invalid input in Department field ");
                    }
                }
                else if (e.CommandName.Equals("UpdateCategory"))
                {
                    CategoryBLL  categoryManager = new CategoryBLL();
                    Label        id      = (Label)CategoryDisplayGrid.Rows[CategoryDisplayGrid.EditIndex].FindControl("lblCat_ID");
                    TextBox      name    = (TextBox)CategoryDisplayGrid.Rows[CategoryDisplayGrid.EditIndex].FindControl("txtname");
                    DropDownList ddlDep  = (DropDownList)(CategoryDisplayGrid.Rows[CategoryDisplayGrid.EditIndex].FindControl("ddlDepName"));
                    string       depName = ddlDep.SelectedItem.Value;
                    // TextBox departmentId = (TextBox)CategoryDisplayGrid.Rows[e.RowIndex].FindControl("txtDepID");

                    int      selectedId       = int.Parse(id.Text);
                    Category categoryToUpdate = new Category();//= empid.Text;
                    categoryToUpdate.CategoryID = selectedId;
                    categoryToUpdate.Name       = name.Text;
                    int res;
                    if (int.TryParse(depName, out res))
                    {
                        categoryToUpdate.DepartmentID = int.Parse(depName);
                        categoryManager.Update(categoryToUpdate);
                    }
                    else
                    {
                        WebMessageBoxUtil.Show("Invalid input in Department field ");
                    }
                }
            }
            catch (Exception exp) { }
            finally
            {
                CategoryDisplayGrid.EditIndex = -1;
                BindGrid(false);
            }
        }
Пример #7
0
        protected void gdvDetails_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            try
            {
                if (e.CommandName.Equals("UpdateDep"))
                {
                    Label   ID  = (Label)gdvDetails.Rows[gdvDetails.EditIndex].FindControl("lblProd_Id");
                    TextBox SP  = (TextBox)gdvDetails.Rows[gdvDetails.EditIndex].Cells[0].FindControl("txtSP");
                    TextBox Exp = (TextBox)gdvDetails.Rows[gdvDetails.EditIndex].FindControl("txtEXP");
                    TextBox CP  = (TextBox)gdvDetails.Rows[gdvDetails.EditIndex].FindControl("txtCP");

                    ProductDetail objdrp = new ProductDetail();
                    objdrp.ProductDetailID = int.Parse(ID.Text);
                    DateTime resDate;
                    if (DateTime.TryParse(Exp.Text, out resDate))
                    {
                        objdrp.DateExpired = resDate;
                    }
                    else
                    {
                        WebMessageBoxUtil.Show("Invalid input in Expiry Date field ");
                        gdvDetails.EditIndex = -1;
                        //BindGrid();
                        return;
                    }
                    float res;
                    if (float.TryParse(SP.Text, out res))
                    {
                        objdrp.SalePrice = res;
                        float res2;
                        if (float.TryParse(CP.Text, out res2))
                        {
                            objdrp.CostPrice   = res2;
                            objdrp.DateUpdated = DateTime.Now;
                            ProductDetailBLL sdBLL = new ProductDetailBLL();
                            sdBLL.Update(objdrp);
                        }
                        else
                        {
                            WebMessageBoxUtil.Show("Invalid input in Cost Price field ");
                        }
                    }
                    else
                    {
                        WebMessageBoxUtil.Show("Invalid input in Sale Price field ");
                    }
                }
            }
            catch (Exception exp) { }
            finally
            {
                gdvDetails.EditIndex = -1;
                BindGrid();
            }
        }
Пример #8
0
        protected void btnLogin_Click(object sender, EventArgs e)
        {
            try
            {
                DropDownList userList = new DropDownList();
                connection.Open();
                SqlCommand command = new SqlCommand("Select * From tbl_Users INNER JOIN tbl_System ON tbl_Users.SystemID = tbl_System.SystemID " +
                                                    "INNER JOIN tbl_SystemRoles ON tbl_System.System_RoleID = tbl_SystemRoles.RoleID", connection);
                DataSet        ds = new DataSet();
                SqlDataAdapter sA = new SqlDataAdapter(command);
                sA.Fill(ds);
                userList.DataSource     = ds.Tables[0];
                userList.DataTextField  = "U_EmpID";
                userList.DataValueField = "U_Password";
                userList.DataBind();

                if (userList.Items.FindByText(UserName.Text) != null)
                {
                    string orgPass = userList.Items.FindByText(UserName.Text).Value;
                    if (orgPass.ToLower().Equals(Password.Text.ToLower()))
                    {
                        DataTable dt = new DataTable();
                        DataView  dv = new DataView();
                        dv           = ds.Tables[0].DefaultView;
                        dv.RowFilter = "U_EmpID = '" + UserName.Text + "'";
                        dt           = dv.ToTable();

                        switch (dt.Rows[0]["RoleName"].ToString())
                        {
                        case "WareHouse":
                            Session["UserSys"] = dt.Rows[0]["SystemID"].ToString();
                            Response.Redirect("WarehouseMain.aspx", false);
                            break;

                        case "Store":
                            Session["UserSys"] = dt.Rows[0]["SystemID"].ToString();
                            Response.Redirect("StoreMain.aspx", false);
                            break;
                        }
                    }
                }
                else
                {
                    WebMessageBoxUtil.Show("Invalid username or password.");
                    return;
                }
            }
            catch (Exception exp)
            {
            }
            finally
            {
                connection.Close();
            }
        }
Пример #9
0
        private void BindGrid()
        {
            DataTable dt = new DataTable();
            DataSet   ds = new DataSet();

            #region Getting Product Details
            try
            {
                int id;
                if (int.TryParse(Session["UserSys"].ToString(), out id))
                {
                    String Query = "Select tblStock_Detail.ProductID AS ProductID ,tbl_ProductMaster.Product_Name AS ProductName, tblStock_Detail.BarCode AS BarCode, tblStock_Detail.Quantity AS Qauntity, tblStock_Detail.ExpiryDate As Expiry,tbl_ProductMaster.Product_Name AS ProductName," +
                                   " tbl_ProductMaster.itemPackSize as PackageSize, tbl_ProductMaster.itemStrength as strength, tbl_ProductMaster.itemForm as dosageForm, FORMAT(tblStock_Detail.UCostPrice, 'N2') AS CostPrice, FORMAT(tblStock_Detail.USalePrice, 'N2') AS SalePrice, tbl_System.SystemName AS Location" +
                                   " From  tblStock_Detail INNER JOIN tbl_ProductMaster ON tblStock_Detail.ProductID = tbl_ProductMaster.ProductID INNER JOIN tbl_System ON tblStock_Detail.StoredAt = tbl_System.SystemID AND tblStock_Detail.StoredAt = '" + id.ToString() + "'";

                    connection.Open();
                    SqlCommand     command = new SqlCommand(Query, connection);
                    SqlDataAdapter SA      = new SqlDataAdapter(command);
                    SA.Fill(ds);
                    if (ds != null && ds.Tables[0] != null && ds.Tables[0].Rows.Count > 0)
                    {
                        StockDisplayGrid.DataSource = ds;
                        StockDisplayGrid.DataBind();
                    }
                    else
                    {
                        WebMessageBoxUtil.Show("No stock available to show");
                        NoProductMessage.Visible = true;
                        ProductCat.Enabled       = false;
                        ProductDept.Enabled      = false;
                        ProductSubCat.Enabled    = false;
                        ProductType.Enabled      = false;
                        SelectProduct.Enabled    = false;
                        btnSearch.Enabled        = false;
                        btnRefresh.Enabled       = false;
                    }
                }
            }
            catch (Exception ex)
            {
            }
            finally
            {
                connection.Close();
            }
            #endregion
        }
Пример #10
0
        protected void Button1_Click(object sender, EventArgs e)
        {
            //HaadLIST();
            string FilePath = "";

            string[] a        = new string[1];
            string   fileName = "";
            string   FullName = "";

            DataTable dt = null;
            DataSet   ds = null;

            if (HaadFileImport.FileName.Length > 0)
            {
                a = HaadFileImport.FileName.Split('.');
                //fileName = Convert.ToString(System.DateTime.Now.Ticks) + "." + a.GetValue(1).ToString();
                //FilePath = Server.MapPath(@"~\APIExcelSheet");
                FilePath = System.IO.Path.GetDirectoryName(HaadFileImport.FileName);
                // HaadFileImport.SaveAs(FilePath + @"\" + fileName);

                FullName = FilePath + @"\" + fileName;

                // Database Saved Code
                string connString = string.Format("Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Extended Properties='Excel 12.0;HDR=yes'", @"G:\HaadList.xlsx");
                string sql        = "SELECT * from [Sheet1$]";
                dt = new DataTable();



                using (OleDbConnection conn = new OleDbConnection(connString))
                {
                    conn.Open();
                    using (OleDbCommand cmd = new OleDbCommand(sql, conn))
                    {
                        using (OleDbDataReader rdr = cmd.ExecuteReader())
                        {
                            dt.Load(rdr);
                            //return dt;
                        }
                    }
                }
            }
            HaadLIST(dt);
            WebMessageBoxUtil.Show("Total Rows Read: " + dt.Rows.Count);
            //gvAPI.DataSource = dt;
            //gvAPI.DataBind();
        }
        //Sp_FillPO_Details
        public void PopulateDropDown(String Text)
        {
            #region Populating Product Name Dropdown

            try
            {
                connection.Open();

                Text = Text + "%";
                SqlCommand     command = new SqlCommand("SELECT Distinct * From tbl_ProductMaster INNER JOIN tblStock_Detail ON tbl_ProductMaster.ProductID = tblStock_Detail.ProductID Where tbl_ProductMaster.Product_Name LIKE '" + Text + "' AND tbl_ProductMaster.Status = 1", connection);
                DataSet        ds      = new DataSet();
                SqlDataAdapter sA      = new SqlDataAdapter(command);
                sA.Fill(ds);
                if (ds.Tables[0].Rows.Count.Equals(0))
                {
                    WebMessageBoxUtil.Show("There is no stock for the selected product");
                }
                if (SelectProduct.DataSource != null)
                {
                    SelectProduct.DataSource = null;
                }

                ProductSet = null;
                ProductSet = ds;
                //ds.Tables[0].Columns.Add("ProductInfo", typeof(string), "Product_Name+ ' '+itemStrength+' '+itemPackSize+' '+itemForm");

                SelectProduct.DataSource     = ds.Tables[0];
                SelectProduct.DataTextField  = "Description";
                SelectProduct.DataValueField = "ProductID";
                SelectProduct.DataBind();
                if (SelectProduct != null)
                {
                    SelectProduct.Items.Insert(0, "Select Product");
                    SelectProduct.SelectedIndex = 0;
                }
            }
            catch (Exception ex)
            {
            }
            finally
            {
                connection.Close();
            }
            #endregion
        }
Пример #12
0
        public void Delete(Category category, SqlConnection connection)
        {
            try
            {
                connection.Open();
                SqlCommand command = new SqlCommand("Sp_DeleteCategory", connection);
                command.CommandType = CommandType.StoredProcedure;
                command.Parameters.AddWithValue("@p_Id", category.CategoryID);

                command.ExecuteNonQuery();
                WebMessageBoxUtil.Show("Category Successfully Deleted ");
            }
            catch (Exception ex)
            {
            }
            finally
            {
                connection.Close();
            }
        }
Пример #13
0
        public void Delete(Vendor vendor, SqlConnection connection)
        {
            try
            {
                connection.Open();
                SqlCommand command = new SqlCommand("Sp_DeleteVendor", connection);
                command.CommandType = CommandType.StoredProcedure;
                command.Parameters.AddWithValue("@p_Supp_ID", vendor.supp_ID);

                command.ExecuteNonQuery();
                WebMessageBoxUtil.Show("Vendor Successfully Deleted ");
            }
            catch (Exception ex)
            {
            }
            finally
            {
                connection.Close();
            }
        }
Пример #14
0
        public void Add(Category category, SqlConnection connection)
        {
            try
            {
                connection.Open();
                SqlCommand command = new SqlCommand("Sp_AddNewCategory", connection);
                command.CommandType = CommandType.StoredProcedure;
                command.Parameters.AddWithValue("@p_Name", category.Name);
                command.Parameters.AddWithValue("@p_DepartmentID", category.DepartmentID);


                command.ExecuteNonQuery();
                WebMessageBoxUtil.Show("Category Successfully Added ");
            }
            catch (Exception ex)
            {
            }
            finally
            {
                connection.Close();
            }
        }
Пример #15
0
        public void Add(Department dep, SqlConnection connection)
        {
            try
            {
                connection.Open();
                SqlCommand command = new SqlCommand("Sp_AddNewDepartment", connection);
                command.CommandType = CommandType.StoredProcedure;
                command.Parameters.AddWithValue("@Name", dep.Name);
                command.Parameters.AddWithValue("@Code", dep.Code);


                command.ExecuteNonQuery();
                WebMessageBoxUtil.Show("Department Successfully Added ");
            }
            catch (Exception ex)
            {
            }
            finally
            {
                connection.Close();
            }
        }
Пример #16
0
        public void Update(SubCategory subCategory, SqlConnection connection)
        {
            try
            {
                connection.Open();
                SqlCommand command = new SqlCommand("Sp_UpdateSelectedSubCategory", connection);
                command.CommandType = CommandType.StoredProcedure;
                command.Parameters.AddWithValue("@p_Id", subCategory.SubCategoryID);
                command.Parameters.AddWithValue("@p_Name", subCategory.Name);
                command.Parameters.AddWithValue("@p_categoryName", subCategory.CategoryName);
                command.Parameters.AddWithValue("@p_DepartmentName", subCategory.DepartmentName);

                command.ExecuteNonQuery();
                WebMessageBoxUtil.Show("SubCategory Successfully Updated ");
            }
            catch (Exception ex)
            {
            }
            finally
            {
                connection.Close();
            }
        }
Пример #17
0
        protected void btnCreateProduct_Click(object sender, EventArgs e)
        {
            if (ProductType.SelectedItem.ToString() == "Medicine(HAAD)" &&
                (GreenRainCode.Text.Equals("") || GreenRainCode.Text.Equals(null)))
            {
                WebMessageBoxUtil.Show("FOR HADD MEDICINES, PLEASE ENTER THE RESPECTIVE GREENRAIN CODE");
            }
            else
            {
                if (btnCreateProduct.Text.Equals("ADD"))
                {
                    int x = 0;

                    #region Creation Product
                    string errorMessage = "";
                    try
                    {
                        connection.Open();
                        SqlCommand command = new SqlCommand("sp_InsertProduct", connection);
                        command.CommandType = CommandType.StoredProcedure;
                        command.Parameters.AddWithValue("@p_BarCodeSerial", BarCodeSerial.Text.ToString());
                        command.Parameters.AddWithValue("@p_ProductCode", GreenRainCode.Text.ToString());
                        command.Parameters.AddWithValue("@p_ProductName", ProductName.Text.ToString());
                        command.Parameters.AddWithValue("@p_Description", ProdcutDesc.Text.ToString());
                        command.Parameters.AddWithValue("@p_BrandName", ProdcutBrand.Text.ToString());
                        command.Parameters.AddWithValue("@p_ProductType", ProductType.SelectedItem.ToString());
                        if (ddlProductOrderType.SelectedIndex > 0)
                        {
                            command.Parameters.AddWithValue("@p_productOrderType", int.Parse(ddlProductOrderType.SelectedValue.ToString()));
                        }
                        else
                        {
                            command.Parameters.AddWithValue("@p_productOrderType", DBNull.Value);
                        }
                        int   res1, res4;
                        float res2, res3, res5;
                        if (int.TryParse(ProductSubCat.SelectedValue.ToString(), out res1))
                        {
                            command.Parameters.AddWithValue("@p_SubCategoryID", res1);
                        }
                        else
                        {
                            command.Parameters.AddWithValue("@p_SubCategoryID", 0);
                        }

                        if (float.TryParse(ProductCost.Text.ToString(), out res2))
                        {
                            command.Parameters.AddWithValue("@p_UnitCost", res2);
                        }
                        else
                        {
                            command.Parameters.AddWithValue("@p_UnitCost", 0);
                        }

                        if (float.TryParse(ProductSale.Text.ToString(), out res3))
                        {
                            command.Parameters.AddWithValue("@p_SP", res3);
                        }
                        else
                        {
                            command.Parameters.AddWithValue("@p_SP", 0);
                        }

                        if (int.TryParse(ProductDiscount.Text.ToString(), out res4))
                        {
                            command.Parameters.AddWithValue("@p_MaxiMumDiscount", res4);
                        }
                        else
                        {
                            command.Parameters.AddWithValue("@p_MaxiMumDiscount", 0);
                        }

                        if (float.TryParse(WholeSalePrice.Text.ToString(), out res5))
                        {
                            command.Parameters.AddWithValue("@p_AWT", res5);
                        }
                        else
                        {
                            command.Parameters.AddWithValue("@p_AWT", 0);
                        }


                        command.Parameters.AddWithValue("@p_form", ItemForm.Text.ToString());
                        command.Parameters.AddWithValue("@p_strength", ItemStrength.Text.ToString());
                        command.Parameters.AddWithValue("@p_packtype", PackType.Text.ToString());
                        command.Parameters.AddWithValue("@p_packsize", PackSize.Text.ToString());

                        command.Parameters.AddWithValue("@p_shelf", shelfNumber.Text.ToString());
                        command.Parameters.AddWithValue("@p_rack", rackNumber.Text.ToString());
                        command.Parameters.AddWithValue("@p_bin", binNumber.Text.ToString());

                        x = command.ExecuteNonQuery();
                    }
                    catch (Exception ex)
                    {
                        errorMessage = ex.Message;
                    }
                    finally
                    {
                        connection.Close();
                    }

                    if (x == 1)
                    {
                        WebMessageBoxUtil.Show("Record Inserted Successfully");
                        Session["PageMasterProduct"]      = "false";
                        BarCodeSerial.Text                = "";
                        GreenRainCode.Text                = "";
                        ProductName.Text                  = "";
                        ProdcutDesc.Text                  = "";
                        ProdcutBrand.Text                 = "";
                        ProductType.SelectedIndex         = -1;
                        ProductSubCat.SelectedIndex       = -1;
                        ProductDept.SelectedIndex         = -1;
                        ProductCat.SelectedIndex          = -1;
                        ddlProductOrderType.SelectedIndex = 0;
                        ProductCost.Text                  = "";
                        ProductSale.Text                  = "";
                        ProductDiscount.Text              = "";
                        rackNumber.Text     = "";
                        shelfNumber.Text    = "";
                        binNumber.Text      = "";
                        WholeSalePrice.Text = "";
                        ItemForm.Text       = "";
                        ItemStrength.Text   = "";
                        PackType.Text       = "";
                        PackSize.Text       = "";
                    }
                    else
                    {
                        WebMessageBoxUtil.Show(errorMessage);
                    }
                    #endregion
                }
                else if (btnCreateProduct.Text.Equals("UPDATE"))
                {
                    #region Updating Product
                    try
                    {
                        connection.Open();
                        SqlCommand command = new SqlCommand("sp_UpdateProduct", connection);
                        command.CommandType = CommandType.StoredProcedure;
                        command.Parameters.AddWithValue("@p_BarCodeSerial", BarCodeSerial.Text.ToString());
                        command.Parameters.AddWithValue("@p_ProductCode", GreenRainCode.Text.ToString());
                        command.Parameters.AddWithValue("@p_ProductName", ProductName.Text.ToString());
                        command.Parameters.AddWithValue("@p_Description", ProdcutDesc.Text.ToString());
                        command.Parameters.AddWithValue("@p_BrandName", ProdcutBrand.Text.ToString());
                        command.Parameters.AddWithValue("@p_ProductType", ProductType.SelectedItem.ToString());
                        if (ddlProductOrderType.SelectedIndex > 0)
                        {
                            command.Parameters.AddWithValue("@p_productOrderType", int.Parse(ddlProductOrderType.SelectedValue.ToString()));
                        }
                        else
                        {
                            command.Parameters.AddWithValue("@p_productOrderType", DBNull.Value);
                        }
                        int   res1, res4, res6;
                        float res2, res3, res5;


                        if (int.TryParse(Session["MS_ProductID"].ToString(), out res6))
                        {
                            command.Parameters.AddWithValue("@p_ProductID", res6);
                        }
                        else
                        {
                            command.Parameters.AddWithValue("@p_ProductID", 0);
                        }

                        if (float.TryParse(ProductCost.Text.ToString(), out res2))
                        {
                            command.Parameters.AddWithValue("@p_UnitCost", res2);
                        }
                        else
                        {
                            command.Parameters.AddWithValue("@p_UnitCost", 0);
                        }

                        if (float.TryParse(ProductSale.Text.ToString(), out res3))
                        {
                            command.Parameters.AddWithValue("@p_SP", res3);
                        }
                        else
                        {
                            command.Parameters.AddWithValue("@p_SP", 0);
                        }

                        if (int.TryParse(ProductDiscount.Text.ToString(), out res4))
                        {
                            command.Parameters.AddWithValue("@p_MaxiMumDiscount", res4);
                        }
                        else
                        {
                            command.Parameters.AddWithValue("@p_MaxiMumDiscount", 0);
                        }

                        if (float.TryParse(WholeSalePrice.Text.ToString(), out res5))
                        {
                            command.Parameters.AddWithValue("@p_AWT", res5);
                        }
                        else
                        {
                            command.Parameters.AddWithValue("@p_AWT", 0);
                        }


                        command.Parameters.AddWithValue("@p_form", ItemForm.Text.ToString());
                        command.Parameters.AddWithValue("@p_strength", ItemStrength.Text.ToString());
                        command.Parameters.AddWithValue("@p_packtype", PackType.Text.ToString());
                        command.Parameters.AddWithValue("@p_packsize", PackSize.Text.ToString());

                        command.Parameters.AddWithValue("@p_shelf", shelfNumber.Text.ToString());
                        command.Parameters.AddWithValue("@p_rack", rackNumber.Text.ToString());
                        command.Parameters.AddWithValue("@p_bin", binNumber.Text.ToString());


                        int x = command.ExecuteNonQuery();
                        if (x > 0)
                        {
                            WebMessageBoxUtil.Show("SuccessFully Updated");
                            Session["PageMasterProduct"] = "false";
                            //SelectProduct.SelectedIndex = 0;
                            BarCodeSerial.Text          = "";
                            GreenRainCode.Text          = "";
                            ProductName.Text            = "";
                            ProductDept.SelectedIndex   = -1;
                            ProductCat.SelectedIndex    = -1;
                            ProductSubCat.SelectedIndex = -1;
                            ProductType.SelectedIndex   = 0;
                            ProdcutBrand.Text           = "";
                            ProdcutDesc.Text            = "";
                            ProductSale.Text            = "";
                            ProductCost.Text            = "";
                            ProductDiscount.Text        = "";
                            WholeSalePrice.Text         = "";
                            ItemForm.Text     = "";
                            ItemStrength.Text = "";
                            PackType.Text     = "";
                            PackSize.Text     = "";
                        }
                    }
                    catch (Exception ex)
                    {
                    }
                    finally
                    {
                        connection.Close();
                    }
                    Response.Redirect("ManageProducts.aspx");
                    #endregion
                }
            }
        }
Пример #18
0
        protected void btnCreateProduct_Click(object sender, EventArgs e)
        {
            if (StockAt.SelectedIndex > 0 && ProductList.SelectedIndex > 0)
            {
                #region BarCode Generation

                DateTime dateValue = (Convert.ToDateTime(DateTextBox.Text.ToString()));

                string p1;
                long   BarCode = 0;
                String mm; //= dateValue.Month.ToString();
                if (dateValue.Month < 10)
                {
                    mm = dateValue.Month.ToString().PadLeft(2, '0');
                }
                else
                {
                    mm = dateValue.Month.ToString();
                }
                String yy = dateValue.ToString("yy", DateTimeFormatInfo.InvariantInfo);
                p1 = BarCodeSerial.Text + mm + yy;

                if (long.TryParse(p1, out BarCode))
                {
                }
                else
                {
                    //post error message
                }


                #endregion

                #region Adding Stock
                int    x            = 0;
                String errorMessage = "";
                try
                {
                    connection.Open();
                    SqlCommand command = new SqlCommand("sp_AddStock", connection);
                    command.CommandType = CommandType.StoredProcedure;
                    command.Parameters.AddWithValue("@p_ProductID", Int32.Parse(ProductList.SelectedValue.ToString()));
                    command.Parameters.AddWithValue("@p_Quantity", Decimal.Parse(Quantity.Text.ToString()));
                    command.Parameters.AddWithValue("@p_Status", "1");
                    command.Parameters.AddWithValue("@p_UserRoleID", Int32.Parse(StockAt.SelectedValue.ToString()));
                    command.Parameters.AddWithValue("@p_BarCode", BarCode);
                    command.Parameters.AddWithValue("@p_Expiry", DateTextBox.Text); // Calender Date or DateTime Picker Date
                    command.Parameters.AddWithValue("@p_Cost", Math.Round(float.Parse(ProductCost.Text.ToString()), 2));
                    command.Parameters.AddWithValue("@p_Sales", Math.Round(float.Parse(ProductSale.Text.ToString()), 2));
                    x = command.ExecuteNonQuery();
                }
                catch (Exception ex)
                {
                    errorMessage = ex.Message;
                }
                finally
                {
                    connection.Close();
                }

                if (x == 1)
                {
                    WebMessageBoxUtil.Show("Record Inserted Successfully");
                    SelectProduct.Text = "";
                    Quantity.Text      = "";
                    ProductName.Text   = "";
                    DateTextBox.Text   = "";
                    BarCodeSerial.Text = "";
                    ProductCost.Text   = "";
                    ProductSale.Text   = "";
                }
                else
                {
                    WebMessageBoxUtil.Show(errorMessage);
                }
                #endregion
            }
            else
            {
                WebMessageBoxUtil.Show("Please provide a System and the Product Name from the dropdowns");
            }
        }
        protected void StockDisplayGrid_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName.Equals("UpdateStock"))
            {
                GridViewRow gvr      = (GridViewRow)(((LinkButton)e.CommandSource).NamingContainer);
                int         RowIndex = gvr.RowIndex;
                try
                {
                    int      recQuan         = int.Parse(((TextBox)StockDisplayGrid.Rows[RowIndex].FindControl("RecQuanVal")).Text);
                    int      expQuan         = int.Parse(((TextBox)StockDisplayGrid.Rows[RowIndex].FindControl("ExpQuanVal")).Text);
                    int      defQuan         = int.Parse(((TextBox)StockDisplayGrid.Rows[RowIndex].FindControl("defQuanVal")).Text);
                    int      retQuan         = int.Parse(((TextBox)StockDisplayGrid.Rows[RowIndex].FindControl("retQuanVal")).Text);
                    int      remQuan         = int.Parse(((Label)StockDisplayGrid.Rows[RowIndex].FindControl("lblRemainQuan")).Text);
                    float    txtCP           = float.Parse(((TextBox)StockDisplayGrid.Rows[RowIndex].FindControl("retCP")).Text);
                    float    txtSP           = float.Parse(((TextBox)StockDisplayGrid.Rows[RowIndex].FindControl("retSP")).Text);
                    int      orderedQuantity = int.Parse(((Label)StockDisplayGrid.Rows[RowIndex].FindControl("lblQuantity")).Text);
                    string   barcode         = ((Label)StockDisplayGrid.Rows[RowIndex].FindControl("lblbarCode")).Text;
                    string   expDate         = ((TextBox)StockDisplayGrid.Rows[RowIndex].FindControl("txtExpDate")).Text;
                    string   status          = ((Label)StockDisplayGrid.Rows[RowIndex].FindControl("lblStatus")).Text;
                    int      bonusOrg        = int.Parse(((Label)StockDisplayGrid.Rows[RowIndex].FindControl("lblBonusOrg")).Text);
                    string   batch           = ((TextBox)StockDisplayGrid.Rows[RowIndex].FindControl("txtBatch")).Text;
                    int      bonusQuan       = 0;
                    string   bonusTxt        = ((TextBox)StockDisplayGrid.Rows[RowIndex].FindControl("txtBonus")).Text;
                    DateTime expiryDate      = new DateTime();
                    DateTime.TryParse(expDate, out expiryDate);
                    //if (!)
                    //{
                    //    //WebMessageBoxUtil.Show("Expiry Date is in incorrect Format");
                    //    //StockDisplayGrid.EditIndex = -1;
                    //    //LoadData();
                    //    //return;
                    //}
                    if (!int.TryParse(bonusTxt, out bonusQuan))
                    {
                        WebMessageBoxUtil.Show("Invalid Format for Bonus");
                        StockDisplayGrid.EditIndex = -1;
                        LoadData();
                        return;
                    }
                    if (bonusQuan == 0 && defQuan == 0 && recQuan == 0 && expQuan == 0 && retQuan == 0)
                    {
                        WebMessageBoxUtil.Show("All values cannot be 0");
                        StockDisplayGrid.EditIndex = -1;
                        LoadData();
                        return;
                    }
                    float txtDisc = 0;
                    if (!float.TryParse(((TextBox)StockDisplayGrid.Rows[RowIndex].FindControl("txtDisc")).Text, out txtDisc))
                    {
                        WebMessageBoxUtil.Show("Invalid Format for Discount");
                        StockDisplayGrid.EditIndex = -1;
                        LoadData();
                        return;
                    }
                    long newBarcode = 0;
                    if (barcode.Equals("0"))
                    {
                        if (!string.IsNullOrEmpty(expDate))
                        {
                            DateTime dateValue = (Convert.ToDateTime(expDate));

                            string p1;
                            String mm;//= dateValue.Month.ToString();
                            if (dateValue.Month < 10)
                            {
                                mm = dateValue.Month.ToString().PadLeft(2, '0');
                            }
                            else
                            {
                                mm = dateValue.Month.ToString();
                            }
                            String yy = dateValue.ToString("yy", DateTimeFormatInfo.InvariantInfo);
                            p1 = ((Label)StockDisplayGrid.Rows[RowIndex].FindControl("lblBrSerial")).Text + mm + yy;

                            if (long.TryParse(p1, out newBarcode))
                            {
                            }
                            else
                            {
                                //post error message
                            }
                        }
                    }

                    if (status.Equals("Partial"))
                    {
                        if (recQuan > remQuan)
                        {
                            WebMessageBoxUtil.Show("Your remaining quantity cannot be larger than " + remQuan);
                            StockDisplayGrid.EditIndex = -1;
                            LoadData();
                            return;
                        }
                        else
                        {
                            remQuan = remQuan - (recQuan + expQuan + defQuan);
                        }
                    }
                    else
                    {
                        remQuan = remQuan - (recQuan + expQuan + defQuan);
                    }

                    if (txtCP < 0 || txtSP < 0)
                    {
                        WebMessageBoxUtil.Show("Entered value cannot be negative");
                        StockDisplayGrid.EditIndex = -1;
                        LoadData();
                        return;
                    }

                    if (recQuan < 0 || expQuan < 0 || defQuan < 0)
                    {
                        WebMessageBoxUtil.Show("Entered value cannot be negative");
                        StockDisplayGrid.EditIndex = -1;
                        LoadData();
                        return;
                    }
                    if (orderedQuantity >= (recQuan + expQuan + defQuan + retQuan))
                    {
                        int requesteeID = int.Parse(Session["RequestDesID"].ToString());
                        connection.Open();
                        SqlCommand command = new SqlCommand("Sp_StockReceiving", connection);
                        command.CommandType = CommandType.StoredProcedure;
                        command.Parameters.AddWithValue("@p_OrderDetailID", int.Parse(((Label)StockDisplayGrid.Rows[RowIndex].FindControl("lblOrdDet_id")).Text));
                        command.Parameters.AddWithValue("@p_ReceivedQuantity", recQuan);
                        command.Parameters.AddWithValue("@p_ExpiredQuantity", expQuan);
                        command.Parameters.AddWithValue("@p_RemainingQuantity", remQuan);
                        command.Parameters.AddWithValue("@p_DefectedQuantity", defQuan);
                        command.Parameters.AddWithValue("@p_ReturnedQuantity", retQuan);
                        command.Parameters.AddWithValue("@p_SystemType", Session["RequestDesRole"].ToString());
                        command.Parameters.AddWithValue("@p_StoreID", Session["UserSys"]);

                        command.Parameters.AddWithValue("@p_ProductID", int.Parse(((Label)StockDisplayGrid.Rows[RowIndex].FindControl("lblProd_id")).Text));
                        command.Parameters.AddWithValue("@p_BarCode", newBarcode);
                        command.Parameters.AddWithValue("@p_DiscountPercentage", txtDisc);
                        command.Parameters.AddWithValue("@p_Bonus", bonusQuan);
                        command.Parameters.AddWithValue("@p_BonusTotal", bonusQuan + bonusOrg);// total bonus added
                        command.Parameters.AddWithValue("@p_BatchNumber", batch);
                        if (string.IsNullOrEmpty(expDate))
                        {
                            command.Parameters.AddWithValue("@p_Expiry", DBNull.Value);
                        }
                        else
                        {
                            command.Parameters.AddWithValue("@p_Expiry", expiryDate);
                        }
                        command.Parameters.AddWithValue("@p_Cost", txtCP);
                        command.Parameters.AddWithValue("@p_Sales", txtSP);
                        command.Parameters.AddWithValue("@p_orderMasterID", int.Parse(((Label)StockDisplayGrid.Rows[RowIndex].FindControl("lblOrdMs_id")).Text));
                        command.Parameters.AddWithValue("@p_isInternal", "TRUE");
                        command.Parameters.AddWithValue("@p_isPO", "TRUE");

                        if (int.Parse(((Label)StockDisplayGrid.Rows[RowIndex].FindControl("lblQuantity")).Text) > recQuan)
                        {
                            command.Parameters.AddWithValue("@p_comments", "Sent to Vendor");
                        }
                        else
                        {
                            command.Parameters.AddWithValue("@p_comments", "Completed");
                        }
                        command.ExecuteNonQuery();
                        WebMessageBoxUtil.Show("Stock Successfully Added");
                    }
                    else
                    {
                        WebMessageBoxUtil.Show("The entered value is larger than the requested value");
                        StockDisplayGrid.EditIndex = -1;
                        //LoadData();
                        return;
                    }
                }
                catch (Exception ex)
                {
                }
                finally
                {
                    connection.Close();
                    StockDisplayGrid.EditIndex = -1;
                    LoadData();
                }
            }
        }
Пример #20
0
        protected void StockDisplayGrid_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName.Equals("UpdateStock"))
            {
                GridViewRow gvr      = (GridViewRow)(((LinkButton)e.CommandSource).NamingContainer);
                int         RowIndex = gvr.RowIndex;
                try
                {
                    int      sentQuan        = int.Parse(((Label)StockDisplayGrid.Rows[RowIndex].FindControl("lblSenQuan")).Text);
                    int      recQuan         = int.Parse(((TextBox)StockDisplayGrid.Rows[RowIndex].FindControl("RecQuanVal")).Text);
                    int      expQuan         = int.Parse(((TextBox)StockDisplayGrid.Rows[RowIndex].FindControl("ExpQuanVal")).Text);
                    int      defQuan         = int.Parse(((TextBox)StockDisplayGrid.Rows[RowIndex].FindControl("defQuanVal")).Text);
                    int      retQuan         = int.Parse(((TextBox)StockDisplayGrid.Rows[RowIndex].FindControl("retQuanVal")).Text);
                    int      expQuanOrg      = int.Parse(((Label)StockDisplayGrid.Rows[RowIndex].FindControl("lblExpQuanOrg")).Text);
                    int      defQuanOrg      = int.Parse(((Label)StockDisplayGrid.Rows[RowIndex].FindControl("lblDefQuanOrg")).Text);
                    int      retQuanOrg      = int.Parse(((Label)StockDisplayGrid.Rows[RowIndex].FindControl("lblretQuanOrg")).Text);
                    int      remQuan         = int.Parse(((Label)StockDisplayGrid.Rows[RowIndex].FindControl("lblRemainQuan")).Text);
                    string   expDate         = ((TextBox)StockDisplayGrid.Rows[RowIndex].FindControl("txtExpDate")).Text;
                    string   status          = ((Label)StockDisplayGrid.Rows[RowIndex].FindControl("lblStatus")).Text;
                    int      orderedQuantity = int.Parse(((Label)StockDisplayGrid.Rows[RowIndex].FindControl("lblQuantity")).Text);
                    string   batch           = ((TextBox)StockDisplayGrid.Rows[RowIndex].FindControl("txtBatch")).Text;
                    DateTime expiryDate;
                    DateTime.TryParse(expDate, out expiryDate);
                    //if()
                    //{
                    //WebMessageBoxUtil.Show("Expiry Date is in incorrect Format");
                    //StockDisplayGrid.EditIndex = -1;
                    //LoadData();
                    //return;
                    //}
                    if (recQuan < 0 || expQuan < 0 || defQuan < 0)
                    {
                        WebMessageBoxUtil.Show("Entered value cannot be negative");
                        StockDisplayGrid.EditIndex = -1;
                        LoadData();
                        return;
                    }
                    if (recQuan > sentQuan)
                    {
                        WebMessageBoxUtil.Show("Received value cannot be larger than sent quantity");
                        StockDisplayGrid.EditIndex = -1;
                        LoadData();
                        return;
                    }
                    if (sentQuan > (recQuan + expQuan + defQuan + retQuan))
                    {
                        WebMessageBoxUtil.Show("Mismatch in received and accepted quantity. Kindly correctly fill expired,defected or returned quantities");
                        StockDisplayGrid.EditIndex = -1;
                        LoadData();
                        return;
                    }
                    if (status.Equals("Partial"))
                    {
                        if (recQuan > remQuan)
                        {
                            WebMessageBoxUtil.Show("Your remaining quantity cannot be larger than " + remQuan);
                            StockDisplayGrid.EditIndex = -1;
                            LoadData();
                            return;
                        }
                        else
                        {
                            int val = 0;
                            if (retQuan != retQuanOrg)
                            {
                                val += retQuan;
                            }
                            if (expQuan != expQuanOrg)
                            {
                                val += expQuan;
                            }
                            if (defQuan != defQuanOrg)
                            {
                                val += defQuan;
                            }
                            remQuan = remQuan - (val + recQuan);
                        }
                    }
                    else
                    {
                        remQuan = remQuan - (recQuan + expQuan + expQuan);
                    }
                    if (orderedQuantity >= (recQuan + expQuan + defQuan + retQuan))
                    {
                        if (retQuan > 0)
                        {
                            if (status.Equals("Partial"))
                            {
                                int val = 0;
                                if (retQuan != retQuanOrg)
                                {
                                    UpdateStock(int.Parse(((Label)StockDisplayGrid.Rows[RowIndex].FindControl("lblOrdDet_id")).Text), retQuan, expiryDate);
                                }
                            }
                            else
                            {
                                //update returned quantity
                                UpdateStock(int.Parse(((Label)StockDisplayGrid.Rows[RowIndex].FindControl("lblOrdDet_id")).Text), retQuan, expiryDate);
                            }
                        }
                        connection.Open();
                        SqlCommand command = new SqlCommand("Sp_StockReceiving", connection);
                        command.CommandType = CommandType.StoredProcedure;
                        command.Parameters.AddWithValue("@p_OrderDetailID", int.Parse(((Label)StockDisplayGrid.Rows[RowIndex].FindControl("lblOrdDet_id")).Text));
                        command.Parameters.AddWithValue("@p_ReceivedQuantity", recQuan);
                        command.Parameters.AddWithValue("@p_ExpiredQuantity", expQuan);
                        command.Parameters.AddWithValue("@p_RemainingQuantity", remQuan);
                        command.Parameters.AddWithValue("@p_DefectedQuantity", defQuan);
                        command.Parameters.AddWithValue("@p_ReturnedQuantity", retQuan);
                        command.Parameters.AddWithValue("@p_SystemType", Session["RequestDesRole"].ToString());
                        command.Parameters.AddWithValue("@p_StoreID", Session["UserSys"]);

                        command.Parameters.AddWithValue("@p_ProductID", int.Parse(((Label)StockDisplayGrid.Rows[RowIndex].FindControl("lblProd_id")).Text));
                        command.Parameters.AddWithValue("@p_BarCode", ((Label)StockDisplayGrid.Rows[RowIndex].FindControl("lblbarCode")).Text);
                        command.Parameters.AddWithValue("@p_Expiry", expiryDate);
                        command.Parameters.AddWithValue("@p_DiscountPercentage", 0);
                        command.Parameters.AddWithValue("@p_Bonus", 0);
                        command.Parameters.AddWithValue("@p_BonusTotal", 0);
                        command.Parameters.AddWithValue("@p_BatchNumber", batch);
                        command.Parameters.AddWithValue("@p_Cost", float.Parse(((Label)StockDisplayGrid.Rows[RowIndex].FindControl("lblCP")).Text));
                        command.Parameters.AddWithValue("@p_Sales", float.Parse(((Label)StockDisplayGrid.Rows[RowIndex].FindControl("lblSP")).Text));
                        command.Parameters.AddWithValue("@p_orderMasterID", int.Parse(((Label)StockDisplayGrid.Rows[RowIndex].FindControl("lblOrdMs_id")).Text));
                        command.Parameters.AddWithValue("@p_isInternal", "TRUE");
                        command.Parameters.AddWithValue("@p_isPO", "FALSE");
                        if (int.Parse(((Label)StockDisplayGrid.Rows[RowIndex].FindControl("lblQuantity")).Text) > recQuan)
                        {
                            if (Session["RequestDesRole"].ToString().ToLower().Equals("warehouse"))
                            {
                                command.Parameters.AddWithValue("@p_comments", "Sent to warehouse");
                            }
                            else
                            {
                                command.Parameters.AddWithValue("@p_comments", "Sent to store");
                            }
                        }
                        else
                        {
                            command.Parameters.AddWithValue("@p_comments", "Completed");
                        }
                        command.ExecuteNonQuery();
                        WebMessageBoxUtil.Show("Stock Successfully Added");
                    }
                    else
                    {
                        WebMessageBoxUtil.Show("The entered value is larger than the requested value");
                        StockDisplayGrid.EditIndex = -1;
                        //LoadData();
                        return;
                    }
                }
                catch (Exception ex)
                {
                }
                finally
                {
                    connection.Close();
                    StockDisplayGrid.EditIndex = -1;
                    LoadData();
                }
            }
        }
        protected void btnAccept_Click(object sender, EventArgs e)
        {
            if (ProductSet.Equals(null))
            {
                WebMessageBoxUtil.Show("Plese generate Sales by providing Dates, in order to generate requests");
            }
            else
            {
                for (int i = 0; i < ProductSet.Tables[0].Rows.Count; i++)
                {
                    if (i == 0)
                    {
                        #region Creating Order
                        int    pRequestFrom = 0;
                        int    pRequestTo   = 0;
                        String OrderMode    = "Warehouse";
                        int    OrderType    = 2;
                        String Invoice      = "";
                        String Vendor       = "False";


                        try
                        {
                            connection.Open();
                            SqlCommand command = new SqlCommand("sp_CreateOrder", connection);
                            command.CommandType = CommandType.StoredProcedure;

                            if (int.TryParse(ProductSet.Tables[0].Rows[i]["TOSALES"].ToString(), out pRequestTo))
                            {
                                command.Parameters.AddWithValue("@p_RequestTO", pRequestTo);
                            }
                            if (int.TryParse(ProductSet.Tables[0].Rows[i]["FROMSALES"].ToString(), out pRequestFrom))
                            {
                                command.Parameters.AddWithValue("@p_RequestFrom", pRequestFrom);
                            }

                            command.Parameters.AddWithValue("@p_OrderType", OrderType);
                            command.Parameters.AddWithValue("@p_Invoice", Invoice);
                            command.Parameters.AddWithValue("@p_OrderMode", OrderMode);
                            command.Parameters.AddWithValue("@p_Vendor", Vendor);
                            command.Parameters.AddWithValue("@p_orderStatus", "Initiated");

                            DataTable      dt = new DataTable();
                            SqlDataAdapter dA = new SqlDataAdapter(command);
                            dA.Fill(dt);
                            if (dt.Rows.Count != 0)
                            {
                                Session["OrderNumber"] = dt.Rows[0][0].ToString();
                            }
                        }
                        catch (Exception ex)
                        {
                        }
                        finally
                        {
                            connection.Close();
                        }
                        #endregion
                    }

                    #region Linking to Order Detail table

                    try
                    {
                        connection.Open();
                        SqlCommand command = new SqlCommand("sp_InserOrderDetail_ByStore", connection);
                        command.CommandType = CommandType.StoredProcedure;

                        int OrderNumber, ProductNumber, Quantity = 0;

                        if (int.TryParse(Session["OrderNumber"].ToString(), out OrderNumber))
                        {
                            command.Parameters.AddWithValue("@p_OrderID", OrderNumber);
                        }
                        if (int.TryParse(ProductSet.Tables[0].Rows[i]["ProductID"].ToString(), out ProductNumber))
                        {
                            command.Parameters.AddWithValue("@p_ProductID", ProductNumber);
                        }
                        if (int.TryParse(ProductSet.Tables[0].Rows[i]["SaleQuantity"].ToString(), out Quantity))
                        {
                            command.Parameters.AddWithValue("@p_OrderQuantity", Quantity);
                        }

                        command.Parameters.AddWithValue("@p_status", "Initiated");
                        command.Parameters.AddWithValue("@p_comments", "Generated to Warehouse");

                        command.ExecuteNonQuery();
                    }
                    catch (Exception ex)
                    {
                    }
                    finally
                    {
                        connection.Close();
                    }
                    #endregion
                }

                WebMessageBoxUtil.Show("Auto Request of following items has been generated to warehouse");
                Response.Redirect("StoreRequestsMain.aspx");
            }
        }
        public void AddEditMasterProduct(bool add)
        {
            try
            {
                ProductMaster obj = new ProductMaster();

                obj.ProductName        = txtProductName.Text;
                obj.ProductCode        = txtProdCode.Text;
                obj.Manufacturer       = txtBrndName.Text;
                obj.Status             = "1";
                obj.ProductDescription = txtDescription.Text;
                obj.GenericName        = txtGName.Text;
                obj.MeasureQuantity    = txtMeasQty.Text;
                obj.MeasureType        = txtMeasType.Text;
                obj.ProductOrgID       = txtProdOrgID.Text;
                obj.ProductType        = txtProdType.Text;
                float res1, res2;
                int   res3, res4;

                if (float.TryParse(txtCP.Text.ToString(), out res1))
                {
                    obj.CostPrice = res1;
                }
                else
                {
                    WebMessageBoxUtil.Show("Invalid input of Cost Price");
                    return;
                }

                if (float.TryParse(txtSP.Text.ToString(), out res2))
                {
                    obj.SalePrice = res2;
                }
                else
                {
                    WebMessageBoxUtil.Show("Invalid input of Sale Price");
                    return;
                }
                if (int.TryParse(TxtDisc.Text.ToString(), out res3))
                {
                    obj.MaxDiscount = res3;
                }
                else
                {
                    WebMessageBoxUtil.Show("Invalid input of Discount");
                    return;
                }


                if (int.TryParse(txtQUnit.Text.ToString(), out res4))
                {
                    obj.QuanityUnit = res4;
                }
                else
                {
                    WebMessageBoxUtil.Show("Invalid input of Quantity Unit");
                    return;
                }

                obj.SubCategoryID = Convert.ToInt32(drpcategory.SelectedValue);

                obj.ProductCode = txtProdCode.Text;
                int thd;
                if (int.TryParse(txtThreshold.Text, out thd))
                {
                    obj.ThreshHold = thd;
                }
                else
                {
                    WebMessageBoxUtil.Show("Invalid input of threshold");
                    return;
                }
                obj.LastUpdatedDate = DateTime.Now;
                ProductMasterBLL objupd = new ProductMasterBLL();
                if (add)
                {
                    obj.DateCreated = DateTime.Now;
                    objupd.Add(obj);
                }
                else
                {
                    obj.ProductID = int.Parse(txtProductID.Text);
                    objupd.Update(obj);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        protected void btnCreateProduct_Click(object sender, EventArgs e)
        {
            if (btnCreateProduct.Text.Equals("EDIT"))
            {
                #region Editing Product(s)
                btnCreateProduct.Text   = "UPDATE";
                BarCodeSerial.Enabled   = false;
                GreenRainCode.Enabled   = true;
                ProductName.Enabled     = true;
                ProdcutDesc.Enabled     = true;
                ProdcutBrand.Enabled    = true;
                ProductType.Enabled     = true;
                ProductDept.Enabled     = true;
                ProductCat.Enabled      = true;
                ProductSubCat.Enabled   = true;
                ProductCost.Enabled     = true;
                ProductSale.Enabled     = true;
                ProductDiscount.Enabled = true;
                #endregion
            }
            else if (btnCreateProduct.Text.Equals("UPDATE"))
            {
                #region Updating Product
                try
                {
                    connection.Open();
                    SqlCommand command = new SqlCommand("sp_UpdateProduct", connection);
                    command.CommandType = CommandType.StoredProcedure;
                    int   res1, res2, res5;
                    float res3, res4;
                    if (int.TryParse(Session["ProductID"].ToString(), out res1))
                    {
                        command.Parameters.AddWithValue("@p_ProductID", res1);
                    }
                    else
                    {
                        WebMessageBoxUtil.Show("invalid product Id");
                        return;
                    }

                    if (int.TryParse(Session["SubCatID"].ToString(), out res2))
                    {
                        command.Parameters.AddWithValue("@p_SubCategoryID", res2);
                    }//
                    else
                    {
                        WebMessageBoxUtil.Show("invalid sub category Id");
                        return;
                    }

                    if (float.TryParse(ProductCost.Text.ToString(), out res3))
                    {
                        command.Parameters.AddWithValue("@p_UnitCost", res3);
                    }
                    else
                    {
                        WebMessageBoxUtil.Show("invalid unit cost");
                        return;
                    }

                    if (float.TryParse(ProductSale.Text.ToString(), out res3))
                    {
                        command.Parameters.AddWithValue("@p_SP", res3);
                    }
                    else
                    {
                        WebMessageBoxUtil.Show("invalid sales price");
                        return;
                    }

                    if (int.TryParse(ProductDiscount.Text.ToString(), out res5))
                    {
                        command.Parameters.AddWithValue("@p_MaxiMumDiscount", res5);
                    }
                    else
                    {
                        WebMessageBoxUtil.Show("invalid discount");
                        return;
                    }
                    command.Parameters.AddWithValue("@p_BarCodeSerial", BarCodeSerial.Text.ToString());
                    command.Parameters.AddWithValue("@p_ProductCode", GreenRainCode.Text.ToString());
                    command.Parameters.AddWithValue("@p_ProductName", ProductName.Text.ToString());
                    command.Parameters.AddWithValue("@p_Description", ProdcutDesc.Text.ToString());
                    command.Parameters.AddWithValue("@p_BrandName", ProdcutBrand.Text.ToString());
                    command.Parameters.AddWithValue("@p_ProductType", ProductType.SelectedItem.ToString());


                    command.ExecuteNonQuery();
                    WebMessageBoxUtil.Show("SuccessFully Updated");
                    SelectProduct.SelectedIndex = 0;
                    BarCodeSerial.Text          = "";
                    GreenRainCode.Text          = "";
                    ProductName.Text            = "";
                    ProductDept.SelectedIndex   = -1;
                    ProductCat.SelectedIndex    = -1;
                    ProductSubCat.SelectedIndex = -1;
                    ProductType.SelectedIndex   = 0;
                    ProdcutBrand.Text           = "";
                    ProdcutDesc.Text            = "";
                    ProductSale.Text            = "";
                    ProductCost.Text            = "";
                    ProductDiscount.Text        = "";
                }
                catch (Exception ex)
                {
                }
                finally
                {
                    connection.Close();
                }

                BarCodeSerial.Enabled   = false;
                GreenRainCode.Enabled   = false;
                ProductName.Enabled     = false;
                ProdcutDesc.Enabled     = false;
                ProdcutBrand.Enabled    = false;
                ProductType.Enabled     = false;
                ProductDept.Enabled     = false;
                ProductCat.Enabled      = false;
                ProductSubCat.Enabled   = false;
                ProductCost.Enabled     = false;
                ProductSale.Enabled     = false;
                ProductDiscount.Enabled = false;
                btnCreateProduct.Text   = "EDIT";
                #endregion
            }
        }
Пример #24
0
        protected void StockDisplayGrid_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            try
            {
                if (e.CommandName.Equals("Delete"))
                {
                    try
                    {
                        //Label Barcode = (Label)StockDisplayGrid.Rows[StockDisplayGrid.EditIndex].FindControl("BarCode");
                        //DataView dv = ProductSet.Tables[0].DefaultView;
                        //dv.RowFilter = "BarCode = '" + long.Parse(Barcode.Text.ToString()) + "'";
                        //DataTable dt = dv.ToTable();
                        //int ProductID = Int32.Parse(dt.Rows[0]["ProductID"].ToString());

                        // Label _StockID = (Label)StockDisplayGrid.Rows[StockDisplayGrid.EditIndex].FindControl("lblStockID");
                        //int stockID = int.Parse(_StockID.Text);
                        int    stockID = int.Parse(e.CommandArgument.ToString());
                        String Query   = "Delete From tblStock_Detail Where StockID = '" + stockID + "'";
                        connection.Open();
                        SqlCommand command = new SqlCommand(Query, connection);
                        command.ExecuteNonQuery();
                        WebMessageBoxUtil.Show("Stock Successfully Deleted ");
                    }
                    catch (Exception exp)
                    {
                    }
                    finally
                    {
                        BindGrid();
                        // StockDisplayGrid.EditIndex = -1;
                    }
                }
                if (e.CommandName.Equals("UpdateStock"))
                {
                    Label    Barcode       = (Label)StockDisplayGrid.Rows[StockDisplayGrid.EditIndex].FindControl("BarCode");
                    TextBox  Quantity      = (TextBox)StockDisplayGrid.Rows[StockDisplayGrid.EditIndex].FindControl("txtQuantity");
                    TextBox  UnitCostPrice = (TextBox)StockDisplayGrid.Rows[StockDisplayGrid.EditIndex].FindControl("txtUnitCostPrice");
                    TextBox  UnitSalePrice = (TextBox)StockDisplayGrid.Rows[StockDisplayGrid.EditIndex].FindControl("txtUnitSalePrice");
                    Label    expiry        = (Label)StockDisplayGrid.Rows[StockDisplayGrid.EditIndex].FindControl("lblExpiry");
                    Label    _StockID      = (Label)StockDisplayGrid.Rows[StockDisplayGrid.EditIndex].FindControl("lblStockID");
                    int      stockID       = int.Parse(_StockID.Text);
                    DataView dv            = ProductSet.Tables[0].DefaultView;
                    dv.RowFilter = "Product_Id_Org = '" + long.Parse(Barcode.Text.ToString()) + "'";
                    DataTable dt = dv.ToTable();
                    // int ProductID = Int32.Parse(dt.Rows[0]["ProductID"].ToString());

                    if (Barcode.Text.Equals(""))
                    {
                        #region Barcode Generation

                        string BarCodeSerial = dt.Rows[0]["BarCode"].ToString();

                        DateTime dateValue = (Convert.ToDateTime(expiry.Text.ToString()));


                        long   BarCodeNumber = 0;
                        String mm            = dateValue.Month.ToString();
                        String yy            = dateValue.ToString("yy", DateTimeFormatInfo.InvariantInfo);
                        string p1            = BarCodeSerial + mm + yy;

                        if (long.TryParse(p1, out BarCodeNumber))
                        {
                        }
                        else
                        {
                            //post error message
                        }
                        #endregion

                        String Query = "Update tblStock_Detail Set BarCode= '" + BarCodeNumber + "', Quantity = '" + Decimal.Parse(Quantity.Text.ToString()) + "', UCostPrice = '" + Math.Round(Decimal.Parse(UnitCostPrice.Text.ToString()), 2) + "', USalePrice = '" + Math.Round(Decimal.Parse(UnitSalePrice.Text.ToString()), 2) + "' Where StockID = '" + stockID + "'";
                        connection.Open();
                        SqlCommand command = new SqlCommand(Query, connection);
                        command.ExecuteNonQuery();
                    }
                    else
                    {
                        String Query = "Update tblStock_Detail Set Quantity = '" + Decimal.Parse(Quantity.Text.ToString()) + "', UCostPrice = '" + Math.Round(Decimal.Parse(UnitCostPrice.Text.ToString()), 2) + "', USalePrice = '" + Math.Round(Decimal.Parse(UnitSalePrice.Text.ToString()), 2) + "' Where StockID = '" + stockID + "'";
                        connection.Open();
                        SqlCommand command = new SqlCommand(Query, connection);
                        command.ExecuteNonQuery();
                    }
                    WebMessageBoxUtil.Show("Stock Successfully Updated ");
                }
            }
            catch (Exception exp)
            {
            }
            finally
            {
                BindGrid();
                StockDisplayGrid.EditIndex = -1;
            }
        }
Пример #25
0
        protected void StockDisplayGrid_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            try
            {
                if (e.CommandName.Equals("AddRec"))
                {
                    #region Fetching values
                    int recQuan, expQuan, defQuan, bonusQuan, retQuan, bonusOrg, remQuan, orderedQuantity;
                    recQuan = expQuan = defQuan = bonusQuan = retQuan = bonusOrg = remQuan = orderedQuantity = 0;

                    float txtDisc, txtCP, txtSP;
                    txtDisc = txtCP = txtSP = 0;

                    string lblRec      = ((TextBox)StockDisplayGrid.FooterRow.FindControl("txtAddRecQuan")).Text;
                    string lblExp      = ((TextBox)StockDisplayGrid.FooterRow.FindControl("txtAddExpQuan")).Text;
                    string lblDef      = ((TextBox)StockDisplayGrid.FooterRow.FindControl("txtAddDefQuan")).Text;
                    string lblRet      = ((TextBox)StockDisplayGrid.FooterRow.FindControl("txtAddRetQuan")).Text;
                    string lblBonus    = ((TextBox)StockDisplayGrid.FooterRow.FindControl("txtAddBonus")).Text;
                    string lblCP       = ((TextBox)StockDisplayGrid.FooterRow.FindControl("txtAddCP")).Text;
                    string lblSP       = ((TextBox)StockDisplayGrid.FooterRow.FindControl("txtAddSP")).Text;
                    string lblexpiry   = ((TextBox)StockDisplayGrid.FooterRow.FindControl("txtAddExpDate")).Text;
                    string lblDiscount = ((TextBox)StockDisplayGrid.FooterRow.FindControl("txtAddDisPer")).Text;
                    string lblBatch    = ((TextBox)StockDisplayGrid.FooterRow.FindControl("txtAddBatch")).Text;

                    // string lblBarcode = ((Label)StockDisplayGrid.FooterRow.FindControl("lblbarCode")).Text;
                    int orderDetID = int.Parse(lblOrderDetID.Text);


                    #endregion

                    #region Parsing fields

                    DateTime expiryDate = new DateTime();
                    DateTime.TryParse(lblexpiry, out expiryDate);
                    bonusOrg        = int.Parse(bonusQuanOrg.Text);
                    remQuan         = int.Parse(RemQuantity.Text);
                    orderedQuantity = int.Parse(OrdQuantity.Text);
                    int.TryParse(lblRec, out recQuan);
                    int.TryParse(lblBonus, out bonusQuan);
                    int.TryParse(lblExp, out expQuan);
                    int.TryParse(lblDef, out defQuan);
                    int.TryParse(lblRet, out retQuan);

                    float.TryParse(lblCP, out txtCP);
                    float.TryParse(lblSP, out txtSP);
                    float.TryParse(lblDiscount, out txtDisc);
                    #endregion

                    #region Input checks
                    if (bonusQuan == 0 && defQuan == 0 && recQuan == 0 && expQuan == 0 && retQuan == 0)
                    {
                        WebMessageBoxUtil.Show("All values cannot be 0");
                        StockDisplayGrid.EditIndex = -1;
                        BindGrid();
                        return;
                    }

                    if (recQuan > remQuan || defQuan > remQuan || expQuan > remQuan || retQuan > remQuan)
                    {
                        WebMessageBoxUtil.Show("Entered Quantity cannout exceed remaining quantity " + remQuan);
                        StockDisplayGrid.EditIndex = -1;
                        BindGrid();
                        return;
                    }
                    else
                    {
                        remQuan = remQuan - (recQuan + expQuan + defQuan + retQuan);
                    }

                    if (txtCP < 0 || txtSP < 0)
                    {
                        WebMessageBoxUtil.Show("Entered value cannot be negative");
                        StockDisplayGrid.EditIndex = -1;
                        BindGrid();
                        return;
                    }

                    if (recQuan < 0 || expQuan < 0 || defQuan < 0 || retQuan < 0)
                    {
                        WebMessageBoxUtil.Show("Entered value cannot be negative");
                        StockDisplayGrid.EditIndex = -1;
                        BindGrid();
                        return;
                    }
                    #endregion

                    #region barcode generation
                    long newBarcode = 0;

                    if (!string.IsNullOrEmpty(lblexpiry))
                    {
                        DateTime dateValue = (Convert.ToDateTime(lblexpiry));

                        string p1;
                        String mm;    //= dateValue.Month.ToString();
                        if (dateValue.Month < 10)
                        {
                            mm = dateValue.Month.ToString().PadLeft(2, '0');
                        }
                        else
                        {
                            mm = dateValue.Month.ToString();
                        }
                        String yy = dateValue.ToString("yy", DateTimeFormatInfo.InvariantInfo);
                        p1 = lblBarSerial.Text + mm + yy;

                        if (long.TryParse(p1, out newBarcode))
                        {
                        }
                        else
                        {
                            //post error message
                        }
                    }

                    #endregion

                    if (orderedQuantity >= (recQuan + expQuan + defQuan + retQuan))
                    {
                        #region Query execution

                        connection.Open();
                        SqlCommand command = new SqlCommand("Sp_StockReceiving", connection);
                        command.CommandType = CommandType.StoredProcedure;
                        command.Parameters.AddWithValue("@p_OrderDetailID", orderDetID);
                        command.Parameters.AddWithValue("@p_ReceivedQuantity", recQuan);
                        command.Parameters.AddWithValue("@p_ExpiredQuantity", expQuan);
                        command.Parameters.AddWithValue("@p_DefectedQuantity", defQuan);
                        command.Parameters.AddWithValue("@p_ReturnedQuantity", retQuan);

                        command.Parameters.AddWithValue("@p_BarCode", newBarcode);
                        command.Parameters.AddWithValue("@p_DiscountPercentage", txtDisc);
                        command.Parameters.AddWithValue("@p_Bonus", bonusQuan);
                        if (!String.IsNullOrEmpty(lblBatch))
                        {
                            command.Parameters.AddWithValue("@p_BatchNumber", lblBatch);
                        }
                        else
                        {
                            command.Parameters.AddWithValue("@p_BatchNumber", DBNull.Value);
                        }
                        if (string.IsNullOrEmpty(lblexpiry))
                        {
                            command.Parameters.AddWithValue("@p_Expiry", DBNull.Value);
                        }
                        else
                        {
                            command.Parameters.AddWithValue("@p_Expiry", expiryDate);
                        }
                        command.Parameters.AddWithValue("@p_Cost", txtCP);
                        command.Parameters.AddWithValue("@p_Sales", txtSP);

                        command.Parameters.AddWithValue("@p_BonusTotal", bonusQuan + bonusOrg);    // total bonus added
                        command.Parameters.AddWithValue("@p_RemainingQuantity", remQuan);
                        command.Parameters.AddWithValue("@p_SystemType", Session["RequestDesRole"].ToString());
                        command.Parameters.AddWithValue("@p_StoreID", Session["UserSys"].ToString());
                        command.Parameters.AddWithValue("@p_orderMasterID", int.Parse(lblOMISD.Text));
                        command.Parameters.AddWithValue("@p_isInternal", "TRUE");
                        command.Parameters.AddWithValue("@p_isPO", lblPO.Text);
                        command.Parameters.AddWithValue("@p_ProductID", int.Parse(lblProdID.Text));

                        command.Parameters.AddWithValue("@p_expiryOriginal", DBNull.Value);

                        if (int.Parse(OrdQuantity.Text) > recQuan)
                        {
                            command.Parameters.AddWithValue("@p_comments", "Sent to Vendor");
                        }
                        else
                        {
                            command.Parameters.AddWithValue("@p_comments", "Completed");
                        }
                        command.ExecuteNonQuery();
                        #endregion
                    }
                    WebMessageBoxUtil.Show("Stock Successfully Added");
                    //RemQuantity.Text = remQuan.ToString();
                }
                else if (e.CommandName.Equals("UpdateStock"))
                {
                    GridViewRow gvr      = (GridViewRow)(((LinkButton)e.CommandSource).NamingContainer);
                    int         RowIndex = gvr.RowIndex;
                    #region Fetching values
                    int recQuan, expQuan, defQuan, bonusQuan, retQuan, bonusOrg, remQuan, bonusTotal, recQuanOrg, expQuanOrg, defQuanOrg, retQuanOrg, orderedQuantity;
                    recQuan = expQuan = defQuan = bonusQuan = retQuan = bonusOrg = remQuan = bonusTotal = recQuanOrg = expQuanOrg = defQuanOrg = retQuanOrg = orderedQuantity = 0;

                    float txtDisc, txtCP, txtSP;
                    txtDisc = txtCP = txtSP = 0;

                    string lblRec      = ((TextBox)StockDisplayGrid.Rows[RowIndex].FindControl("RecQuanVal")).Text;
                    string lblExp      = ((TextBox)StockDisplayGrid.Rows[RowIndex].FindControl("ExpQuanVal")).Text;
                    string lblDef      = ((TextBox)StockDisplayGrid.Rows[RowIndex].FindControl("defQuanVal")).Text;
                    string lblRet      = ((TextBox)StockDisplayGrid.Rows[RowIndex].FindControl("retQuanVal")).Text;
                    string lblBonus    = ((TextBox)StockDisplayGrid.Rows[RowIndex].FindControl("txtBonus")).Text;
                    string lblCP       = ((TextBox)StockDisplayGrid.Rows[RowIndex].FindControl("retCP")).Text;
                    string lblSP       = ((TextBox)StockDisplayGrid.Rows[RowIndex].FindControl("retSP")).Text;
                    string lblexpiry   = ((TextBox)StockDisplayGrid.Rows[RowIndex].FindControl("txtExpDate")).Text;
                    string lblDiscount = ((TextBox)StockDisplayGrid.Rows[RowIndex].FindControl("txtDisc")).Text;
                    string lblBatch    = ((TextBox)StockDisplayGrid.Rows[RowIndex].FindControl("txtBatch")).Text;

                    int    entryID    = int.Parse(((Label)StockDisplayGrid.Rows[RowIndex].FindControl("lblentryID")).Text);
                    string lblBarcode = ((Label)StockDisplayGrid.Rows[RowIndex].FindControl("lblbarCode")).Text;
                    int    orderDetID = int.Parse(((Label)StockDisplayGrid.Rows[RowIndex].FindControl("lblOrdDet_id")).Text);
                    string lblExpOrg  = ((Label)StockDisplayGrid.Rows[RowIndex].FindControl("lblExpOrg")).Text;

                    #endregion

                    #region Parsing fields

                    DateTime expiryOrg = new DateTime();
                    if (!string.IsNullOrEmpty(lblExpOrg))
                    {
                        DateTime.TryParse(lblExpOrg, out expiryOrg);
                    }
                    DateTime expiryDate = new DateTime();
                    DateTime.TryParse(lblexpiry, out expiryDate);
                    bonusTotal      = int.Parse(bonusQuanOrg.Text);
                    remQuan         = int.Parse(RemQuantity.Text);
                    orderedQuantity = int.Parse(OrdQuantity.Text);
                    bonusOrg        = int.Parse(((Label)StockDisplayGrid.Rows[RowIndex].FindControl("lblBonusOrg")).Text);
                    recQuanOrg      = int.Parse(((Label)StockDisplayGrid.Rows[RowIndex].FindControl("lblRecQuanOrg")).Text);
                    retQuanOrg      = int.Parse(((Label)StockDisplayGrid.Rows[RowIndex].FindControl("lblRetQuanOrg")).Text);
                    expQuanOrg      = int.Parse(((Label)StockDisplayGrid.Rows[RowIndex].FindControl("lblExpQuanOrg")).Text);
                    defQuanOrg      = int.Parse(((Label)StockDisplayGrid.Rows[RowIndex].FindControl("lblDefQuanOrg")).Text);

                    if (int.TryParse(lblRec, out recQuan))
                    {
                        if (int.TryParse(lblExp, out expQuan))
                        {
                            if (int.TryParse(lblDef, out defQuan))
                            {
                                if (int.TryParse(lblRet, out retQuan))
                                {
                                    if (float.TryParse(lblCP, out txtCP))
                                    {
                                        if (float.TryParse(lblSP, out txtSP))
                                        {
                                            if (float.TryParse(lblDiscount, out txtDisc))
                                            {
                                                if (int.TryParse(lblBonus, out bonusQuan))
                                                {
                                                }
                                                else
                                                {
                                                }
                                            }
                                            else
                                            {
                                            }
                                        }
                                        else
                                        {
                                        }
                                    }
                                    else
                                    {
                                    }
                                }
                                else
                                {
                                }
                            }
                            else
                            {
                            }
                        }
                        else
                        {
                        }
                    }
                    else
                    {
                    }
                    #endregion

                    #region Input checks
                    if (bonusQuan == 0 && defQuan == 0 && recQuan == 0 && expQuan == 0 && retQuan == 0)
                    {
                        WebMessageBoxUtil.Show("All values cannot be 0");
                        StockDisplayGrid.EditIndex = -1;
                        BindGrid();
                        return;
                    }

                    if (recQuan > remQuan || defQuan > remQuan || expQuan > remQuan || retQuan > remQuan)
                    {
                        if (recQuan == recQuanOrg)
                        {
                        }
                        else if (defQuan == defQuanOrg)
                        {
                        }
                        else if (expQuan == expQuanOrg)
                        {
                        }
                        else if (retQuan == retQuanOrg)
                        {
                        }
                        else
                        {
                            WebMessageBoxUtil.Show("Entered Quantity cannout exceed remaining quantity " + remQuan);
                            StockDisplayGrid.EditIndex = -1;
                            BindGrid();
                            return;
                        }
                    }
                    else
                    {
                        int val = 0;
                        if (recQuan != recQuanOrg)
                        {
                            if (recQuan < recQuanOrg)
                            {
                                val -= (recQuanOrg - recQuan);
                            }
                            else
                            {
                                val += (recQuan - recQuanOrg);
                            }
                        }
                        if (expQuan != expQuanOrg)
                        {
                            if (expQuan < expQuanOrg)
                            {
                                val -= (expQuanOrg - expQuan);
                            }
                            else
                            {
                                val += (expQuan - expQuanOrg);
                            }
                        }
                        if (defQuan != defQuanOrg)
                        {
                            if (defQuan < defQuanOrg)
                            {
                                val -= (defQuanOrg - defQuan);
                            }
                            else
                            {
                                val += (defQuan - defQuanOrg);
                            }
                        }
                        if (retQuan != retQuanOrg)
                        {
                            if (retQuan < retQuanOrg)
                            {
                                val -= (retQuanOrg - retQuan);
                            }
                            else
                            {
                                val += (retQuan - retQuanOrg);
                            }
                        }
                        remQuan = remQuan - (val);
                    }

                    if (txtCP < 0 || txtSP < 0)
                    {
                        WebMessageBoxUtil.Show("Entered value cannot be negative");
                        StockDisplayGrid.EditIndex = -1;
                        BindGrid();
                        return;
                    }

                    if (recQuan < 0 || expQuan < 0 || defQuan < 0 || retQuan < 0)
                    {
                        WebMessageBoxUtil.Show("Entered value cannot be negative");
                        StockDisplayGrid.EditIndex = -1;
                        BindGrid();
                        return;
                    }
                    #endregion

                    #region barcode generation
                    long newBarcode = 0;
                    if (lblBarcode.Equals("0") || (!expiryDate.Equals(expiryOrg)))
                    {
                        if (!string.IsNullOrEmpty(lblexpiry))
                        {
                            DateTime dateValue = (Convert.ToDateTime(lblexpiry));

                            string p1;
                            String mm;//= dateValue.Month.ToString();
                            if (dateValue.Month < 10)
                            {
                                mm = dateValue.Month.ToString().PadLeft(2, '0');
                            }
                            else
                            {
                                mm = dateValue.Month.ToString();
                            }
                            String yy = dateValue.ToString("yy", DateTimeFormatInfo.InvariantInfo);
                            p1 = lblBarSerial.Text + mm + yy;

                            if (long.TryParse(p1, out newBarcode))
                            {
                            }
                            else
                            {
                                //post error message
                            }
                        }
                    }
                    #endregion

                    if (orderedQuantity >= (recQuan + expQuan + defQuan + retQuan))
                    {
                        #region Query execution
                        connection.Open();
                        SqlCommand command = new SqlCommand("Sp_StockReceiving", connection);
                        command.CommandType = CommandType.StoredProcedure;
                        command.Parameters.AddWithValue("@p_OrderDetailID", orderDetID);
                        command.Parameters.AddWithValue("@p_ReceivedQuantity", recQuan);
                        command.Parameters.AddWithValue("@p_ReceivedQuantityOrg", recQuanOrg);
                        command.Parameters.AddWithValue("@p_ExpiredQuantity", expQuan);
                        command.Parameters.AddWithValue("@p_ExpiredQuantityOrg", expQuanOrg);
                        command.Parameters.AddWithValue("@p_DefectedQuantity", defQuan);
                        command.Parameters.AddWithValue("@p_DefectedQuantityOrg", defQuanOrg);
                        command.Parameters.AddWithValue("@p_ReturnedQuantity", retQuan);
                        command.Parameters.AddWithValue("@p_ReturnedQuantityOrg", retQuanOrg);
                        command.Parameters.AddWithValue("@p_ProductID", int.Parse(lblProdID.Text));
                        command.Parameters.AddWithValue("@p_BarCode", newBarcode);
                        command.Parameters.AddWithValue("@p_DiscountPercentage", txtDisc);
                        command.Parameters.AddWithValue("@p_Bonus", bonusQuan);
                        command.Parameters.AddWithValue("@p_bonusOriginal", bonusOrg);
                        if (!String.IsNullOrEmpty(lblBatch))
                        {
                            command.Parameters.AddWithValue("@p_BatchNumber", lblBatch);
                        }
                        else
                        {
                            command.Parameters.AddWithValue("@p_BatchNumber", DBNull.Value);
                        }
                        if (string.IsNullOrEmpty(lblexpiry))
                        {
                            command.Parameters.AddWithValue("@p_Expiry", DBNull.Value);
                        }
                        else
                        {
                            command.Parameters.AddWithValue("@p_Expiry", expiryDate);
                        }
                        command.Parameters.AddWithValue("@p_Cost", txtCP);
                        command.Parameters.AddWithValue("@p_Sales", txtSP);

                        command.Parameters.AddWithValue("@p_BonusTotal", bonusQuan + (bonusTotal - bonusOrg));// total bonus added
                        command.Parameters.AddWithValue("@p_RemainingQuantity", remQuan);
                        command.Parameters.AddWithValue("@p_SystemType", Session["RequestDesRole"].ToString());
                        command.Parameters.AddWithValue("@p_StoreID", Session["UserSys"].ToString());
                        command.Parameters.AddWithValue("@p_orderMasterID", int.Parse(lblOMISD.Text));
                        command.Parameters.AddWithValue("@p_isInternal", "TRUE");
                        command.Parameters.AddWithValue("@p_isPO", lblPO.Text);
                        command.Parameters.AddWithValue("@p_entryID", entryID);

                        if (!string.IsNullOrWhiteSpace(lblExpOrg))
                        {
                            command.Parameters.AddWithValue("@p_expiryOriginal", expiryOrg);
                        }
                        else
                        {
                            command.Parameters.AddWithValue("@p_expiryOriginal", DBNull.Value);
                        }

                        if (int.Parse(OrdQuantity.Text) > recQuan)
                        {
                            command.Parameters.AddWithValue("@p_comments", "Sent to Vendor");
                        }
                        else
                        {
                            command.Parameters.AddWithValue("@p_comments", "Completed");
                        }
                        command.ExecuteNonQuery();
                        #endregion
                    }
                    WebMessageBoxUtil.Show("Stock Successfully Updated");
                    // RemQuantity.Text = remQuan.ToString();
                    // bonusQuanOrg.Text = (bonusQuan + (bonusTotal - bonusOrg)).ToString();
                    // retQuantity.Text = retQuan.ToString();
                }
            }
            catch (Exception exp) { }
            finally
            {
                if (connection.State == ConnectionState.Open)
                {
                    connection.Close();
                }
                StockDisplayGrid.EditIndex = -1;
                BindLabels(false);
                BindGrid();
            }
        }
        protected void StockDisplayGrid_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            try
            {
                if (e.CommandName.Equals("UpdateStock"))
                {
                    #region Updating SendQuantity in tblOrderDetails
                    Label   OderDetailID  = (Label)StockDisplayGrid.Rows[StockDisplayGrid.EditIndex].FindControl("OrderDetailNo");
                    string  status        = ((Label)StockDisplayGrid.Rows[StockDisplayGrid.EditIndex].FindControl("lblStatus")).Text;
                    TextBox Quantity      = (TextBox)StockDisplayGrid.Rows[StockDisplayGrid.EditIndex].FindControl("txtQuantity");
                    int     remQuan       = int.Parse(((Label)StockDisplayGrid.Rows[StockDisplayGrid.EditIndex].FindControl("lblRemainQuan")).Text);
                    int     RequestNumber = 0;
                    if (int.TryParse(OderDetailID.Text.ToString(), out RequestNumber))
                    {
                        try
                        {
                            int SndQuantity = 0;
                            if (int.TryParse(Quantity.Text.ToString(), out SndQuantity))
                            {
                                if (SndQuantity > remQuan)
                                {
                                    WebMessageBoxUtil.Show("Your remaining quantity cannot be larger than " + remQuan);
                                    StockDisplayGrid.EditIndex = -1;
                                    LoadData();
                                    return;
                                }
                                connection.Open();
                                SqlCommand command = new SqlCommand("sp_UpdateSendQuantity", connection);
                                command.CommandType = CommandType.StoredProcedure;
                                command.Parameters.AddWithValue("@p_OrderDetailID", RequestNumber);
                                command.Parameters.AddWithValue("@p_SndQuantity", SndQuantity);
                                if (status.Equals("Partial"))
                                {
                                    command.Parameters.AddWithValue("@p_Status", "Partial");
                                }
                                else
                                {
                                    command.Parameters.AddWithValue("@p_Status", "Pending");
                                }
                                command.ExecuteNonQuery();
                            }
                        }
                        catch (Exception ex)
                        {
                        }
                        finally
                        {
                            connection.Close();
                        }
                    }
                    else
                    {
                        //send to Main Request Screen of warehouse
                    }
                    #endregion

                    btnDecline.Enabled = false;
                }
            }
            catch (Exception ex)
            {
            }
            finally
            {
                StockDisplayGrid.EditIndex = -1;
                LoadData();
            }
        }
Пример #27
0
        protected void StockDisplayGrid_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            try
            {
                int    recQuan, expQuan, defQuan, bonusQuan, retQuan;
                int    entryID         = int.Parse(((Label)StockDisplayGrid.Rows[e.RowIndex].FindControl("lblentryID")).Text);
                int    orderDetID      = int.Parse(((Label)StockDisplayGrid.Rows[e.RowIndex].FindControl("lblOrdDet_id")).Text);
                string lblExpOrg       = ((Label)StockDisplayGrid.Rows[e.RowIndex].FindControl("lblExpOrg")).Text;
                string lblRec          = ((Label)StockDisplayGrid.Rows[e.RowIndex].FindControl("lblRecQuan")).Text;
                string lblExp          = ((Label)StockDisplayGrid.Rows[e.RowIndex].FindControl("lblExpQuan")).Text;
                string lblDef          = ((Label)StockDisplayGrid.Rows[e.RowIndex].FindControl("lblDefQuan")).Text;
                string lblRet          = ((Label)StockDisplayGrid.Rows[e.RowIndex].FindControl("lblRetQuan")).Text;
                string lblBonus        = ((Label)StockDisplayGrid.Rows[e.RowIndex].FindControl("lblBonus")).Text;
                int    orderedQuantity = int.Parse(OrdQuantity.Text);



                #region Parsing fields

                DateTime expiryOrg = new DateTime();
                if (!string.IsNullOrEmpty(lblExpOrg))
                {
                    DateTime.TryParse(lblExpOrg, out expiryOrg);
                }

                int.TryParse(lblRec, out recQuan);
                int.TryParse(lblBonus, out bonusQuan);
                int.TryParse(lblExp, out expQuan);
                int.TryParse(lblDef, out defQuan);
                int.TryParse(lblRet, out retQuan);
                int remainingValue = int.Parse(RemQuantity.Text);

                #endregion

                #region Query Execution


                connection.Open();
                SqlCommand command = new SqlCommand("Sp_DeleteOrderDetail_ReceiveEntry", connection);
                command.CommandType = CommandType.StoredProcedure;

                command.Parameters.AddWithValue("@p_entryID", entryID);
                command.Parameters.AddWithValue("@p_OrderDetailID", orderDetID);

                command.Parameters.AddWithValue("@p_ProductID", int.Parse(lblProdID.Text));
                command.Parameters.AddWithValue("@p_StoreID", Session["UserSys"].ToString());
                command.Parameters.AddWithValue("@p_ReceivedQuantity", recQuan);
                command.Parameters.AddWithValue("@p_orderMasterID", int.Parse(lblOMISD.Text));
                if (!string.IsNullOrWhiteSpace(lblExpOrg))
                {
                    command.Parameters.AddWithValue("@p_expiryOriginal", expiryOrg);
                }
                else
                {
                    command.Parameters.AddWithValue("@p_expiryOriginal", DBNull.Value);
                }
                command.Parameters.AddWithValue("@p_ExpiredQuantity", expQuan);
                command.Parameters.AddWithValue("@p_DefectedQuantity", defQuan);
                command.Parameters.AddWithValue("@p_ReturnedQuantity", retQuan);
                command.Parameters.AddWithValue("@p_Bonus", bonusQuan);
                if ((remainingValue + (recQuan + retQuan + defQuan + expQuan)) == orderedQuantity)
                {
                    command.Parameters.AddWithValue("@p_status", "Pending");
                }
                else if ((remainingValue + (recQuan + retQuan + defQuan + expQuan)) < orderedQuantity)
                {
                    command.Parameters.AddWithValue("@p_status", "Partial");
                }

                command.ExecuteNonQuery();
                WebMessageBoxUtil.Show("Entry Successfully Deleted ");
                #endregion
            }
            catch (Exception exp) {}
            finally{
                if (connection.State == ConnectionState.Open)
                {
                    connection.Close();
                }
                BindLabels(false);
                BindGrid();
            }
        }