Exemplo n.º 1
0
        private void FetchUploadFileMasterList()
        {
            if (Session["UploadFileMasterList"] == null)
            {
                ObjectResult <UploadFileMasterResult> objUploadFileMasterResult  = objSP_PRICINGEntities.SP_FETCH_UPLOAD_FILE_MASTER_DETAILS();
                List <UploadFileMasterResult>         UploadFileMasterResultList = objUploadFileMasterResult.ToList();

                List <UploadFileMaster> UploadFileMasterList = new List <UploadFileMaster>();

                if (UploadFileMasterResultList != null && UploadFileMasterResultList.Count > 0)
                {
                    foreach (UploadFileMasterResult oUploadFileMasterResult in UploadFileMasterResultList)
                    {
                        UploadFileMaster objUploadFileMaster = new UploadFileMaster();
                        General.ReflectSingleData(objUploadFileMaster, oUploadFileMasterResult);
                        UploadFileMasterList.Add(objUploadFileMaster);
                    }
                }
                Session["UploadFileMasterList"] = UploadFileMasterList;
            }
        }
Exemplo n.º 2
0
        public ActionResult PricingDeployment(PricingDeployment objPricingDeployment, string Command, FormCollection collection, HttpPostedFileBase file, HttpPostedFileBase file1)
        {
            LoginController         objLoginController   = new LoginController();
            List <UploadFileMaster> UploadFileMasterList = (List <UploadFileMaster>)Session["UploadFileMasterList"];

            string strEntityID    = collection["EntityID"];
            string strIsSecuredID = collection["IsSecuredID"];

            Int32 intEntityID    = Convert.ToInt32(strEntityID.Split(',')[0]);
            Int32 intIsSecuredID = Convert.ToInt32(strIsSecuredID.Split(',')[0]);

            try
            {
                if (ValidateSession())
                {
                    bool blnUploadStatus     = false;
                    bool blnUploadDataStatus = true;

                    #region Price Deployment
                    if (Command == "PDUpload")
                    {
                        if (file != null && file.ContentLength > 0)
                        {
                            UploadFileMaster objUploadFileMaster = UploadFileMasterList.Find(delegate(UploadFileMaster oUploadFileMaster) { return(oUploadFileMaster.UploadTypeCode == "PDR"); });
                            string           strFilePath         = System.Web.HttpContext.Current.Server.MapPath("~/Uploads/");
                            string           strFileName         = Path.GetFileNameWithoutExtension(file.FileName) + DateTime.Now.ToString("dd_mmm_yyyy_hh_mm");
                            string           strExtension        = Path.GetExtension(file.FileName);

                            strFilePath += strFileName + strExtension;
                            file.SaveAs(strFilePath);

                            FileInfo newFile = new FileInfo(strFilePath);

                            string   strSourceColumn = objUploadFileMaster.SourceColumn;
                            string[] arrSourceColumn = null;
                            if (strSourceColumn != "")
                            {
                                arrSourceColumn = strSourceColumn.Split('|');
                            }

                            DataTable dtData = new DataTable();

                            for (int i = 0; i < arrSourceColumn.Length; i++)
                            {
                                dtData.Columns.Add(arrSourceColumn[i]);
                            }

                            string   strDestinationColumn = objUploadFileMaster.DestinationColumn;
                            string[] arrDestinationColumn = null;

                            if (strDestinationColumn != "")
                            {
                                arrDestinationColumn = strDestinationColumn.Split('|');
                            }

                            string strTableName = objUploadFileMaster.TableName;

                            using (ExcelPackage xlPackage = new ExcelPackage(newFile))
                            {
                                ExcelWorksheet worksheet = xlPackage.Workbook.Worksheets[objUploadFileMaster.SheetName];

                                string strVersion = worksheet.Cell(1, 2).Value.Trim();
                                if (strVersion == "")
                                {
                                    strVersion = "0";
                                }

                                DataRow drNew;

                                for (int iRow = 4; iRow < 36; iRow++)
                                {
                                    if (Convert.ToString(worksheet.Cell(iRow, 1).Value) != "")
                                    {
                                        drNew = dtData.NewRow();

                                        var Days    = worksheet.Cell(iRow, 1).Value.Split('-');
                                        var MinDays = Days[0].Trim();
                                        var MaxDays = Days[1].Trim();

                                        drNew["VERSION"]         = strVersion;
                                        drNew["ENTITY_ID"]       = intEntityID;
                                        drNew["IS_SECURED_ID"]   = intIsSecuredID;
                                        drNew["MIN_DAYS"]        = MinDays;//worksheet.Cell(iRow, 1).Value;
                                        drNew["MAX_DAYS"]        = MaxDays;
                                        drNew["DEPLOYMENT_RATE"] = worksheet.Cell(iRow, 2).Value;
                                        drNew["CREATED_DATE"]    = DateTime.Now;
                                        drNew["CREATED_BY"]      = 1;

                                        dtData.Rows.Add(drNew);
                                    }
                                    else
                                    {
                                        break;
                                    }
                                }
                            }

                            string strMyConnection = Convert.ToString(System.Configuration.ConfigurationManager.ConnectionStrings["SP_PRICINGConnectionString"]);

                            if (arrSourceColumn != null && arrDestinationColumn != null && arrSourceColumn.Length == arrDestinationColumn.Length)
                            {
                                using (SqlBulkCopy bulkCopy = new SqlBulkCopy(strMyConnection))
                                {
                                    bulkCopy.DestinationTableName = strTableName;

                                    for (int i = 0; i < arrSourceColumn.Length; i++)
                                    {
                                        bulkCopy.ColumnMappings.Add(arrSourceColumn[i], arrDestinationColumn[i]);
                                    }
                                    bulkCopy.WriteToServer(dtData);
                                }
                                blnUploadStatus = true;
                                DataSet dsIV = new DataSet();
                                dsIV = General.ExecuteDataSet(objUploadFileMaster.ExtraProcedure);
                            }
                            else
                            {
                                blnUploadStatus = false;
                            }

                            if (blnUploadStatus)
                            {
                                ManageUploadFileInfo(0, file.FileName, strFilePath, blnUploadStatus, blnUploadDataStatus);

                                ViewBag.Message = "Imported successfully";
                            }

                            return(View(objPricingDeployment));
                        }
                    }
                    #endregion

                    #region Actual Deployment
                    else if (Command == "ADUpload")
                    {
                        if (file1 != null && file1.ContentLength > 0)
                        {
                            UploadFileMaster objUploadFileMaster = UploadFileMasterList.Find(delegate(UploadFileMaster oUploadFileMaster) { return(oUploadFileMaster.UploadTypeCode == "ADR"); });

                            string strFilePath  = System.Web.HttpContext.Current.Server.MapPath("~/Uploads/");
                            string strFileName  = Path.GetFileNameWithoutExtension(file1.FileName) + DateTime.Now.ToString("dd_mmm_yyyy_hh_mm");
                            string strExtension = Path.GetExtension(file1.FileName);

                            strFilePath += strFileName + strExtension;
                            file1.SaveAs(strFilePath);

                            FileInfo newFile = new FileInfo(strFilePath);

                            string   strSourceColumn = objUploadFileMaster.SourceColumn;
                            string[] arrSourceColumn = null;
                            if (strSourceColumn != "")
                            {
                                arrSourceColumn = strSourceColumn.Split('|');
                            }

                            DataTable dtData = new DataTable();

                            for (int i = 0; i < arrSourceColumn.Length; i++)
                            {
                                dtData.Columns.Add(arrSourceColumn[i]);
                            }

                            string   strDestinationColumn = objUploadFileMaster.DestinationColumn;
                            string[] arrDestinationColumn = null;

                            if (strDestinationColumn != "")
                            {
                                arrDestinationColumn = strDestinationColumn.Split('|');
                            }

                            string strTableName = objUploadFileMaster.TableName;

                            using (ExcelPackage xlPackage = new ExcelPackage(newFile))
                            {
                                ExcelWorksheet worksheet = xlPackage.Workbook.Worksheets[objUploadFileMaster.SheetName];

                                string strVersion = worksheet.Cell(1, 2).Value.Trim();
                                if (strVersion == "")
                                {
                                    strVersion = "0";
                                }

                                DataRow drNew;

                                for (int iRow = 4; iRow < 100; iRow++)
                                {
                                    if (Convert.ToString(worksheet.Cell(iRow, 1).Value) != "")
                                    {
                                        drNew = dtData.NewRow();

                                        var Days    = worksheet.Cell(iRow, 1).Value.Split(' ');
                                        var MinDays = Days[0].Trim();
                                        var MaxDays = Days[2].Trim();

                                        drNew["VERSION"]         = strVersion;
                                        drNew["MIN_DAYS"]        = MinDays;//worksheet.Cell(iRow, 1).Value;
                                        drNew["MAX_DAYS"]        = MaxDays;
                                        drNew["DEPLOYMENT_RATE"] = worksheet.Cell(iRow, 2).Value;
                                        drNew["CREATED_DATE"]    = DateTime.Now;
                                        drNew["CREATED_BY"]      = 1;

                                        dtData.Rows.Add(drNew);
                                    }
                                    else
                                    {
                                        break;
                                    }
                                }
                            }

                            string strMyConnection = Convert.ToString(System.Configuration.ConfigurationManager.ConnectionStrings["SP_PRICINGConnectionString"]);

                            if (arrSourceColumn != null && arrDestinationColumn != null && arrSourceColumn.Length == arrDestinationColumn.Length)
                            {
                                using (SqlBulkCopy bulkCopy = new SqlBulkCopy(strMyConnection))
                                {
                                    bulkCopy.DestinationTableName = strTableName;

                                    for (int i = 0; i < arrSourceColumn.Length; i++)
                                    {
                                        bulkCopy.ColumnMappings.Add(arrSourceColumn[i], arrDestinationColumn[i]);
                                    }
                                    bulkCopy.WriteToServer(dtData);
                                }
                                blnUploadStatus = true;
                                DataSet dsIV = new DataSet();
                                dsIV = General.ExecuteDataSet(objUploadFileMaster.ExtraProcedure);
                            }
                            else
                            {
                                blnUploadStatus = false;
                            }

                            if (blnUploadStatus)
                            {
                                ManageUploadFileInfo(0, file1.FileName, strFilePath, blnUploadStatus, blnUploadDataStatus);

                                ViewBag.Message = "Imported successfully";
                            }

                            return(View(objPricingDeployment));
                        }
                    }
                    #endregion

                    #region Pricing Deployment Download
                    else if (Command == "PDDownload")
                    {
                        UploadFileMaster objUploadFileMaster = UploadFileMasterList.Find(delegate(UploadFileMaster oUploadFileMaster) { return(oUploadFileMaster.UploadTypeCode == "PDR"); });
                        string           strFilePath         = System.Web.HttpContext.Current.Server.MapPath(objUploadFileMaster.TemplateFileName);

                        if (System.IO.File.Exists(strFilePath))
                        {
                            FileInfo fileinfo = new FileInfo(strFilePath);

                            Response.Clear();
                            Response.ClearHeaders();
                            Response.ClearContent();
                            Response.AddHeader("content-disposition", "attachment; filename=" + Path.GetFileName(strFilePath));
                            Response.AddHeader("Content-Type", "application/Excel");
                            Response.ContentType = "application/vnd.xls";
                            Response.AddHeader("Content-Length", fileinfo.Length.ToString());
                            Response.WriteFile(fileinfo.FullName);
                            Response.End();
                        }

                        return(View(objPricingDeployment));
                    }
                    #endregion

                    return(View());
                }
                else
                {
                    return(RedirectToAction("Login", "Login"));
                }
            }
            catch (Exception ex)
            {
                UserMaster objUserMaster = new UserMaster();
                objUserMaster = (UserMaster)Session["LoggedInUser"];
                LogError(ex.Message, ex.StackTrace, "UnderlyingCreationController", "PricingDeployment Post", objUserMaster.UserID);
                return(RedirectToAction("ErrorPage", "Login"));
            }
        }
