public ActionResult GetCodeName(string values)
        {
            try
            {
                var      id    = values.Split(',');
                int      rId   = Convert.ToInt32(id.FirstOrDefault());
                NewChart datas = new NewChart();

                datas = _newChartService.All().ToList().FirstOrDefault(x => x.AcSyscode == rId);
                _newChartService.Save();

                return(Json(datas, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public ActionResult UploadExcel()
        {
            //RBACUser rUser = new RBACUser(Session["UserName"].ToString());
            //if (!rUser.HasPermission("MonthlyContribution_Import"))
            //{
            //    return Json("I", JsonRequestBehavior.AllowGet);
            //}
            try
            {
                var UploadedFile = Request.Files["file"];
                int AcSyscode    = Convert.ToInt32(Request.Form["AcSyscode"]);

                string BranchCode = "";
                if (!string.IsNullOrEmpty(Session["BranchCode"] as string))
                {
                    BranchCode = Session["BranchCode"].ToString();
                }

                string          fileLocation  = "";
                string          filePath      = "";
                string          FileName      = "";
                string[]        fileList      = null;
                string          fileExtension = "";
                List <NewChart> TNChartList   = new List <NewChart>();

                filePath = ConfigurationManager.AppSettings["UPFilePath"];

                DataSet ds = new DataSet();
                if (UploadedFile.ContentLength > 0)
                {
                    FileName      = Path.GetFileName(UploadedFile.FileName);
                    fileExtension = System.IO.Path.GetExtension(FileName);
                    fileLocation  = Path.Combine(Server.MapPath(filePath), FileName);

                    if (fileExtension == ".xls" || fileExtension == ".xlsx")
                    {
                        fileList = System.IO.Directory.GetFiles(Server.MapPath(filePath));
                        foreach (string file in fileList)
                        {
                            System.IO.File.Delete(file);
                        }

                        UploadedFile.SaveAs(fileLocation);

                        string excelConnectionString = string.Empty;
                        excelConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;OLE DB Services=-4;Data Source=" + fileLocation + ";Extended Properties=\"Excel 12.0;HDR=Yes;IMEX=2\"";
                        //connection String for xls file format.
                        if (fileExtension == ".xls")
                        {
                            excelConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + fileLocation + ";Extended Properties=\"Excel 8.0;HDR=Yes;IMEX=2\"";
                        }
                        //connection String for xlsx file format.
                        else if (fileExtension == ".xlsx")
                        {
                            excelConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;OLE DB Services=-4;Data Source=" + fileLocation + ";Extended Properties=\"Excel 12.0;HDR=Yes;IMEX=2\"";
                        }

                        //Create Connection to Excel work book and add oledb namespace
                        using (OleDbConnection excelConnection = new OleDbConnection(excelConnectionString))
                        {
                            excelConnection.Open();
                            DataTable dt = new DataTable();

                            dt = excelConnection.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
                            if (dt == null)
                            {
                                return(null);
                            }

                            String[] excelSheets = new String[dt.Rows.Count];
                            int      t           = 0;
                            //excel data saves in temp file here.
                            foreach (DataRow row in dt.Rows)
                            {
                                excelSheets[t] = row["TABLE_NAME"].ToString();
                                t++;
                            }

                            using (OleDbConnection excelConnection1 = new OleDbConnection(excelConnectionString))
                            {
                                string query = string.Format("Select * from [{0}]", excelSheets[0]);
                                using (OleDbDataAdapter dataAdapter = new OleDbDataAdapter(query, excelConnection1))
                                {
                                    dataAdapter.Fill(ds);
                                }
                            }
                        }
                    }
                    if (fileExtension.ToString().ToLower().Equals(".xml"))
                    {
                        fileList = System.IO.Directory.GetFiles(Server.MapPath(filePath));
                        foreach (string file in fileList)
                        {
                            System.IO.File.Delete(file);
                        }

                        Request.Files["FileUpload"].SaveAs(fileLocation);
                        XmlTextReader xmlreader = new XmlTextReader(fileLocation);
                        ds.ReadXml(xmlreader);
                        xmlreader.Close();
                        ds.Dispose();
                    }
                    List <NewChart> LstImpFlie = new List <NewChart>();
                    StringBuilder   ValdtMsg   = new StringBuilder();
                    if (ds != null)
                    {
                        var FDT = RemoveAllNullRowsFromDataTable(ds.Tables[0]);
                        LstImpFlie = GetNChartFromDT(FDT);
                        //ValdtMsg.Append(ValidateFileFiledFormat(FDT));
                    }
                    else
                    {
                        ValdtMsg.Append("Cannot Read File Properly!!");
                    }

                    if (ValdtMsg.Length > 0)
                    {
                        return(Json(ValdtMsg.ToString(), JsonRequestBehavior.AllowGet));
                    }
                    using (var transaction = new TransactionScope())
                    {
                        try
                        {
                            foreach (var nItem in LstImpFlie)
                            {
                                var parChart   = _newChartService.All().FirstOrDefault(x => x.AcSyscode == AcSyscode);
                                var parLbl     = _levelLenService.All().FirstOrDefault(x => x.LevelNo == parChart.LevelNo).LevelNo + 1;
                                var sep        = _minLevService.All().FirstOrDefault().Sepa;
                                var LAcSysCode = _newChartService.All().OrderByDescending(x => x.AcSyscode).Select(s => s.AcSyscode).FirstOrDefault();

                                NewChart chart = new NewChart()
                                {
                                    Accode       = GetAccNewCode(parChart.Accode.ToString(), sep, parLbl, Convert.ToInt32(parChart.AcSyscode)),
                                    AcName       = nItem.AcName,
                                    ParentCode   = parChart.AcSyscode,
                                    LevelNo      = parLbl,
                                    AcSyscode    = LAcSysCode + 1,
                                    B_S          = false,
                                    I_S          = false,
                                    T_B          = false,
                                    ParentAcCode = parChart.Accode,
                                    AccType      = "",
                                    OldCode      = nItem.OldCode,
                                    BranchCode   = BranchCode
                                };

                                _newChartService.Add(chart);
                                _newChartService.Save();
                            }
                            transaction.Complete();
                            return(Json("0", JsonRequestBehavior.AllowGet));
                        }
                        catch (Exception)
                        {
                            transaction.Dispose();
                            return(Json("1", JsonRequestBehavior.AllowGet));
                        }
                        finally
                        {
                            ds.Clear();
                            ds.Dispose();
                            ValdtMsg.Length = 0;
                            ValdtMsg.Clear();
                        }
                    }
                }
                else
                {
                    return(Json("2", JsonRequestBehavior.AllowGet));
                }
            }
            catch (Exception ex)
            {
                return(Json(ex.Message.ToString(), JsonRequestBehavior.AllowGet));
            }
        }
        public ActionResult AddNewNode(NewChart model)
        {
            try
            {
                string msg = "";
                if (model.IsModifyFor == "Sa")
                {
                    RBACUser rUser = new RBACUser(Session["UserName"].ToString());
                    if (!rUser.HasPermission("ChartOfAccounts_Insert"))
                    {
                        msg = "No Add Permission For This User !!";
                        return(Json(new { success = false, msg = msg }, JsonRequestBehavior.AllowGet));
                    }
                    var parChart   = _newChartService.All().FirstOrDefault(x => x.AcSyscode == model.AcSyscode);
                    var parLbl     = _levelLenService.All().FirstOrDefault(x => x.LevelNo == parChart.LevelNo).LevelNo + 1;
                    var sep        = _minLevService.All().FirstOrDefault().Sepa;
                    var LAcSysCode = _newChartService.All().OrderByDescending(x => x.AcSyscode).Select(s => s.AcSyscode).FirstOrDefault();

                    NewChart chart = new NewChart()
                    {
                        Accode       = GetAccNewCode(parChart.Accode.ToString(), sep, parLbl, Convert.ToInt32(parChart.AcSyscode)),
                        AcName       = model.NewAcName,
                        ParentCode   = parChart.AcSyscode,
                        LevelNo      = parLbl,
                        AcSyscode    = LAcSysCode + 1,
                        B_S          = false,
                        I_S          = false,
                        T_B          = false,
                        ParentAcCode = parChart.Accode,
                        AccType      = "",
                        OldCode      = model.NewOldCode
                    };

                    _newChartService.Add(chart);

                    parChart.T_B = true;
                    _newChartService.Update(parChart);

                    _newChartService.Save();
                    msg = "Save successfully!";
                    return(Json(new { success = true, msg = msg }, JsonRequestBehavior.AllowGet));
                }
                else
                {
                    RBACUser rUser = new RBACUser(Session["UserName"].ToString());
                    if (!rUser.HasPermission("ChartOfAccounts_Update"))
                    {
                        msg = "No Modify Permission For This User !!";
                        return(Json(new { success = false, msg = msg }, JsonRequestBehavior.AllowGet));
                    }
                    var parChart = _newChartService.All().FirstOrDefault(x => x.AcSyscode == model.AcSyscode);
                    parChart.AcName  = model.NodeName;
                    parChart.OldCode = model.OldCode;

                    _newChartService.Update(parChart);
                    _newChartService.Save();
                    msg = "Modify successfully!";
                    return(Json(new { success = true, msg = msg }, JsonRequestBehavior.AllowGet));
                }
            }
            catch (Exception ex)
            {
                return(Json(new { success = false, msg = ex }, JsonRequestBehavior.AllowGet));
            }
        }