Friday, 4 October 2013

ALl Layer Code

Data Access Layer
------------------------

    #region Brand
    public static void InsertBrand(Brand cls)
    {
        // con = new SqlConnection(Connection.MyConnection());
        con = new SqlConnection("Server=USER-PC;Database=Emart4u;uid=sa;pwd=linku");
        cmd = new SqlCommand("InsertBrand", con);
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.Parameters.AddWithValue("@Brand_Name", cls.Brand_Name);    
        cmd.Parameters.AddWithValue("@Brand_Description", cls.Brand_Description);
        con.Open();
        cmd.ExecuteNonQuery();
        con.Close();
    }
    public static DataTable getAllBrand()
    {
        con = new SqlConnection("Server=USER-PC;Database=Emart4u;uid=sa;pwd=linku");
        //con = new SqlConnection(Connection.MyConnection());
        cmd = new SqlCommand("SelectBrand", con);
        cmd.CommandType = CommandType.StoredProcedure;
        da = new SqlDataAdapter();
        da.SelectCommand = cmd;
        dt = new DataTable();
        da.Fill(dt);
        return dt;
    }
    public static void UpdateBrand(Brand c)
    {
        con = new SqlConnection("Server=USER-PC;Database=Emart4u;uid=sa;pwd=linku");
        //con = new SqlConnection(Connection.MyConnection());
        cmd = new SqlCommand("UpdateBrand", con);
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.Parameters.AddWithValue("@Brand_ID", c.Brand_ID);
        cmd.Parameters.AddWithValue("@Brand_Name", c.Brand_Name);
        cmd.Parameters.AddWithValue("@Brand_Description", c.Brand_Description);
     
        con.Open();
        cmd.ExecuteNonQuery();
        con.Close();
    }
    public static void DeleteBrand(int cid)
    {
        con = new SqlConnection("Server=USER-PC;Database=Emart4u;uid=sa;pwd=linku");
        cmd = new SqlCommand("DeleteBrand", con);
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.Parameters.AddWithValue("@Brand_ID", cid);
        con.Open();
        cmd.ExecuteNonQuery();
        con.Close();
    }
    #endregion
-------------------
Business Layer
-------------------------
  #region Brand
    public static void InsertBrand(Brand cls)
    {
        LessonPlanDataAccess.InsertBrand(cls);
    }
    public static List<Brand> getAllBrand()
    {
        List<Brand> BrandList = new List<Brand>();
        DataTable dt = LessonPlanDataAccess.getAllBrand();
        foreach (DataRow row in dt.Rows)
        {
            Brand c = new Brand();
            c.Brand_ID = int.Parse(row["Brand_ID"].ToString());
            c.Brand_Name = row["Brand_Name"].ToString();
            c.Brand_Description = row["Brand_Description"].ToString();
         
            BrandList.Add(c);
        }
        return BrandList;
    }
    public static void UpdateBrand(Brand c)
    {
        LessonPlanDataAccess.UpdateBrand(c);
    }
    public static void DeleteBrand(int cid)
    {
        LessonPlanDataAccess.DeleteBrand(cid);
    }
    #endregion
------------------------------------------
object layer
---------------------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

/// <summary>
/// Summary description for Brand
/// </summary>
///
[Serializable]
public class Brand
{
public Brand()
{
//
// TODO: Add constructor logic here
//
}

    public int Brand_ID
    {
        get;
        set;
    }
    public string Brand_Name
    {
        get;
        set;
    }
    public string Brand_Description
    {
        get;
        set;
    }
}-----------------------------------------
Design
----------------
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Brand.aspx.cs" Inherits="Projects_Brand" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
<%@ Register Src="~/UserControl/U_Message.ascx" TagName="Message" TagPrefix="Mes"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
   
     <style type="text/css">
        .EmptyMessage
        {
            font-family: Arial;
            color:Red;
            font-size:16px;
            font-weight:bold;
        }
          .TabStyle
    {
        height:460px;
        overflow:inherit;
    }
    </style>
</head>
<body>
   <form id="form1" runat="server">
    <div class="TabStyle">
        <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>
        <asp:TabContainer ID="TabContainerBrand" runat="server"  Style="height: auto; width: auto">
            <asp:TabPanel ID="TabPanel1" runat="server">
                <HeaderTemplate>
                    <asp:LinkButton ID="LinkButton1" runat="server" onclick="LinkButton1_Click" >Display</asp:LinkButton>
                </HeaderTemplate>
                <ContentTemplate>
                    <asp:Panel ID="Panel1" runat="server">
                        <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
                            DataKeyNames="Brand_ID" onrowcommand="GridView1_RowCommand"
                            onrowediting="GridView1_RowEditing" >
                        <Columns>
                       
                           <asp:TemplateField HeaderText="BrandName">
                            <ItemTemplate>
                     <asp:LinkButton ID="ImgBtnEdit" runat="server" CausesValidation="false" ImageUrl="~/Images/edit.png"
                      CommandName="Edit" CommandArgument='<%# Eval("Brand_ID") %>' Text='<%# Eval("Brand_Name") %>'/></ItemTemplate>
                     </asp:TemplateField>
            <asp:BoundField HeaderText="Description" DataField="Brand_Description">        
           </asp:BoundField>
                        </Columns>
                        </asp:GridView>
                    </asp:Panel>
                </ContentTemplate>
            </asp:TabPanel>
            <asp:TabPanel ID="Tabpanel2" runat="server">
                <HeaderTemplate>
                    <asp:LinkButton ID="LinkButton2" runat="server" onclick="LinkButton2_Click">Entry</asp:LinkButton>
                </HeaderTemplate>
                <ContentTemplate>
                    <asp:Panel ID="Panel2" runat="server">
                        <table class="style1">
                            <tr>
                                <td colspan="2">
                                    Brand
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    &nbsp;
                                </td>
                                <td>
                                    &nbsp;
                                </td>
                            </tr>
                            <tr>
                                <td style="text-align: right">
                                    <asp:Label ID="Label1" runat="server" Text="Brand Name :"></asp:Label>
                                </td>
                                <td>
                                    <asp:TextBox ID="TxtBrand" runat="server" Height="24px" Width="221px"></asp:TextBox>
                                    <span class="EmptyMessage">
                                    <asp:RequiredFieldValidator ID="req1" runat="server" ErrorMessage="Enter Brand Name"
                                    ControlToValidate="TxtBrand" SetFocusOnError="true" ValidationGroup="1">*</asp:RequiredFieldValidator>
                                    </span>
                                </td>
                            </tr>
                            <tr>
                                <td style="text-align: right" width="40%">
                                    <asp:Label ID="Label2" runat="server" Text="Brand Description :"></asp:Label>
                                </td>
                                <td width="60%">
                                       <asp:TextBox ID="TxtBrandDescription" runat="server" Height="24px" Width="221px"></asp:TextBox>
                                </td>
                            </tr>
               
                            <tr>
                                <td>
                                    &nbsp;
                                </td>
                                <td>
                                    <asp:Button ID="BtnSave" runat="server" Text="Save" ValidationGroup="1" onclick="BtnSave_Click" />
                                    <asp:Button ID="BtnCancel" runat="server" Text="Cancel"
                                        onclick="BtnCancel_Click" />
                                </td
                            </tr>
                        </table>
                    </asp:Panel>
                </ContentTemplate>
            </asp:TabPanel>
        </asp:TabContainer>
        <Mes:Message ID="MessageID" runat="server" />
        <asp:ValidationSummary ID="val1" runat="server" ShowMessageBox="true" ShowSummary="false" ValidationGroup="1" />
    </div>
    </form>