Exemplo n.º 3
0
        public ActionResult HolidayMaster(string Command, HttpPostedFileBase file)
        {
            if (ValidateSession())
            {
            }
            FetchUploadFileMasterList();
            List <UploadFileMaster> UploadFileMasterList = (List <UploadFileMaster>)Session["UploadFileMasterList"];
            HolidayMaster           hMaster = new HolidayMaster();

            if (Command == "PDDownload")
            {
                UploadFileMaster objUploadFileMaster = UploadFileMasterList.Find(
                    delegate(UploadFileMaster oUploadFileMaster)
                {
                    return(oUploadFileMaster.UploadTypeCode == "HM");
                });
                string strFilePath = System.Web.HttpContext.Current.Server.MapPath(objUploadFileMaster.TemplateFileName);

                if (System.IO.File.Exists(strFilePath))
                {
                    FileInfo fileinfo = new FileInfo(strFilePath);

                    Response.Clear();
                    Response.ClearHeaders();
                    Response.ClearContent();
                    Response.AddHeader("content-disposition", "attachment; filename=" + Path.GetFileName(strFilePath));
                    Response.AddHeader("Content-Type", "application/Excel");
                    Response.ContentType = "application/vnd.xls";
                    Response.AddHeader("Content-Length", fileinfo.Length.ToString());
                    Response.WriteFile(fileinfo.FullName);
                    Response.End();
                }
            }
            if (Command == "PDUpload")
            {
                if (file != null && file.ContentLength > 0)
                {
                    UploadFileMaster objUploadFileMaster = UploadFileMasterList.Find(delegate(UploadFileMaster oUploadFileMaster) { return(oUploadFileMaster.UploadTypeCode == "HM"); });
                    string           strFilePath         = System.Web.HttpContext.Current.Server.MapPath("~/Uploads/");
                    string           strFileName         = Path.GetFileNameWithoutExtension(file.FileName) + DateTime.Now.ToString("dd_mmm_yyyy_hh_mm");
                    string           strExtension        = Path.GetExtension(file.FileName);

                    strFilePath += strFileName + strExtension;
                    file.SaveAs(strFilePath);

                    FileInfo newFile = new FileInfo(strFilePath);

                    string   strSourceColumn = objUploadFileMaster.SourceColumn;
                    string[] arrSourceColumn = null;
                    if (strSourceColumn != "")
                    {
                        arrSourceColumn = strSourceColumn.Split('|');
                    }

                    DataTable dtData = new DataTable();

                    for (int i = 0; i < arrSourceColumn.Length; i++)
                    {
                        dtData.Columns.Add(arrSourceColumn[i]);
                    }

                    string   strDestinationColumn = objUploadFileMaster.DestinationColumn;
                    string[] arrDestinationColumn = null;

                    if (strDestinationColumn != "")
                    {
                        arrDestinationColumn = strDestinationColumn.Split('|');
                    }

                    string strTableName = objUploadFileMaster.TableName;

                    using (ExcelPackage xlPackage = new ExcelPackage(newFile))
                    {
                        ExcelWorksheet worksheet = xlPackage.Workbook.Worksheets[objUploadFileMaster.SheetName];

                        string strVersion = worksheet.Cell(1, 2).Value.Trim();
                        if (strVersion == "")
                        {
                            strVersion = "0";
                        }

                        DataRow drNew;

                        for (int iRow = 2; iRow < 36; iRow++)
                        {
                            if (Convert.ToString(worksheet.Cell(iRow, 1).Value) != "")
                            {
                                drNew = dtData.NewRow();

                                var Reason       = worksheet.Cell(iRow, 1).Value;
                                var Holiday_Date = DateTime.FromOADate(double.Parse(worksheet.Cell(iRow, 2).Value));

                                drNew["REASON"]       = Reason;//worksheet.Cell(iRow, 1).Value;
                                drNew["HOLIDAY_DATE"] = Convert.ToDateTime(Holiday_Date);
                                drNew["VERSION"]      = 1;
                                drNew["ISACTIVE"]     = 1;
                                dtData.Rows.Add(drNew);
                            }
                            else
                            {
                                break;
                            }
                        }
                    }
                    string strMyConnection = Convert.ToString(System.Configuration.ConfigurationManager.ConnectionStrings["SP_PRICINGConnectionString"]);
                    if (arrSourceColumn != null && arrDestinationColumn != null && arrSourceColumn.Length == arrDestinationColumn.Length)
                    {
                        using (SqlBulkCopy bulkCopy = new SqlBulkCopy(strMyConnection))
                        {
                            bulkCopy.DestinationTableName = strTableName;

                            for (int i = 0; i < arrSourceColumn.Length; i++)
                            {
                                bulkCopy.ColumnMappings.Add(arrSourceColumn[i], arrDestinationColumn[i]);
                            }
                            bulkCopy.WriteToServer(dtData);
                        }
                        blnUploadStatus = true;
                    }
                    else
                    {
                        blnUploadStatus = false;
                    }
                    if (blnUploadStatus)
                    {
                        ViewBag.Message = "Imported successfully";
                    }

                    return(View(hMaster));
                }
            }
            return(View(hMaster));
        }