public JsonResult _InsertSupplier(Supplier ins)
        {
            //...Insert Object
            Supplier ins2 = SupplierRep.Insert(ins);

            //...Repopulate Grid...
            return Json(new GridModel(SupplierRep.GetAllSupplier()));
        }
        public JsonResult _UpdateSupplier(Supplier ins)
        {
            //...Update Object
            Supplier ins2 = SupplierRep.Update(ins);

            //...Repopulate Grid...
            return Json(new GridModel(SupplierRep.GetAllSupplier()));
        }
        public List<Supplier> GetAllSupplier()
        {
            //...Create New Instance of Object...
            List<Supplier> list = new List<Supplier>();
            Supplier ins;

            //...Database Connection...
            DataBaseConnection dbConn = new DataBaseConnection();
            SqlConnection con = dbConn.SqlConn();
            SqlCommand cmdI;

            //...SQL Commands...
            cmdI = new SqlCommand("SELECT s.*,st.SupplierType FROM t_Supplier s inner join l_SupplierType st on s.SupplierTypeID=st.SupplierTypeID where s.Removed = 0 order by s.Supplier", con);
            cmdI.Connection.Open();
            SqlDataReader drI = cmdI.ExecuteReader();

            //...Retrieve Data...
            if (drI.HasRows)
            {
                while (drI.Read())
                {
                    ins = new Supplier();
                    ins.SupplierID = Convert.ToInt32(drI["SupplierID"]);
                    ins.Suppliers = (drI["Supplier"]).ToString();
                    ins.StockCondition = (drI["StockCondition"]).ToString();
                    ins.Term = Convert.ToString(drI["Term"]);
                    ins.CreatedDate = Convert.ToDateTime(drI["CreatedDate"]);
                    ins.SupplierTypeID = Convert.ToInt32(drI["SupplierTypeID"]);
                    ins.suppliertypeid2 = drI["SupplierType"].ToString();
                    ins.CompanyID = Convert.ToInt32(drI["CompanyID"]);
                    ins.ModifiedDate = Convert.ToDateTime(drI["ModifiedDate"]);
                    ins.ModifiedBy = Convert.ToString(drI["ModifiedBy"]);
                    ins.Removed = Convert.ToBoolean(drI["Removed"]);
                    ins.FromFriday = Convert.ToBoolean(drI["FromFriday"]);
                    list.Add(ins);
                }
            }

            //...Close Connections...
            drI.Close();
            con.Close();

            //...Return...
            return list;
        }
        public Supplier GetSupplier(int SupplierID)
        {
            //...Create New Instance of Object...
            Supplier ins = new Supplier();

            //...Database Connection...
            DataBaseConnection dbConn = new DataBaseConnection();
            SqlConnection con = dbConn.SqlConn();
            SqlCommand cmdI;

            //...SQL Commands...
            cmdI = new SqlCommand("SELECT s.*, st.SupplierType FROM t_Supplier s INNER JOIN l_SupplierType st on s.SupplierTypeID = st.SupplierTypeID WHERE SupplierID =" + SupplierID, con);
            cmdI.Connection.Open();
            SqlDataReader drI = cmdI.ExecuteReader();

            //...Retrieve Data...
            if (drI.HasRows)
            {
                while (drI.Read())
                {
                    ins.SupplierID = Convert.ToInt32(drI["SupplierID"]);
                    ins.Suppliers = (drI["Supplier"]).ToString();
                    ins.StockCondition = (drI["StockCondition"]).ToString();
                    ins.Term = Convert.ToString(drI["Term"]);
                    ins.CreatedDate = Convert.ToDateTime(drI["CreatedDate"]);
                    ins.SupplierTypeID = Convert.ToInt32(drI["SupplierTypeID"]);
                    ins.CompanyID = Convert.ToInt32(drI["CompanyID"]);
                    ins.ModifiedDate = Convert.ToDateTime(drI["ModifiedDate"]);
                    ins.ModifiedBy = Convert.ToString(drI["ModifiedBy"]);
                    ins.Removed = Convert.ToBoolean(drI["Removed"]);
                    ins.FromFriday = Convert.ToBoolean(drI["FromFriday"]);
                    ins.suppliertypeid2 = drI["SupplierType"].ToString();
                }
            }

            //...Close Connections...
            drI.Close();
            con.Close();

            //...Return...
            return ins;
        }
        public JsonResult _AddSupplier(GRVListImport ins)
        {
            //...Update Object
            if (ins.SupplierID == 0)
            {
                //...Insert Supplier
                Supplier sup = new Supplier();
                sup.CompanyID = 0;
                sup.CreatedDate = DateTime.Now;
                sup.FromFriday = ins.FromFriday;
                sup.StockCondition = ins.StockCondition;
                sup.Suppliers = ins.Suppliers;
                sup.SupplierTypeID = ins.SupplierTypeID;
                sup.Term = ins.Term;

                sup = SupRep.Insert(sup);
                ins.SupplierID = sup.SupplierID;
                ins.hasError = (ins.SupplierID == 0) ? true: false;
                GRVListImport ins2 = GRVRep.UpdateTemp(ins);

                //...Update all similair
                GRVRep.UpdateImports();
            }
            else
            {
                //...Update only single one
                ins.hasError = (ins.SupplierID == 0) ? true : false;
                GRVListImport ins2 = GRVRep.UpdateTemp(ins);

                GRVRep.UpdateImports();
            }

            //...Repopulate Grid...
            return Json(new GridModel(GRVRep.GetAllGRVList(ins.BatchId)));
        }
        public Supplier Update(Supplier ins)
        {
            //...Get User and Date Data...
             string ModifiedDate = string.Format("{0:yyyy-MM-dd hh:mm:ss}", DateTime.Now);
              string EmployeeId = Convert.ToString(HttpContext.Current.Session["Username"]);

            //...Database Connection...
            DataBaseConnection dbConn = new DataBaseConnection();
            SqlConnection con = dbConn.SqlConn();
            con.Open();
            SqlCommand cmdI = con.CreateCommand();
            cmdI.Connection = con;

            //...Update Record...
            cmdI.Parameters.Clear();
            cmdI.CommandText = StoredProcedures.SupplierUpdate;
            cmdI.CommandType = System.Data.CommandType.StoredProcedure;
            cmdI.Parameters.AddWithValue("@SupplierID", ins.SupplierID);
            cmdI.Parameters.AddWithValue("@Supplier", ins.Suppliers);
            cmdI.Parameters.AddWithValue("@StockCondition", ins.StockCondition);
            cmdI.Parameters.AddWithValue("@Term", ins.Term);
            cmdI.Parameters.AddWithValue("@CreatedDate", DateTime.Now);
            cmdI.Parameters.AddWithValue("@SupplierTypeID", ins.SupplierTypeID);
            cmdI.Parameters.AddWithValue("@CompanyID", ins.CompanyID);
            cmdI.Parameters.AddWithValue("@ModifiedDate",ModifiedDate);
               cmdI.Parameters.AddWithValue("@ModifiedBy",EmployeeId);

            cmdI.ExecuteNonQuery();
            cmdI.Connection.Close();

            return ins;
        }
        public Supplier Insert(Supplier ins)
        {
            //...Get User and Date Data...
             string ModifiedDate = string.Format("{0:yyyy-MM-dd hh:mm:ss}", DateTime.Now);
             string EmployeeId = Convert.ToString(HttpContext.Current.Session["Username"]);
             string strTrx = "SupplierIns_" + EmployeeId;

            //...Database Connection...
            DataBaseConnection dbConn = new DataBaseConnection();
            SqlConnection con = dbConn.SqlConn();
            con.Open();

            //...Command Interface...
            SqlCommand cmdI = con.CreateCommand();
            SqlTransaction trx;
             trx = con.BeginTransaction(strTrx);
            cmdI.Connection = con;
            cmdI.Transaction = trx;

            try
            {
                //...Insert Record...
                cmdI.CommandText = StoredProcedures.SupplierInsert;
                cmdI.CommandType = System.Data.CommandType.StoredProcedure;
                //cmdI.Parameters.AddWithValue("@SupplierID", ins.SupplierID);
                cmdI.Parameters.AddWithValue("@Supplier", ins.Suppliers);
                cmdI.Parameters.AddWithValue("@StockCondition", ins.StockCondition);
                cmdI.Parameters.AddWithValue("@Term", ins.Term);
                cmdI.Parameters.AddWithValue("@CreatedDate", DateTime.Now);
                cmdI.Parameters.AddWithValue("@SupplierTypeID", ins.SupplierTypeID);
                cmdI.Parameters.AddWithValue("@CompanyID", 1);
                cmdI.Parameters.AddWithValue("@ModifiedDate",ModifiedDate);
                cmdI.Parameters.AddWithValue("@ModifiedBy",EmployeeId);
                cmdI.Parameters.AddWithValue("@Removed", ins.Removed);
                cmdI.Parameters.AddWithValue("@FromFriday", ins.FromFriday);

                //...Return new ID
                ins.SupplierID = (int)cmdI.ExecuteScalar();

                trx.Commit();
                cmdI.Connection.Close();
            }
            catch (SqlException ex)
            {
                if (trx != null) trx.Rollback();
            }
            finally
            {
                //Check for close and respond accordingly
                if (con.State != ConnectionState.Closed)
                {
                    con.Close();
                }
                //Clean up
                con.Dispose();
                cmdI.Dispose();
                trx.Dispose();
            }
            return ins;
        }
        public List<Supplier> GetSuppliersPerSupplierType(int SupplierTypeID)
        {
            //...Create New Instance of Object...
            List<Supplier> list = new List<Supplier>();
            Supplier ins;

            //...Database Connection...
            DataBaseConnection dbConn = new DataBaseConnection();
            SqlConnection con = dbConn.SqlConn();
            SqlCommand cmdI;

            //...SQL Commands...
            cmdI = new SqlCommand("SELECT * FROM t_Supplier WHERE SupplierTypeID = " + SupplierTypeID, con);
            cmdI.Connection.Open();
            SqlDataReader drI = cmdI.ExecuteReader();

            //...Retrieve Data...
            if (drI.HasRows)
            {
                while (drI.Read())
                {
                    ins = new Supplier();
                    ins.SupplierID = Convert.ToInt32(drI["SupplierID"]);
                    ins.Suppliers = (drI["Supplier"]).ToString();
                    ins.StockCondition = (drI["StockCondition"]).ToString();
                    ins.Term = Convert.ToString(drI["Term"]);
                    ins.CreatedDate = Convert.ToDateTime(drI["CreatedDate"]);
                    ins.SupplierTypeID = Convert.ToInt32(drI["SupplierTypeID"]);
                    ins.CompanyID = Convert.ToInt32(drI["CompanyID"]);
                    ins.ModifiedDate = Convert.ToDateTime(drI["ModifiedDate"]);
                    ins.ModifiedBy = Convert.ToString(drI["ModifiedBy"]);
                    ins.Removed = Convert.ToBoolean(drI["Removed"]);
                    list.Add(ins);
                }
            }

            //...Close Connections...
            drI.Close();
            con.Close();

            //...Return...
            return list;
        }