</body>
</html>
 -------------------------------------------
C# Code
------------------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Projects_Brand : System.Web.UI.Page
{
    #region Events
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            fillgrid();
        }
    }
    protected void BtnSave_Click(object sender, EventArgs e)
    {
        if (BtnSave.Text == "Save")
        {
            if (TxtBrand.Text != "")
            {
                if (CheckDuplicate(TxtBrand.Text) == false)
                {
                    Save();
                    fillgrid();
                }
                else
                {
                    Message("Data Alredy Exists !");
                }
            }

        }
        else
        {
            if (CheckDuplicateForEdit(TxtBrand.Text) == false)
            {
                update();
                fillgrid();
            }
            else
            {
                Message("Data Alredy Exists !");
            }
        }
    }
    protected void LinkButton2_Click(object sender, EventArgs e)
    {
        Reset();
    }
    protected void LinkButton1_Click(object sender, EventArgs e)
    {
        fillgrid();
    }
    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "Edit")
        {
            int catID = int.Parse(e.CommandArgument.ToString());
            Session["PCID"] = catID;
            Brand c = new Brand();
            var catlist = from p in LessonPlanManagement.getAllBrand()
                          where p.Brand_ID == catID
                          select p;
            if (catlist.ToList().Count > 0)
            {
                TabContainerBrand.ActiveTabIndex = 1;
                Tabpanel2.Visible = true;
                TxtBrand.Text = catlist.ToList()[0].Brand_Name.ToString();              
                TxtBrandDescription.Text = catlist.ToList()[0].Brand_Description.ToString();
                BtnSave.Text = "Update";
                BtnCancel.Text = "Delete";
            }
        }
    }
    protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
    {
        e.Cancel = true;
    }
    protected void BtnCancel_Click(object sender, EventArgs e)
    {
        if (BtnCancel.Text == "Cancel")
        {
            Reset();
        }
        else
        {
            Delete();
        }
    }
    #endregion
 
    #region Methods
    private void Save()
    {
        Brand InsertBrand = new Brand();
        if (Session["PCID"] != null)
        {
            if (TxtBrand.Text.Length > 0)
            {
                update();
                Reset();
            }
            else
            {
                Message("Data Already Exists !");
            }
        }
        else
        {
            if (TxtBrand.Text.Length > 0)
            {
                if (CheckDuplicate(TxtBrand.Text.Trim()) == false)
                {
                    InsertBrand.Brand_Name = TxtBrand.Text;
                    //InsertCategory.Parent_Category_ID = int.Parse(DdlParentCategory.SelectedValue.ToString());
                    InsertBrand.Brand_Description = TxtBrandDescription.Text;
                    LessonPlanManagement.InsertBrand(InsertBrand);
                    Message("Data Inserted Successfully !");
                    Reset();
                }
                else
                {
                    Message("Data Already Exists !");
                }
                TxtBrand.Focus();
            }
        }
    }
    private void update()
    {
        if (Session["PCID"].ToString() != null)
        {
            Brand updateBrand = new Brand();
            updateBrand.Brand_ID = int.Parse(Session["PCID"].ToString());
            updateBrand.Brand_Name = TxtBrand.Text.Trim();          
            updateBrand.Brand_Description = TxtBrandDescription.Text.Trim();
            LessonPlanManagement.UpdateBrand(updateBrand);
            Message("Data Updated Successfully !");
            fillgrid();
        }
    }

    private void Delete()
    {
        LessonPlanManagement.DeleteBrand(int.Parse(Session["PCID"].ToString()));
        Message("Data Deleted Successfully !");
        Reset();
        Session["PCID"] = null;
        fillgrid();
    }

    private bool CheckDuplicate(string BrandName)
    {
        bool ReturnValue = false;
        List<Brand> CategoryList = new List<Brand>();
        CategoryList = LessonPlanManagement.getAllBrand();
        var lnqProject = from bus in CategoryList
                         where bus.Brand_Name.ToLower() == BrandName.ToLower()
                         select bus;
        if (lnqProject.Count() > 0)
        {
            ReturnValue = true;
        }
        return ReturnValue;
    }
    private bool CheckDuplicateForEdit(string CategoryName)
    {
        bool ReturnValue = false;
        List<Brand> BrandList = new List<Brand>();
        BrandList = LessonPlanManagement.getAllBrand();
        var lnqProject = from bus in BrandList
                         where bus.Brand_Name.ToLower() == CategoryName.ToLower() && bus.Brand_ID != int.Parse(Session["PCID"].ToString())
                         select bus;
        if (lnqProject.Count() > 0)
        {
            ReturnValue = true;
        }
        return ReturnValue;
    }

    void Message(string msg)
    {
        UserControl_Message uc = (UserControl_Message)this.Page.FindControl("MessageID");
        if (uc != null)
        {
            Label lb = (Label)uc.FindControl("LblModalMessage");
            lb.Text = msg;
            uc.Visible = true;
            AjaxControlToolkit.ModalPopupExtender modal = (AjaxControlToolkit.ModalPopupExtender)uc.FindControl("modalMessage");
            modal.Show();
        }
    }
    private void Reset()
    {
        TxtBrand.Text = "";
        TxtBrandDescription.Text = "";
       
    }
    public void fillgrid()
    {
        Brand cat = new Brand();
        var lnqcatDetails = from c in LessonPlanManagement.getAllBrand()
                            select c;
        if (lnqcatDetails.ToList().Count > 0)
        {
            GridView1.DataSource = lnqcatDetails.ToList();
            GridView1.DataBind();
        }
        else
        {
            GridView1.DataSource = null;
            GridView1.DataBind();
        }
    }
 
    #endregion
}
-------------------------------------------
Create Procedure [dbo].[InsertBrand]
(
@Brand_Name varchar(50),

@Brand_Description varchar(150)
)
AS
BEGIN
Insert into Brand (Brand_Name,Brand_Description)
Values
(@Brand_Name,@Brand_Description)
END
---------------------
Create Procedure [dbo].[UpdateBrand]
(
@Brand_ID int,
@Brand_Name varchar(50),

@Brand_Description varchar(100)
)
as begin
update Brand Set
Brand_Name=@Brand_Name,Brand_Description=@Brand_Description
where Brand_ID=@Brand_ID
end
-----------------------
ALTER PROCEDURE [dbo].[DeleteBrand]
(
@Brand_ID int
)
as
begin

