private int UpdateName(ClassDBModel dbModel)
        {
            SqlConnection conn = new SqlConnection(DBConnection.GetConnection());

            conn.Open();
            SqlCommand dCmd = new SqlCommand("UPDATE Class SET ClassName=@ClassName,AddedBy=@AddedBy WHERE ClassID=@ClassID ", conn);

            dCmd.CommandType = CommandType.Text;
            try
            {
                dCmd.Parameters.AddWithValue("@ClassName", dbModel.ClassName);
                dCmd.Parameters.AddWithValue("@ClassID", dbModel.ClassID);
                dCmd.Parameters.AddWithValue("@AddedBy", "Forhad");
                return(dCmd.ExecuteNonQuery());
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                dCmd.Dispose();
                conn.Close();
                conn.Dispose();
            }
        }
        public JsonResult LoadSelectedClass(ClassDBModel _dbModel)
        {
            List <ClassDBModel> _dbModelList = new List <ClassDBModel>();

            _dbModelList = LoadSelectedClassName(_dbModel);
            return(this.Json(_dbModelList, JsonRequestBehavior.AllowGet));
        }
        private int SaveName(ClassDBModel _dbModel)
        {
            SqlConnection conn = new SqlConnection(DBConnection.GetConnection());

            conn.Open();
            SqlCommand dCmd = new SqlCommand(@"INSERT INTO Class (ClassName, AddedBy)
                                              VALUES(@ClassName, @AddedBy)", conn);

            dCmd.CommandType = System.Data.CommandType.Text;

            try
            {
                dCmd.Parameters.AddWithValue("@ClassID", 0);
                dCmd.Parameters.AddWithValue("@ClassName", _dbModel.ClassName);
                dCmd.Parameters.AddWithValue("@AddedBy", "Iqbal");
                return(dCmd.ExecuteNonQuery());
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                dCmd.Dispose();
                conn.Close();
                conn.Dispose();
            }
        }
        public JsonResult DeleteSelectedClass(ClassDBModel _dbModel)
        {
            int _result = 0;

            _result = DeleteClassName(_dbModel);
            if (_result > 0)
            {
                return(Json(new { success = true }));
            }
            else
            {
                return(Json(new { success = false }));
            }
        }
Example #5
0
        public JsonResult SaveData(ClassDBModel _dbModel)
        {
            int Result = 0;

            Result = SaveName(_dbModel);
            if (Result > 0)
            {
                return(Json(new { Success = true }));
            }
            else
            {
                return(Json(new { Success = true }));
            }
        }
        public JsonResult SaveData(ClassDBModel _dbModel)
        {
            int Result = 0;

            if (_dbModel.ClassID > 0)
            {
                Result = UpdateName(_dbModel);
            }
            else
            {
                Result = SaveName(_dbModel);
            }
            if (Result > 0)
            {
                return(Json(new { Success = true }));
            }
            else
            {
                return(Json(new { Success = false }));
            }
        }
        //public ActionResult Info(int ClassID, string reportTypes)
        //{
        //    try
        //    {


        //        //string reportTypes = "EXCELOPENXML";

        //        DataSet ds = new DataSet();
        //        LocalReport localReport = new LocalReport();

        //        ds = LoadAllCG01Report(ClassID);
        //        localReport.ReportPath = Server.MapPath("~/Reports/Report1.rdlc");


        //        ReportDataSource reportDataSource1 = new ReportDataSource();

        //        reportDataSource1.Name = "DataSet1";
        //        reportDataSource1.Value = ds.Tables[0];

        //        //ReportDataSource reportDataSource2 = new ReportDataSource();
        //        //reportDataSource2.Name = "Info1";
        //        //reportDataSource2.Value = ds.Tables[0];

        //        ReportParameter ClassName = new ReportParameter("ClassName", ds.Tables[0].Rows[0]["ClassName"].ToString());
        //        //ReportParameter PCostingRef = new ReportParameter("CostingRef", ds.Tables[0].Rows[0]["CostingRef"].ToString());
        //        //ReportParameter PCompanyName = new ReportParameter("CompanyName", ds.Tables[0].Rows[0]["CompanyName"].ToString());
        //        //ReportParameter PBuyerName = new ReportParameter("BuyerName", ds.Tables[0].Rows[0]["BuyerName"].ToString());
        //        //ReportParameter PStyleID = new ReportParameter("StyleID", " ");


        //        localReport.SetParameters(parameters: new ReportParameter[] { ClassName });
        //        //PCostingRef, PCompanyName, PBuyerName,
        //        ////PStyleID,PStyleName, PProductTypeName, PSAM, PCM,PFOB, POrderQty, PTargetPerDay, PEfficiency,PRemarks,Commission,
        //        ////NegoFabCost,NegoTrimCost,NegoWashCost,NegoArtCost,NegoTestCost,NegoOtherCost,TotalFabCost,TotalTrimCost,
        //        ////TotalWashCost,TotalEmbCost,TotalOtherCost});

        //        localReport.Refresh();
        //        localReport.DataSources.Add(reportDataSource1);
        //        //localReport.DataSources.Add(reportDataSource2);
        //        string reportType = reportTypes;
        //        string mimeType;
        //        string encoding;
        //        string fileNameExtension = "";
        //        //The DeviceInfo settings should be changed based on the reportType
        //        //http://msdn2.microsoft.com/en-us/library/ms155397.aspx
        //        string deviceInfo = "<DeviceInfo>" +
        //            "  <OutputFormat>PDF</OutputFormat>" +
        //                "  <PageWidth>8.50in</PageWidth>" +
        //                "  <PageHeight>11.69in</PageHeight>" +
        //                "  <MarginTop>.2in</MarginTop>" +
        //                "  <MarginLeft>.5in</MarginLeft>" +
        //                "  <MarginRight>.5in</MarginRight>" +
        //                "  <MarginBottom>.2in</MarginBottom>" +
        //            "</DeviceInfo>";
        //        Warning[] warnings;
        //        string[] streams;
        //        byte[] renderedBytes;

        //        renderedBytes = localReport.Render(reportType, deviceInfo, out mimeType, out encoding, out fileNameExtension, out streams, out warnings);
        //        if (reportType == "EXCELOPENXML")
        //        {
        //            return File(renderedBytes, mimeType, "Info.xlsx");
        //        }
        //        else
        //        {
        //            return File(renderedBytes, mimeType, "Info.pdf");
        //        }
        //    }
        //    catch (Exception ex)
        //    {
        //        throw ex;
        //    }
        //}
        //public DataSet LoadAllCG01Report(int ClassID)
        //{
        //    List<ClassDBModel> _modelList = new List<ClassDBModel>();
        //    SqlConnection conn = new SqlConnection(DBConnection.GetConnection());
        //    conn.Open();
        //    SqlCommand dAd = new SqlCommand("SELECT * FROM Class WHERE ClassID=@ClassID", conn);
        //    SqlDataAdapter sda = new SqlDataAdapter(dAd);
        //    dAd.CommandType = CommandType.Text;
        //    dAd.Parameters.AddWithValue("@ClassID", ClassID);
        //    DataSet ds = new DataSet();
        //    try
        //    {
        //        sda.Fill(ds);


        //        return ds;
        //    }
        //    catch (Exception ex)
        //    {
        //        //UtilityOptions.ErrorLog(ex.ToString(), MethodBase.GetCurrentMethod().Name);
        //        throw ex;
        //    }
        //    finally
        //    {
        //        ds.Dispose();
        //        dAd.Dispose();
        //        conn.Close();
        //        conn.Dispose();
        //    }
        //}

        private List <ClassDBModel> LoadSelectedClassName(ClassDBModel dbModel)
        {
            List <ClassDBModel> _modelList = new List <ClassDBModel>();
            SqlConnection       conn       = new SqlConnection(DBConnection.GetConnection());

            conn.Open();
            SqlCommand     dAd = new SqlCommand("SELECT * FROM Class WHERE ClassID=@ClassID", conn);
            SqlDataAdapter sda = new SqlDataAdapter(dAd);

            dAd.CommandType = CommandType.Text;
            dAd.Parameters.AddWithValue("@ClassID", dbModel.ClassID);
            DataTable dt = new DataTable();

            try
            {
                sda.Fill(dt);
                if (dt.Rows.Count > 0)
                {
                    _modelList = (from DataRow row in dt.Rows
                                  select new ClassDBModel
                    {
                        ClassID = Convert.ToInt32(row["ClassID"].ToString()),
                        ClassName = row["ClassName"].ToString(),
                        AddedBy = row["AddedBy"].ToString()
                    }).ToList();
                }
                return(_modelList);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                dt.Dispose();
                dAd.Dispose();
                conn.Close();
                conn.Dispose();
            }
        }
        private int DeleteClassName(ClassDBModel dbModel)
        {
            SqlConnection conn = new SqlConnection(DBConnection.GetConnection());

            conn.Open();
            SqlCommand dCmd = new SqlCommand("DELETE FROM Class WHERE ClassID = @ClassID", conn);

            dCmd.CommandType = CommandType.Text;
            try
            {
                dCmd.Parameters.AddWithValue("@ClassID", dbModel.ClassID);
                return(dCmd.ExecuteNonQuery());
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                dCmd.Dispose();
                conn.Close();
                conn.Dispose();
            }
        }