Delete from Brand where Brand_ID=@Brand_ID

end

------------------

ALTER PROCEDURE [dbo].[SelectBrand]
as

begin

Select   Brand_ID,Brand_Name,Brand_Description from Brand

end
--------------

Thursday, 23 May 2013

Image Insert into database using FileUpload control in ASP.NET And retrived


 if (FileUploadLogo.HasFile == true)
                    {
                        //getting length of uploaded file
                        int length = FileUploadLogo.PostedFile.ContentLength;
                        //create a byte array to store the binary image data
                        byte[] imgbyte = new byte[length];
                        //store the currently selected file in memeory
                        HttpPostedFile img = FileUploadLogo.PostedFile;
                        //set the binary data
                        img.InputStream.Read(imgbyte, 0, length);
                        string imagename = FileUploadLogo.FileName;
                        newBrand.BrandLogo = imgbyte;
                        FileUploadLogo.SaveAs(Server.MapPath("~/images/AMS/Inventory/Brand/" + FileUploadLogo.FileName));
                        string FileName = Path.GetFileName(FileUploadLogo.FileName);
                        newBrand.Logo_Name = FileName;
               }

                                                            Retrived

 var brand =( from bra in ERPManagement.GetInstance.GetAllBrand()
                            where bra.Brand_ID == BrandID
                            select bra).ToList();
                TxtBrand.Text = brand[0].Brand_Name;
                TxtDescription.Text = brand[0].Brand_Description;
                ImgLogo.ImageUrl = "~/images/AMS/Inventory/Brand/" + brand[0].Logo_Name;
                ImgLogo.DataBind();
                BrandID = 0;

Wednesday, 22 May 2013

Auto complete Extender in a textbox in window Application

        private void StoreRoomBM_Load(object sender, EventArgs e)
        {
            autoItem();
        }
//Create a method Which name is Auto Item  and after that that method calls in Page Load Event
void AutoItem()
        {
            try
            {
                AutoCompleteStringCollection autocomp = new AutoCompleteStringCollection();
                List<POS_ManagerBrandDetails> ListItem = new List<POS_ManagerBrandDetails>();
                ListItem = ERPManagement.GetInstance.AllItemDetails();
                for (int i = 0; i < ListItem.Count; i++)
                {
                    autocomp.Add(ListItem[i].ItemName);
                    TxtBrand.AutoCompleteMode = AutoCompleteMode.Suggest;
                    TxtBrand.AutoCompleteSource = AutoCompleteSource.CustomSource;
                    TxtBrand.AutoCompleteCustomSource = autocomp;
                }
            }
            catch (Exception ex)
            {
            }
        }

Monday, 20 May 2013

Checkbox in a gridview and retrive the data about choose the checkbox wise(At a time multiple checkbox choose) in Window Application

 
 ///Store Procedure At a time multiple id sent from front end
//Insert Data and at that time delete the record through the role id and insert data in to the database at that RolId
ALTER PROCEDURE [POS].[KC_InsertUserAccess]
(
@Role_ID               INT=0,
@Store_ID               INT=0,
@Parameter AS Pos.UserAccessType READONLY
)
AS
BEGIN
   SET NOCOUNT ON
    BEGIN
    BEGIN TRY
    BEGIN TRAN
   
------------------
--TRUNCATE TABLE Pos.UserAccess

DELETE FROM Pos.UserAccess
WHERE Role_ID=@Role_ID

INSERT INTO Pos.UserAccess
(Store_ID,Link_ID,Role_ID)

SELECT @Store_ID,Link_ID,@Role_ID FROM  @Parameter
------------------
COMMIT TRAN
END TRY
BEGIN CATCH
ROLLBACK TRAN
END CATCH
END
SET NOCOUNT OFF
END
//
ALTER PROCEDURE POS.SelectManagerBrand
(
@Parameter VARCHAR(100)
)
AS
BEGIN

DECLARE @SQL VARCHAR(MAX)
SET @SQL=
'SELECT        IG.Item_Name, IBD.Barcode, SQA.Item_Quantity, IVD.Variation_Name, ISNULL(IP.Fixed_Price, 0) + ISNULL(IVP.Retail_Price_Inclusive, 0) AS Sale_Price,
                         MB.Brand_Name
FROM            Inventory.MST_Brand AS MB INNER JOIN
                         Inventory.D_ItemGeneralInfo AS IG INNER JOIN
                         Inventory.ItemBarcodeDetails AS IBD ON IG.Item_ID = IBD.Item_ID INNER JOIN
                         Inventory.MST_Category AS MC ON IG.Category_ID = MC.Category_ID INNER JOIN
                         Inventory.StockQCApprove AS SQA ON IBD.Barcode = SQA.Matrix_Detail_ID INNER JOIN
                         Inventory.D_ItemBrand AS IB ON IG.Item_ID = IB.Item_ID ON MB.Brand_ID = IB.Brand_ID LEFT OUTER JOIN
                         Inventory.D_ItemVariationPrice AS IVP INNER JOIN
                         Inventory.D_ItemVariationDetails AS IVD ON IVP.Variation_Detail_ID = IVD.Variation_Detail_ID ON IBD.Barcode = IVP.Barcode AND IG.Item_ID = IVD.Item_ID AND
                         IBD.Barcode = IVD.Barcode LEFT OUTER JOIN
                         Inventory.D_ItemPricing AS IP ON IG.Item_ID = IP.Item_ID AND IBD.Barcode = IP.Barcode
WHERE       MB.Brand_ID IN ('+@Parameter+')'

EXEC(@SQL)

END
--DROP TYPE Pos.SelectManagerType
--CREATE TYPE Pos.SelectManagerType
--AS TABLE
--(
--ID VARCHAR(50) NULL
--)
//


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Swash.Objects;
using Swash.BusinessLayer;
using System.Data.SqlClient;

namespace POS
{
    public partial class StoreRoomBM : Form
    {
        int rowcount = 0, nextCount = 0;
        int j, k = 0;
        int FirstIndex = 0, LastIndex = 20;
        string bids = "";
        int sum = 0;
        int BrandId = 0;
        int count = 0;
        string brandNames = "";
        List<int> lstBrand = new List<int>();
        List<string> lstNames = new List<string>();
        DataTable dtBrand;
        DataTable dtBranddtl;
        bool flag = false;
        SqlDataAdapter da = new SqlDataAdapter();
        int scrollVal;
        DataSet ds;
        DataTable dtIndex;
        int skip = 0, take = 0;


        public StoreRoomBM()
        {
            InitializeComponent();
        }

        public void CreatBrandWiseTable()
        {
            dtBranddtl = new DataTable();
            dtBranddtl.Columns.Add("ItemName", typeof(string));
            dtBranddtl.Columns.Add("Variation", typeof(string));
            dtBranddtl.Columns.Add("Barcode", typeof(string));
            dtBranddtl.Columns.Add("itemQuantity", typeof(string));
            dtBranddtl.Columns.Add("SalePrice", typeof(string));
        }

        private void StoreRoomBM_Load(object sender, EventArgs e)
        {
            txtFindBrand.Text = "Find Brand";
            AutoCompForFindBrand();
            autoItem();
            FillBrand();
            CreateDT();
            FillAllLoadTime();

            CreatBrandWiseTable();
        }
        public void GetListing()
        {

        }
      

        private void txtFindBrand_Enter(object sender, EventArgs e)
        {
            txtFindBrand.Clear();
        }
        private void txtFindBrand_Leave(object sender, EventArgs e)
        {
            try
            {
                if (txtFindBrand.Text == "")
                    txtFindBrand.Text = "Find Brand";
                else
                {
                    string s = string.Empty;
                    k = txtFindBrand.Text.LastIndexOf(" ");
                    s = txtFindBrand.Text;
                    txtFindBrand.Text = txtFindBrand.Text.Substring(0, k);
                    k = Convert.ToInt32(s.Substring(k));
                }
            }
            catch (Exception ex)
            {
            }
        }
        void AutoCompForFindBrand()
        {
            try
            {
                AutoCompleteStringCollection autocomp = new AutoCompleteStringCollection();
                var obj = ERPManagement.GetInstance.GetAllBrand();
                for (int i = 0; i < obj.Count; i++)
                {
                    autocomp.Add(obj[i].Brand_Name);
                    txtFindBrand.AutoCompleteMode = AutoCompleteMode.Suggest;
                    txtFindBrand.AutoCompleteSource = AutoCompleteSource.CustomSource;
                    txtFindBrand.AutoCompleteCustomSource = autocomp;
                }
            }
            catch (Exception ex)
            {
            }
        }
        void autoItem()
        {
            try
            {
                AutoCompleteStringCollection autocomp = new AutoCompleteStringCollection();
                List<POS_ManagerBrandDetails> ListItem = new List<POS_ManagerBrandDetails>();
                ListItem = ERPManagement.GetInstance.AllItemDetails();
                for (int i = 0; i < ListItem.Count; i++)
                {
                    autocomp.Add(ListItem[i].ItemName);
                    TxtBrand.AutoCompleteMode = AutoCompleteMode.Suggest;
                    TxtBrand.AutoCompleteSource = AutoCompleteSource.CustomSource;
                    TxtBrand.AutoCompleteCustomSource = autocomp;
                }
            }
            catch (Exception ex)
            {
            }
        }
        void FillBrand()
        {
            try
            {
                var AllBrand = from c in ERPManagement.GetInstance.GetAllBrand()
                               select new { c.Brand_ID, Brandname = c.Brand_Name };
                if (AllBrand.ToList().Count > 0)
                {
                    dgvAllBrand.Columns.Clear();
                    DataGridViewCheckBoxColumn Select = new DataGridViewCheckBoxColumn();
                    Select.Visible = true;
                    dgvAllBrand.Columns.Add(Select);
                    dgvAllBrand.DataSource = AllBrand.ToList();
                    dgvAllBrand.Columns["Brand_ID"].Visible = false;
                    dgvAllBrand.Columns[0].Width = 25;
                }
                else
                {
                    dgvAllBrand.DataSource = null;
                }
            }
            catch (Exception ex)
            {
            }
        }
        void SetGridHeaderNames()
        {
            DataDetailsData.Columns[0].HeaderText = "Item Name";
            DataDetailsData.Columns[1].HeaderText = "Variation Name";
            DataDetailsData.Columns[2].HeaderText = "Barcode";
            DataDetailsData.Columns[3].HeaderText = "Quantity";
            DataDetailsData.Columns[4].HeaderText = "Sale Price";
            DataDetailsData.Columns[5].HeaderText = "Brand Name";
        }
        private void dgvAllBrand_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            try
            {
                if (e.ColumnIndex == 0)
                {
                    DataGridViewCheckBoxCell ch1 = new DataGridViewCheckBoxCell();
                    ch1 = (DataGridViewCheckBoxCell)dgvAllBrand.Rows[e.RowIndex].Cells[e.ColumnIndex];

                    if (ch1.Value == null)
                        ch1.Value = false;
                    switch (ch1.Value.ToString().ToLower())
                    {
                        case "true":
                            ch1.Value = false;
                            RemoveFromDT(Convert.ToInt32(dgvAllBrand.Rows[e.RowIndex].Cells[1].Value.ToString()));
                            lstNames.Remove(dgvAllBrand.Rows[e.RowIndex].Cells[2].Value.ToString());
                            lstBrand.Remove(Convert.ToInt32(dgvAllBrand.Rows[e.RowIndex].Cells[1].Value.ToString()));
                            UpdateBrandsString(lstBrand);
                            count--;
                            Count();
                            // UpdateBrandsString(lstNames);
                            if (bids != "")
                            {
                                var bb = (from k in ERPManagement.GetInstance.AllDataAgniastBrandID(bids).AsEnumerable()
                                          select new
                                          {
                                              Item_Name = k.Field<string>("Item_Name"),
                                              Variation_Name = k.Field<string>("Variation_Name"),
                                              Barcode = k.Field<string>("Barcode"),
                                              Item_Quantity = k.Field<int>("Item_Quantity"),
                                              Sale_Price = k.Field<decimal>("Sale_Price"),
                                              Brand_Name = k.Field<string>("Brand_Name")
                                          }).Take(15);
                                DataTable dt = new DataTable();
                                dt.Columns.Add("Item Name");
                                dt.Columns.Add("Variation Name");
                                dt.Columns.Add("Barcode");
                                dt.Columns.Add("Quantity");
                                dt.Columns.Add("Price");
                                dt.Columns.Add("BrandName");
                                foreach (var x in bb)
                                {
                                    dt.Rows.Add(x.Item_Name, x.Variation_Name, x.Barcode, x.Item_Quantity, x.Sale_Price, x.Brand_Name);
                                    dt.AcceptChanges();
                                }
                                if (bb.ToList().Count > 0)
                                {
                                    int showtotal = bb.ToList().Count;
                                    DataDetailsData.DataSource = dt;
                                    SetGridHeaderNames();
                                    var bbb = (from k in ERPManagement.GetInstance.AllDataAgniastBrandID(bids).AsEnumerable()
                                               select new
                                               {
                                                   Item_Name = k.Field<string>("Item_Name"),
                                                   Variation_Name = k.Field<string>("Variation_Name"),
                                                   Barcode = k.Field<string>("Barcode"),
                                                   Item_Quantity = k.Field<int>("Item_Quantity"),
                                                   Sale_Price = k.Field<decimal>("Sale_Price"),
                                                   Brand_Name = k.Field<string>("Brand_Name")
                                               });
                                    DataTable dt1 = new DataTable();
                                    dt1.Columns.Add("Item Name");
                                    dt1.Columns.Add("Variation Name");
                                    dt1.Columns.Add("Barcode");
                                    dt1.Columns.Add("Quantity");
                                    dt1.Columns.Add("Price");
                                    dt1.Columns.Add("BrandName");
                                    foreach (var x in bb)
                                    {
                                        dt1.Rows.Add(x.Item_Name, x.Variation_Name, x.Barcode, x.Item_Quantity, x.Sale_Price, x.Brand_Name);
                                        dt1.AcceptChanges();
                                    }
                                    LblREcordCount.Text = 1 + " - " + showtotal + "  of " + ERPManagement.GetInstance.AllDataAgniastBrandID(bids).AsEnumerable().Count();
                                    btnPrevious.Enabled = false;
                                    LblRecord.Visible = false;
                                    label2.Visible = false;
                                    LblNo.Visible = true;
                                }
                                else
                                {
                                    DataDetailsData.DataSource = dtBranddtl;
                                    label2.Visible = true;
                                    LblNo.Visible = false;
                                }
                            }
                            else
                            {
                                // DataDetailsData.DataSource = null;
                                //FillItemGridDetails(0);

                            }
                            break;
                        case "false":
                            ch1.Value = true;
                            InsertToDT(Convert.ToInt32(dgvAllBrand.Rows[e.RowIndex].Cells[1].Value.ToString()));
                            lstNames.Add(dgvAllBrand.Rows[e.RowIndex].Cells[2].Value.ToString());
                            lstBrand.Add(Convert.ToInt32(dgvAllBrand.Rows[e.RowIndex].Cells[1].Value.ToString()));
                            UpdateBrandsString(lstBrand);
                            count++;
                            Count();
                            //UpdateBrandsString(lstNames);
                            if (bids != "")
                            {
                                DataDetailsData.DataSource = null;

                                var bb = (from k in ERPManagement.GetInstance.AllDataAgniastBrandID(bids).AsEnumerable()
                                          select new
                                          {
                                              Item_Name = k.Field<string>("Item_Name"),
                                              Variation_Name = k.Field<string>("Variation_Name"),
                                              Barcode = k.Field<string>("Barcode"),
                                              Item_Quantity = k.Field<int>("Item_Quantity"),
                                              Sale_Price = k.Field<decimal>("Sale_Price"),
                                              Brand_Name = k.Field<string>("Brand_Name")
                                          }).Take(15);
                                DataTable dt = new DataTable();
                                dt.Columns.Add("Item Name");
                                dt.Columns.Add("Variation Name");
                                dt.Columns.Add("Barcode");
                                dt.Columns.Add("Quantity");
                                dt.Columns.Add("Price");
                                dt.Columns.Add("BrandName");
                                foreach (var x in bb)
                                {
                                    dt.Rows.Add(x.Item_Name, x.Variation_Name, x.Barcode, x.Item_Quantity, x.Sale_Price, x.Brand_Name);
                                    dt.AcceptChanges();
                                }
                                if (bb.ToList().Count > 0)
                                {
                                    int showtotal = bb.ToList().Count;
                                    DataDetailsData.DataSource = dt;
                                    SetGridHeaderNames();
                                    //  LblRecord.Visible = false;
                                    LblNo.Visible = true;
                                    var bbb = (from k in ERPManagement.GetInstance.AllDataAgniastBrandID(bids).AsEnumerable()
                                               select new
                                               {
                                                   Item_Name = k.Field<string>("Item_Name"),
                                                   Variation_Name = k.Field<string>("Variation_Name"),
                                                   Barcode = k.Field<string>("Barcode"),
                                                   Item_Quantity = k.Field<int>("Item_Quantity"),
                                                   Sale_Price = k.Field<decimal>("Sale_Price"),
                                                   Brand_Name = k.Field<string>("Brand_Name")
                                               });
                                    DataTable dt2 = new DataTable();
                                    dt2.Columns.Add("Item Name");
                                    dt2.Columns.Add("Variation Name");
                                    dt2.Columns.Add("Barcode");
                                    dt2.Columns.Add("Quantity");
                                    dt2.Columns.Add("Price");
                                    dt2.Columns.Add("BrandName");
                                    foreach (var x in bb)
                                    {
                                        dt2.Rows.Add(x.Item_Name, x.Variation_Name, x.Barcode, x.Item_Quantity, x.Sale_Price, x.Brand_Name);
                                        dt2.AcceptChanges();
                                    }

                                    LblREcordCount.Text = 1 + " - " + showtotal + "  of " + ERPManagement.GetInstance.AllDataAgniastBrandID(bids).AsEnumerable().Count();
                                    btnPrevious.Enabled = false;
                                    LblRecord.Visible = false;
                                }
                                else
                                {
                                    DataDetailsData.DataSource = dtBranddtl;//defaut header
                                    LblRecord.Visible = true;
                                    LblNo.Visible = false;
                                }
                            }
                            else
                            {
                                DataDetailsData.DataSource = dtBranddtl;
                                // FillItemGridDetails(0);
                            }
                            break;

                    }
                }
            }
            catch (Exception ex)
            {
            }
        }
        void Count()
        {
            if (dgvAllBrand.Rows.Count == count)
            {
                flag = true;
                chkAll.Checked = true;

                return;
            }
            else
            {
                flag = false;
                chkAll.Checked = false;
            }
        }
        private void txtFindBrand_TextChanged(object sender, EventArgs e)
        {
            //try
            //{
            //    FillBrandDetails(txtFindBrand.Text.Trim());
            //    DataDetailsData.DataSource = null;
            //    lstBrand.Clear();
            //}
            //catch (Exception ex)
            //{

            //}
        }
        private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            try
            {
                FillBrand();
                // DataDetailsData.DataSource = null;
                lstBrand.Clear();

            }
            catch (Exception ex)
            {

            }
        }
        private void BtnSave_Click(object sender, EventArgs e)
        {
            this.Close();
        }
        private void btnFind_Click(object sender, EventArgs e)
        {
            try
            {
                if (txtFindBrand.Text != "Find Brand")
                {
                    string name = txtFindBrand.Text.ToUpper();
                    FillDetails(name);
                    DataDetailsData.DataSource = null;
                    lstBrand.Clear();
                    //FillItemGridDetails(0);
                }
                else
                {
                    FillBrand();
                }
            }
            catch (Exception ex)
            {

            }
        }
        void FillAllLoadTime()
        {
            try
            {
                var a = from p in ERPManagement.GetInstance.AllItemDetails().Take(15)
                        select new
                        {
                            Item_Name = p.ItemName,
                            Variation_Name = p.Variation,
                            Barcode = p.Barcode,
                            Quantity = p.itemQuantity,
                            Price = p.SalePrice,
                            BrandName = p.BrandName
                        };
                DataTable dt = new DataTable();
                dt.Columns.Add("Item_Name");
                dt.Columns.Add("Variation_Name");
                dt.Columns.Add("Barcode");
                dt.Columns.Add("Quantity");
                dt.Columns.Add("Price");
                dt.Columns.Add("BrandName");
                foreach (var x in a)
                {
                    dt.Rows.Add(x.Item_Name, x.Variation_Name, x.Barcode, x.Quantity, x.Price, x.BrandName);
                    dt.AcceptChanges();
                }
                if (a.ToList().Count > 0)
                {
                    int showtotal = a.ToList().Count;
                    DataDetailsData.DataSource = dt;
                    SetGridHeaderNames();
                    LblREcordCount.Text = 1 + " - " + showtotal + "  of " + ERPManagement.GetInstance.AllItemDetails().Count;
                    btnPrevious.Enabled = false;
                    LblRecord.Visible = false;
                }
                else
                {

                    DataDetailsData.DataSource = null;
                    LblRecord.Visible = true;
                }
            }
            catch (Exception ex)
            {
            }
        }
        public bool CheckGrid()
        {
            bool retval = false;
            foreach (DataGridViewRow drg in dgvAllBrand.Rows)
            {
                DataGridViewCheckBoxCell ch1 = new DataGridViewCheckBoxCell();
                ch1 = (DataGridViewCheckBoxCell)drg.Cells[0];
                if (ch1.Value != null)
                {
                    retval = true;
                    break;
                }
            }
            return retval;
        }
        private void FillDetails(string name)
        {
            try
            {
                var AllBrand = from c in ERPManagement.GetInstance.GetAllBrand()
                               where c.Brand_Name.ToUpper().StartsWith(name)
                               select new { c.Brand_ID, Brandname = c.Brand_Name };
                if (AllBrand.ToList().Count > 0)
                {
                    dgvAllBrand.Columns.Clear();
                    DataGridViewCheckBoxColumn Select = new DataGridViewCheckBoxColumn();
                    Select.Visible = true;
                    dgvAllBrand.Columns.Add(Select);
                    dgvAllBrand.DataSource = AllBrand.ToList();
                    dgvAllBrand.Columns["Brand_ID"].Visible = false;
                    dgvAllBrand.Columns[0].Width = 25;
                }
                else
                {
                    dgvAllBrand.DataSource = null;
                }
            }
            catch (Exception ex)
            {
            }
        }
        private void btnNext_Click(object sender, EventArgs e)
        {
            try
            {
                if (!CheckGrid())
                {

                    nextCount++;
                    for (int i = 1; i < ERPManagement.GetInstance.AllItemDetails().ToList().Count / 15 + 1; i++)
                    {
                        if (nextCount == i)
                        {
                            skip = skip + 15;
                            take = 15;
                            var a = from p in ERPManagement.GetInstance.AllItemDetails().Skip(skip).Take(take)
                                    select p;
                            DataTable dt = new DataTable();
                            dt.Columns.Add("Item Name");
                            dt.Columns.Add("Variation Name");
                            dt.Columns.Add("Barcode");
                            dt.Columns.Add("Quantity");
                            dt.Columns.Add("Price");
                            dt.Columns.Add("BrandName");
                            foreach (var x in a)
                            {
                                dt.Rows.Add(x.ItemName, x.Variation, x.Barcode, x.itemQuantity, x.SalePrice, x.BrandName);
                                dt.AcceptChanges();
                            }
                            if (a.ToList().Count > 0)
                            {
                                btnPrevious.Enabled = true;
                                DataDetailsData.DataSource = dt;
                                LblREcordCount.Text = (skip + 1) + " - " + (skip + a.ToList().Count) + "  of " + ERPManagement.GetInstance.AllItemDetails().Count;
                                LblRecord.Visible = false;
                            }
                            else
                            {
                                DataDetailsData.DataSource = null;
                                LblRecord.Visible = true;
                            }
                        }
                    }
                }
                else
                {
                    var bb = (from k in ERPManagement.GetInstance.AllDataAgniastBrandID(bids).AsEnumerable()
                              select new
                              {
                                  Item_Name = k.Field<string>("Item_Name"),
                                  Variation_Name = k.Field<string>("Variation_Name"),
                                  Barcode = k.Field<string>("Barcode"),
                                  Item_Quantity = k.Field<int>("Item_Quantity"),
                                  Sale_Price = k.Field<decimal>("Sale_Price"),
                                  Brand_Name = k.Field<string>("Brand_Name")
                              });
                    nextCount++;
                    for (int i = 1; i < bb.ToList().Count / 15 + 1; i++)
                    {
                        if (nextCount == i)
                        {
                            skip = skip + 15;
                            take = 15;
                            var a = (from k in ERPManagement.GetInstance.AllDataAgniastBrandID(bids).AsEnumerable()
                                     select new
                                     {
                                         Item_Name = k.Field<string>("Item_Name"),
                                         Variation_Name = k.Field<string>("Variation_Name"),
                                         Barcode = k.Field<string>("Barcode"),
                                         Item_Quantity = k.Field<int>("Item_Quantity"),
                                         Sale_Price = k.Field<decimal>("Sale_Price"),
                                         Brand_Name = k.Field<string>("Brand_Name")
                                     }).Skip(skip).Take(take);
                            DataTable dt = new DataTable();
                            dt.Columns.Add("Item Name");
                            dt.Columns.Add("Variation Name");
                            dt.Columns.Add("Barcode");
                            dt.Columns.Add("Quantity");
                            dt.Columns.Add("Price");
                            dt.Columns.Add("BrandName");
                            foreach (var x in a)
                            {
                                dt.Rows.Add(x.Item_Name, x.Variation_Name, x.Barcode, x.Item_Quantity, x.Sale_Price, x.Brand_Name);
                                dt.AcceptChanges();
                            }
                            if (a.ToList().Count > 0)
                            {
                                btnPrevious.Enabled = true;
                                DataDetailsData.DataSource = dt;
                                LblREcordCount.Text = (skip + 1) + " - " + (skip + a.ToList().Count) + "  of " + ERPManagement.GetInstance.AllDataAgniastBrandID(bids).AsEnumerable().Count();
                                if (skip + a.ToList().Count == bb.ToList().Count)
                                {
                                    btnNext.Enabled = false;
                                }
                                LblRecord.Visible = false;
                                btnPrevious.Enabled = true;
                            }
                            else
                            {

                                DataDetailsData.DataSource = null;
                                LblRecord.Visible = true;
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            { }
        }
        private void btnPrevious_Click(object sender, EventArgs e)
        {
            try
            {
                if (!CheckGrid())
                {

                    nextCount--;
                    for (int i = 0; i < ERPManagement.GetInstance.AllItemDetails().ToList().Count / 15; i++)
                    {
                        if (nextCount == i)
                        {

                            skip = skip - 15;
                            take = 15;

                            var a = from p in ERPManagement.GetInstance.AllItemDetails().Skip(skip).Take(take)
                                    select p;
                            DataTable dt = new DataTable();
                            dt.Columns.Add("Item Name");
                            dt.Columns.Add("Variation Name");
                            dt.Columns.Add("Barcode");
                            dt.Columns.Add("Quantity");
                            dt.Columns.Add("Price");
                            dt.Columns.Add("BrandName");
                            foreach (var x in a)
                            {
                                dt.Rows.Add(x.ItemName, x.Variation, x.Barcode, x.itemQuantity, x.SalePrice, x.BrandName);
                                dt.AcceptChanges();
                            }
                            if (a.ToList().Count > 0)
                            {
                                //if (skip == 1)
                                //    btnPrevious.Enabled = false;
                                DataDetailsData.DataSource = dt;
                                LblREcordCount.Text = (skip + 1) + " - " + (skip + a.ToList().Count) + "  of " + ERPManagement.GetInstance.AllItemDetails().Count;
                                LblRecord.Visible = false;
                            }
                            else
                            {

                                DataDetailsData.DataSource = null;
                                LblRecord.Visible = true;
                            }
                        }
                    }
                }
                else
                {
                    var bb = (from k in ERPManagement.GetInstance.AllDataAgniastBrandID(bids).AsEnumerable()
                              select new
                              {
                                  Item_Name = k.Field<string>("Item_Name"),
                                  Variation_Name = k.Field<string>("Variation_Name"),
                                  Barcode = k.Field<string>("Barcode"),
                                  Item_Quantity = k.Field<int>("Item_Quantity"),
                                  Sale_Price = k.Field<decimal>("Sale_Price"),
                                  Brand_Name = k.Field<string>("Brand_Name")
                              });
                    nextCount--;
                    for (int i = 0; i < bb.ToList().Count / 15; i++)
                    {
                        if (nextCount == i)
                        {

                            skip = skip - 15;
                            take = 15;
                            var a = (from k in ERPManagement.GetInstance.AllDataAgniastBrandID(bids).AsEnumerable()
                                     select new
                                     {
                                         Item_Name = k.Field<string>("Item_Name"),
                                         Variation_Name = k.Field<string>("Variation_Name"),
                                         Barcode = k.Field<string>("Barcode"),
                                         Item_Quantity = k.Field<int>("Item_Quantity"),
                                         Sale_Price = k.Field<decimal>("Sale_Price"),
                                         Brand_Name = k.Field<string>("Brand_Name")
                                     }).Skip(skip).Take(take);
                            DataTable dt = new DataTable();
                            dt.Columns.Add("Item Name");
                            dt.Columns.Add("Variation Name");
                            dt.Columns.Add("Barcode");
                            dt.Columns.Add("Quantity");
                            dt.Columns.Add("Price");
                            dt.Columns.Add("BrandName");
                            foreach (var x in a)
                            {
                                dt.Rows.Add(x.Item_Name, x.Variation_Name, x.Barcode, x.Item_Quantity, x.Sale_Price, x.Brand_Name);
                                dt.AcceptChanges();
                            }
                            if (a.ToList().Count > 0)
                            {
                                //if (skip == 1)
                                //    btnPrevious.Enabled = false;
                                DataDetailsData.DataSource = dt;
                                LblREcordCount.Text = (skip + 1) + " - " + (skip + a.ToList().Count) + "  of " + ERPManagement.GetInstance.AllDataAgniastBrandID(bids).AsEnumerable().Count();
                                if (skip == 0)
                                {
                                    btnPrevious.Enabled = false;
                                }
                                btnNext.Enabled = true;
                                LblRecord.Visible = false;
                            }
                            else
                            {

                                DataDetailsData.DataSource = null;
                                LblRecord.Visible = true;
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            { }
        }
        private void button1_Click(object sender, EventArgs e)
        {
            //FillItemGridDetails(0);
        }
        private void Btnok_Click(object sender, EventArgs e)
        {
            StoreRoom obj = new StoreRoom();
            //obj.StartPosition = FormStartPosition.Manual;
            ////Point p = GridViewItems.Location;
            //// obj.Location = new Point(GridViewItems.Location.X + this.Location.X, p.Y + 122); //Point(this.Location.X, 62 + this.Location.Y);
            obj.Show();
        }
        public void CreateDT()
        {
            dtBrand = new System.Data.DataTable();
            dtBrand.Columns.Add("BrandID", typeof(int));
        }
        public void InsertToDT(int bid)
        {
            try
            {
                if (dtBrand == null)
                    CreateDT();
                dtBrand.Rows.Add(bid);
                dtBrand.AcceptChanges();
            }
            catch (Exception ex)
            {
            }
        }
        public void RemoveFromDT(int bid)
        {
            try
            {
                int index = 0;
                foreach (DataRow dr in dtBrand.Rows)
                {
                    if (Convert.ToInt32(dr["BrandID"].ToString()) == bid)
                    {
                        break;
                    }
                    index++;
                }
                dtBrand.Rows.RemoveAt(index);
                dtBrand.AcceptChanges();
            }
            catch (Exception ex)
            {
            }
        }
        public void UpdateBrandsString(List<int> lst)
        {
            try
            {
                if (lst.Count > 1)
                {
                    bids = "";
                    foreach (int x in lstBrand)
                    {
                        bids = bids + x.ToString() + ",";
                    }
                    bids = bids.Remove(bids.LastIndexOf(','));
                }
                else if (lst.Count == 1)
                {
                    bids = lst[0].ToString();
                }
                else
                {
                    bids = "";
                }
            }
            catch (Exception ex)
            {
            }
        }
        private void button1_Click_1(object sender, EventArgs e)
        {
            try
            {
                if (TxtBrand.Text != "")
                {
                    string nm = TxtBrand.Text.ToUpper().Trim();
                    var nn = from bb in ERPManagement.GetInstance.AllItemDetails()
                             where bb.ItemName.ToUpper().StartsWith(nm)
                             select new { ItemName = bb.ItemName, variation = bb.Variation, barcode = bb.Barcode, quantity = bb.itemQuantity, Saleprice = bb.SalePrice, brandname = bb.BrandName };
                    DataTable dt = new DataTable();
                    dt.Columns.Add("Item Name");
                    dt.Columns.Add("Variation Name");
                    dt.Columns.Add("Barcode");
                    dt.Columns.Add("Quantity");
                    dt.Columns.Add("Price");
                    dt.Columns.Add("BrandName");
                    foreach (var x in nn)
                    {
                        dt.Rows.Add(x.ItemName, x.variation, x.barcode, x.quantity, x.Saleprice, x.brandname);
                        dt.AcceptChanges();
                    }
                    if (nn.ToList().Count > 0)
                    {
                        DataDetailsData.DataSource = dt;
                        LblRecord.Visible = false;
                    }
                    else
                    {
                        DataDetailsData.DataSource = null;
                        LblRecord.Visible = true;
                    }
                }
                else
                {
                    MessageBox.Show("Put item name.", "KenCloud", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    TxtBrand.Focus();
                }
            }
            catch (Exception ex)
            {
            }

        }
        public void UpdateBrandsString(List<string> lst)
        {
            try
            {
                if (lst.Count > 1)
                {
                    brandNames = "";
                    foreach (string x in lstNames)
                    {
                        brandNames = brandNames + x.ToString() + ",";
                    }
                    brandNames = brandNames.Remove(brandNames.LastIndexOf(','));
                }
                else if (lst.Count == 1)
                {
                    brandNames = lst[0].ToString();
                }
                else
                {
                    brandNames = "";
                }
            }
            catch (Exception ex)
            {
            }
            //TxtBrand.Text = brandNames;
        }
        private void chkAll_CheckedChanged(object sender, EventArgs e)
        {
            try
            {
                if (chkAll.Checked)
                {
                    if (flag == false)
                    {
                        foreach (DataGridViewRow Row in dgvAllBrand.Rows)
                        {
                            ((DataGridViewCheckBoxCell)Row.Cells[0]).Value = true;
                            InsertToDT(Convert.ToInt32(Row.Cells[1].Value.ToString()));
                            lstNames.Add(Row.Cells[2].Value.ToString());
                            lstBrand.Add(Convert.ToInt32(Row.Cells[1].Value.ToString()));
                            UpdateBrandsString(lstBrand);
                            count++;
                            Count();
                            //UpdateBrandsString(lstNames);
                            if (bids != "")
                            {
                                // DataDetailsData.DataSource = null;
                                var bb = ERPManagement.GetInstance.AllDataAgniastBrandID(bids);
                                if (bb.Rows.Count > 0)
                                {
                                    DataDetailsData.DataSource = bb;
                                    SetGridHeaderNames();
                                    LblRecord.Visible = false;
                                    LblNo.Visible = true;
                                }
                                else
                                {
                                    DataDetailsData.DataSource = dtBranddtl;//defaut header
                                    LblRecord.Visible = true;
                                    LblNo.Visible = false;
                                }
                            }
                            else
                            {
                                DataDetailsData.DataSource = dtBranddtl;
                                // FillItemGridDetails(0);
                            }
                        }
                        // FillItemGridDetails(0);
                    }
                }
                else
                {
                    if (flag == true)
                    {
                        foreach (DataGridViewRow Row in dgvAllBrand.Rows)
                        {
                            ((DataGridViewCheckBoxCell)Row.Cells[0]).Value = false;
                            count--;
                            RemoveFromDT(Convert.ToInt32(Row.Cells[1].Value.ToString()));
                            lstNames.Remove(Row.Cells[2].Value.ToString());
                            lstBrand.Remove(Convert.ToInt32(Row.Cells[1].Value.ToString()));
                            UpdateBrandsString(lstBrand);
                            Count();
                            //UpdateBrandsString(lstNames);
                            if (bids != "")
                            {
                                var bb = ERPManagement.GetInstance.AllDataAgniastBrandID(bids);
                                if (bb.Rows.Count > 0)
                                {
                                    DataDetailsData.DataSource = bb;
                                    SetGridHeaderNames();
                                    label2.Visible = false;
                                    LblNo.Visible = true;
                                }
                                else
                                {
                                    DataDetailsData.DataSource = dtBranddtl;
                                    label2.Visible = true;
                                    LblNo.Visible = false;
                                }
                            }
                            else
                            {
                                // DataDetailsData.DataSource = null;
                                //FillItemGridDetails(0);

                            }
                        }
                    }


                }
            }
            catch (Exception ex)
            {
            }

        }
        private void BtnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}