Пример #1
0
 public ActionResult Edit([Bind(Include = "CONO,INCDATE,INCCTRY,CONSTCODE,INTYPE,PRINOBJ,PRINOBJStr,CONAME,PINDCODE,SINDCODE,WEB,COSTAT,COSTATD,FILETYPE,FILELOC,SEALLOC,STAFFCODE,SPECIALRE,SPECIALREBool,ARRE,ARREBool,CMMT,CMMTStr,REM,SXCODE,SXNAME,REFCODE,SEQNO,STAMP")] CSCOMSTR cSCOMSTR)
 {
     if (ModelState.IsValid)
     {
         ASIDBConnection newdb = new ASIDBConnection();
         db.Entry(cSCOMSTR).State = EntityState.Modified;
         try
         {
             CSCOMSTR curRec = newdb.CSCOMSTRs.Find(cSCOMSTR.CONO);
             if (curRec.STAMP == cSCOMSTR.STAMP)
             {
                 cSCOMSTR.STAMP = cSCOMSTR.STAMP + 1;
                 db.SaveChanges();
                 return(RedirectToAction("Index"));
             }
             else
             {
                 ModelState.AddModelError(string.Empty, "Record is modified");
             }
         }
         catch (Exception e)
         {
             ModelState.AddModelError(string.Empty, e.Message);
         }
         finally
         {
             newdb.Dispose();
         }
     }
     ViewBag.INCCTRY   = new SelectList(db.HKCTRies, "CTRYCODE", "CTRYDESC", cSCOMSTR.INCCTRY);
     ViewBag.CONSTCODE = new SelectList(db.HKCONSTs, "CONSTCODE", "CONSTDESC", cSCOMSTR.CONSTCODE);
     ViewBag.STAFFCODE = new SelectList(db.HKSTAFFs, "STAFFCODE", "STAFFDESC", cSCOMSTR.STAFFCODE);
     return(View(cSCOMSTR));
 }
Пример #2
0
        private CSCOAR createNextYearRecord(CSCOAR curRec)
        {
            string   sid      = curRec.CONO;
            CSCOMSTR cSCOMSTR = db.CSCOMSTRs.Find(sid);

            DateTime indate = cSCOMSTR.INCDATE; // get incorporate date to determine AR due
            int      yy     = indate.Year;
            int      mm     = indate.Month;
            int      dd     = indate.Day;

            CSCOAR newRec = new CSCOAR();

            newRec.ARNO   = (short)(curRec.ARNO + 1); // WARNING assuming the next ARNO is available
            newRec.LASTAR = curRec.FILEDAR;
            newRec.CONO   = curRec.CONO;
            int lyy = newRec.LASTAR?.Year ?? yy;

            lyy = lyy + 1; // add 1 year to last year File AR Date

            newRec.ARTOFILE = new DateTime(lyy, mm, dd);

            dd = 1; // reminder is set to 1 month prior to AR Due Date and on the 1st
            if (mm == 1)
            {
                mm = 12; lyy = lyy - 1;
            }
            else
            {
                mm = mm - 1;
            };
            newRec.REMINDER1 = new DateTime(lyy, mm, dd);
            newRec.STAMP     = 1;
            return(newRec);
        }
Пример #3
0
        public ActionResult DeleteConfirmed(string id)
        {
            CSCOMSTR cSCOMSTR = db.CSCOMSTRs.Find(MyHtmlHelpers.ConvertByteStrToId(id));

            db.CSCOMSTRs.Remove(cSCOMSTR);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Пример #4
0
        // GET: CSCOMSTRs/Create
        public ActionResult Create()
        {
            CSCOMSTR cSCOMSTR = new CSCOMSTR();

            ViewBag.INCCTRY   = new SelectList(db.HKCTRies, "CTRYCODE", "CTRYDESC");
            ViewBag.CONSTCODE = new SelectList(db.HKCONSTs, "CONSTCODE", "CONSTDESC");
            ViewBag.STAFFCODE = new SelectList(db.HKSTAFFs, "STAFFCODE", "STAFFDESC");
            cSCOMSTR.STAMP    = 1; // set initial stamp
            cSCOMSTR.SEQNO    = 1; // set inital seqno
            return(View("Create1", cSCOMSTR));
        }
Пример #5
0
        // GET: CSCOMSTRs/Details/5
        public ActionResult Details(string id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            CSCOMSTR cSCOMSTR = db.CSCOMSTRs.Find(MyHtmlHelpers.ConvertByteStrToId(id));

            if (cSCOMSTR == null)
            {
                return(HttpNotFound());
            }
            return(View(cSCOMSTR));
        }
Пример #6
0
        private bool UpdateCompany(CSCONAME cSCONAME)
        {
            bool result = false;

            CSCOMSTR cSCOMSTR = db.CSCOMSTRs.Find(cSCONAME.CONO);

            if (cSCOMSTR != null)
            {
                cSCOMSTR.CONAME          = cSCONAME.CONAME;
                cSCOMSTR.STAMP           = cSCOMSTR.STAMP + 1;
                db.Entry(cSCOMSTR).State = EntityState.Modified;
                result = true;
            }

            return(result);
        }
Пример #7
0
        public ActionResult Create([Bind(Include = "CONO,INCDATE,INCCTRY,CONSTCODE,INTYPE,PRINOBJ,PRINOBJStr,CONAME,PINDCODE,SINDCODE,WEB,COSTAT,COSTATD,FILETYPE,FILELOC,SEALLOC,STAFFCODE,SPECIALRE,SPECIALREBool,ARRE,ARREBool,CMMT,CMMTStr,REM,SXCODE,SXNAME,REFCODE,SEQNO,STAMP")] CSCOMSTR cSCOMSTR)
        {
            if (ModelState.IsValid)
            {
                cSCOMSTR.STAMP = 1; // set initial stamp
                cSCOMSTR.SEQNO = 1; // set inital seqno
                db.CSCOMSTRs.Add(cSCOMSTR);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.INCCTRY   = new SelectList(db.HKCTRies, "CTRYCODE", "CTRYDESC", cSCOMSTR.INCCTRY);
            ViewBag.CONSTCODE = new SelectList(db.HKCONSTs, "CONSTCODE", "CONSTDESC", cSCOMSTR.CONSTCODE);
            ViewBag.STAFFCODE = new SelectList(db.HKSTAFFs, "STAFFCODE", "STAFFDESC", cSCOMSTR.STAFFCODE);
            return(View(cSCOMSTR));
        }
Пример #8
0
        // GET: CSCOMSTRs/Delete/5
        public ActionResult Delete(string id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            CSCOMSTR cSCOMSTR = db.CSCOMSTRs.Find(MyHtmlHelpers.ConvertByteStrToId(id));

            if (cSCOMSTR == null)
            {
                return(HttpNotFound());
            }
            ViewBag.INCCTRY   = new SelectList(db.HKCTRies, "CTRYCODE", "CTRYDESC", cSCOMSTR.INCCTRY);
            ViewBag.CONSTCODE = new SelectList(db.HKCONSTs, "CONSTCODE", "CONSTDESC", cSCOMSTR.CONSTCODE);
            ViewBag.STAFFCODE = new SelectList(db.HKSTAFFs, "STAFFCODE", "STAFFDESC", cSCOMSTR.STAFFCODE);
            return(View(cSCOMSTR));
        }
Пример #9
0
        public PartialViewResult Search()
        {
            CSCOMSTR searchRec = null;

            //searchRec.CONO = pSearchCode;
            //searchRec.CONAME = pSearchName;
            if (Session["SearchRec"] != null)
            {
                searchRec = (CSCOMSTR)Session["SearchRec"];
            }
            else
            {
                searchRec = new CSCOMSTR();
            }
            ViewBag.STAFFCODE = new SelectList(db.HKSTAFFs, "STAFFCODE", "STAFFDESC");
            return(PartialView("Partial/Search", searchRec));
        }
Пример #10
0
        private bool UpdateCompany(CSCOSTAT cSCOSTAT)
        {
            bool result = false;

            CSCOMSTR cSCOMSTR = db.CSCOMSTRs.Find(cSCOSTAT.CONO);

            if (cSCOMSTR != null)
            {
                cSCOMSTR.COSTAT          = cSCOSTAT.COSTAT;
                cSCOMSTR.FILELOC         = cSCOSTAT.FILELOC;
                cSCOMSTR.FILETYPE        = cSCOSTAT.FILETYPE;
                cSCOMSTR.COSTATD         = cSCOSTAT.SDATE;
                cSCOMSTR.SEALLOC         = cSCOSTAT.SEALLOC;
                cSCOMSTR.STAMP           = cSCOMSTR.STAMP + 1;
                db.Entry(cSCOMSTR).State = EntityState.Modified;
                result = true;
            }

            return(result);
        }
Пример #11
0
        // GET: CSCOMSTRs
        public ActionResult Index(int?page)
        {
            string pSearchCode  = "";
            string pSearchName  = "";
            string pSearchStaff = "";

            if (Session["SearchRec"] != null)
            {
                CSCOMSTR searchRec = (CSCOMSTR)(Session["SearchRec"]);
                pSearchCode  = searchRec.CONO ?? "";
                pSearchName  = searchRec.CONAME ?? "";
                pSearchStaff = searchRec.STAFFCODE ?? "";
            }

            IQueryable <CSCOMSTR> cSCOMSTRs = db.CSCOMSTRs;

            if (pSearchCode != "")
            {
                cSCOMSTRs = cSCOMSTRs.Where(x => x.CONO.Contains(pSearchCode));
            }
            ;
            if (pSearchName != "")
            {
                cSCOMSTRs = cSCOMSTRs.Where(x => x.CONAME.Contains(pSearchName));
            }
            ;
            if (pSearchStaff != "")
            {
                cSCOMSTRs = cSCOMSTRs.Where(x => x.STAFFCODE == pSearchStaff);
            }
            ;

            var curRec = cSCOMSTRs.OrderBy(n => n.CONAME).Include(c => c.HKCTRY).Include(c => c.HKCONST).Include(c => c.HKSTAFF);

            return(View("Index", curRec.ToList().ToPagedList(page ?? 1, 30)));
            //return View("IndexNG2", cSCOMSTRs.ToList());
        }
Пример #12
0
        public ActionResult Create([Bind(Include = "TRNO,VDATE,CONO,COADDRID,ATTN,REM,SEQNO,POSTBool,STAMP")] CSCNM cSCNM)
        {
            if (ModelState.IsValid)
            {
                SALASTNO serialTbl = db.SALASTNOes.Find("CSCN");
                if (serialTbl != null)
                {
                    CSCOMSTR cSCOMSTR = db.CSCOMSTRs.Find(cSCNM.CONO);
                    if (cSCOMSTR != null)
                    {
                        try
                        {
                            string prefix  = serialTbl.LASTPFIX;
                            int    MaxNo   = serialTbl.LASTNOMAX;
                            bool   AutoGen = serialTbl.AUTOGEN == "Y";
                            if (AutoGen)
                            {
                                serialTbl.LASTNO          = serialTbl.LASTNO + 1;
                                cSCNM.TRNO                = serialTbl.LASTNO.ToString("D10");
                                serialTbl.STAMP           = serialTbl.STAMP + 1;
                                db.Entry(serialTbl).State = EntityState.Modified;
                            }
                            cSCNM.STAMP = 1;

                            // increment company seqno count before using it in transaction
                            cSCOMSTR.SEQNO = cSCOMSTR.SEQNO + 1;
                            cSCOMSTR.STAMP = cSCOMSTR.STAMP + 1;

                            cSCNM.SEQNO = cSCOMSTR.SEQNO;
                            db.Entry(cSCOMSTR).State = EntityState.Modified;

                            db.CSCNMs.Add(cSCNM);
                            db.SaveChanges();

                            //return Edit(MyHtmlHelpers.ConvertIdToByteStr(cSCNM.TRNO), 1);
                            return(RedirectToAction("Edit", new { id = MyHtmlHelpers.ConvertIdToByteStr(cSCNM.TRNO), page = 1 }));
                        }
                        catch (DbEntityValidationException dbEx)
                        {
                            foreach (var validationErrors in dbEx.EntityValidationErrors)
                            {
                                foreach (var validationError in validationErrors.ValidationErrors)
                                {
                                    //string message = string.Format("{0}:{1}",
                                    //    validationErrors.Entry.Entity.ToString(),
                                    //   validationError.ErrorMessage);
                                    // raise a new exception nesting
                                    // the current instance as InnerException
                                    ModelState.AddModelError(validationError.PropertyName, validationError.ErrorMessage);
                                }
                            }
                        }
                        catch (DbUpdateException ex)
                        {
                            UpdateException updateException = (UpdateException)ex.InnerException;
                            if (updateException != null)
                            {
                                if (updateException.InnerException != null)
                                {
                                    var sqlException = (FirebirdSql.Data.FirebirdClient.FbException)updateException.InnerException;

                                    foreach (var error in sqlException.Errors)
                                    {
                                        if (error.Message != null)
                                        {
                                            ModelState.AddModelError(string.Empty, error.Message);
                                        }
                                    }
                                }
                                else
                                {
                                    ModelState.AddModelError(string.Empty, updateException.Message);
                                }
                            }
                            else
                            {
                                ModelState.AddModelError(string.Empty, updateException.Message);
                            }
                        }
                        catch (Exception e)
                        {
                            db.CSCNMs.Remove(cSCNM);
                            ModelState.AddModelError(string.Empty, e.Message);
                        }
                        finally
                        {
                        }
                    }
                    else
                    {
                        ModelState.AddModelError(string.Empty, "Unable to find company #");
                    }
                }
            }


            ViewBag.CSCND    = db.CSCNDs.Where(x => x.TRNO == cSCNM.TRNO);
            ViewBag.CONAME   = db.CSCOMSTRs.Where(x => x.CONO == cSCNM.CONO).Select(y => y.CONAME).FirstOrDefault();
            ViewBag.CONO     = new SelectList(db.CSCOMSTRs.Select(x => new { CONO = x.CONO, CONAME = x.CONAME + "  (" + x.CONO + ")" }).OrderBy(y => y.CONAME), "CONO", "CONAME", cSCNM.CONO);
            ViewBag.ATTNDESC = new SelectList(db.CSCOPICs.Where(x => x.CONO == cSCNM.CONO).Select(x => new { PRSNAME = x.CSPR.PRSNAME, PRSDESC = x.CSPR.PRSNAME }).OrderBy(y => y.PRSDESC), "PRSNAME", "PRSDESC", cSCNM.ATTN);
            ViewBag.COADDR   = new SelectList(db.CSCOADDRs.Where(x => x.CONO == cSCNM.CONO).Select(x => new { COADDR = x.CONO + "|" + x.ADDRID, COADDRDESC = x.ADDRTYPE + " | " + x.MAILADDR + " | " + x.ADDR1 + " " + x.ADDR2 + " " + x.ADDR3 }), "COADDR", "COADDRDESC", cSCNM.COADDR);

            ViewBag.Title = "Create Discounted Bill";
            return(View("Edit", cSCNM));
        }
Пример #13
0
        public ActionResult Create([Bind(Include = "JOBNO,VDATE,CONO,REM,JOBSTAFF,JOBPOST,CASECNT,OKCNT,COMPLETE,COMPLETED,STAMP")] CSJOBM cSJOBM)
        {
            if (ModelState.IsValid)
            {
                SALASTNO serialTbl = db.SALASTNOes.Find("CSJOB");
                if (serialTbl != null)
                {
                    CSCOMSTR cSCOMSTR = db.CSCOMSTRs.Find(cSJOBM.CONO);
                    if (cSCOMSTR != null)
                    {
                        try
                        {
                            string prefix  = serialTbl.LASTPFIX;
                            int    MaxNo   = serialTbl.LASTNOMAX;
                            bool   AutoGen = serialTbl.AUTOGEN == "Y";
                            serialTbl.LASTNO = serialTbl.LASTNO + 1;
                            cSJOBM.JOBNO     = serialTbl.LASTNO.ToString("D10");

                            serialTbl.STAMP           = serialTbl.STAMP + 1;
                            db.Entry(serialTbl).State = EntityState.Modified;


                            db.CSJOBMs.Add(cSJOBM);

                            db.SaveChanges();
                            //return Edit(MyHtmlHelpers.ConvertIdToByteStr(cSRCP.TRNO), 1);
                            return(RedirectToAction("Edit", new { id = MyHtmlHelpers.ConvertIdToByteStr(cSJOBM.JOBNO), page = 1 }));
                        }
                        catch (DbEntityValidationException dbEx)
                        {
                            foreach (var validationErrors in dbEx.EntityValidationErrors)
                            {
                                foreach (var validationError in validationErrors.ValidationErrors)
                                {
                                    //string message = string.Format("{0}:{1}",
                                    //    validationErrors.Entry.Entity.ToString(),
                                    //   validationError.ErrorMessage);
                                    // raise a new exception nesting
                                    // the current instance as InnerException
                                    ModelState.AddModelError(validationError.PropertyName, validationError.ErrorMessage);
                                }
                            }
                        }
                        catch (DbUpdateException ex)
                        {
                            UpdateException updateException = (UpdateException)ex.InnerException;
                            if (updateException != null)
                            {
                                if (updateException.InnerException != null)
                                {
                                    var sqlException = (FirebirdSql.Data.FirebirdClient.FbException)updateException.InnerException;

                                    foreach (var error in sqlException.Errors)
                                    {
                                        if (error.Message != null)
                                        {
                                            ModelState.AddModelError(string.Empty, error.Message);
                                        }
                                    }
                                }
                                else
                                {
                                    ModelState.AddModelError(string.Empty, updateException.Message);
                                }
                            }
                            else
                            {
                                ModelState.AddModelError(string.Empty, updateException.Message);
                            }
                        }
                        catch (Exception e)
                        {
                            ModelState.AddModelError(string.Empty, e.Message);
                        }
                        finally
                        {
                        }
                    }
                    else
                    {
                        ModelState.AddModelError(string.Empty, "Unable to find company #");
                    }
                }
            }

            ViewBag.CONO     = new SelectList(db.CSCOMSTRs.Select(x => new { CONO = x.CONO, CONAME = x.CONAME + "  (" + x.CONO + ")" }).OrderBy(y => y.CONAME), "CONO", "CONAME", cSJOBM.CONO);
            ViewBag.JOBSTAFF = new SelectList(db.HKSTAFFs, "STAFFCODE", "STAFFDESC", cSJOBM.JOBSTAFF);
            ViewBag.Title    = "Create New Job Taking";
            return(View("Edit", cSJOBM));
        }
Пример #14
0
 public ActionResult SearchPost([Bind(Include = "CONO,CONAME,STAFFCODE")] CSCOMSTR cSCOMSTR)
 {
     Session["SearchRec"] = cSCOMSTR;
     return(Index(1));
 }
Пример #15
0
        public ActionResult Index(HttpPostedFileBase postedFile, string dbTableName, string dbKey, string localKey)

        {
            string filePath = string.Empty;

            if (postedFile != null)

            {
                string path = Server.MapPath("~/Uploads/");

                if (!Directory.Exists(path))

                {
                    Directory.CreateDirectory(path);
                }



                filePath = path + Path.GetFileName(postedFile.FileName);

                string extension = Path.GetExtension(postedFile.FileName);

                string keyId = "";

                string templine = "";

                postedFile.SaveAs(filePath);


                IEnumerable <dynamic> csRecs = null;

                DataTable refTable;
                string    usefile = "";

                if (dbTableName == "CSCOMSTR")
                {
                    csRecs = db.CSCOMSTRs.ToList();

                    //whereFunc = item => item.CONO == $"{keyId}";
                    //orderByFunc = item => item.CONAME;
                }
                else if (dbTableName == "CSCOSTAT")
                {
                    csRecs  = db.CSCOSTATs.ToList();
                    usefile = path + "cs_company1.csv";
                }
                else if (dbTableName == "CSCOAR")
                {
                    csRecs  = db.CSCOARs.ToList();
                    usefile = path + "cs_company1.csv";
                }



                //Create a DataTable.

                DataTable dt = new DataTable();

                //addColumns(dt, companycol);
                //dt.Columns.AddRange(new DataColumn[3] { new DataColumn("CaseFeeId", typeof(int)),

                //                new DataColumn("CaseFeeCode", typeof(string)),

                //                new DataColumn("CaseFeeDesc",typeof(string)) });



                //Read the contents of CSV file.

                string csvData = System.IO.File.ReadAllText(filePath);



                //Execute a loop over the rows.
                bool    IsHeader = true;
                int     rowcnt   = 0;
                DataRow curRow   = null;
                foreach (string row in csvData.Split('\n'))

                {
                    if ((!IsHeader) && (!string.IsNullOrEmpty(row)))

                    {
                        curRow = dt.Rows.Add();
                        rowcnt++;
                        int i = 1;



                        //Execute a loop over the columns.

                        //foreach (string cell in row.Split('\t'))
                        foreach (string cell in row.Split('|'))
                        {
                            try
                            {
                                dt.Rows[dt.Rows.Count - 1][i] = cell ?? "";
                            }
                            catch (Exception e)
                            {
                                Console.WriteLine(rowcnt.ToString() + " | " + e.Message);
                            }
                            finally
                            {
                                i++;
                            }
                        }

                        if ((dbTableName == "CSCOSTAT") || (dbTableName == "CSCOAR"))
                        {
                            string myDateStr = (string)curRow["status_date"];
                            string mySortStr = myDateStr.Split('/')[2] + myDateStr.Split('/')[1] + myDateStr.Split('/')[0];
                            curRow["sort_date"] = mySortStr;
                        }

                        if ((localKey.Length > 0) && (DBNull.Value != curRow[localKey]))
                        {
                            keyId = (string)curRow[localKey] ?? "";

                            if (dbTableName == "CSCOMSTR")
                            {
                                CSCOMSTR csRec = null;
                                Func <CSCOMSTR, bool>   whereFunc   = item => item.CONO == $"{keyId}";
                                Func <CSCOMSTR, Object> orderByFunc = item => item.CONAME;

                                //csRec = ((List<CSCOMSTR>) csRecs).Where(whereFunc).FirstOrDefault();
                                csRec = ((List <CSCOMSTR>)csRecs).Where(item => item.CONO == keyId).FirstOrDefault();
                                if (csRec == null)
                                {
                                    curRow["New"] = "***";
                                }
                                else if (csRec.CONAME != (string)curRow["company_name"])
                                {
                                    curRow["New"] = "**";
                                }
                                else if (csRec.INTYPE != (string)curRow["company_intype"])
                                {
                                    curRow["New"] = "*";
                                }
                                else if (csRec.CONSTCODE != (string)curRow["company_constitution"])
                                {
                                    curRow["New"] = "*";
                                }

                                if (DBNull.Value != curRow["company_staffid"])
                                {
                                    curRow["company_staffid"] =
                                        convertStaff((string)curRow["company_staffid"]);
                                }


                                if (DBNull.Value != curRow["company_constitution"])
                                {
                                    curRow["company_constitution"] =
                                        convertConst((string)curRow["company_constitution"]);
                                }

                                if (DBNull.Value != curRow["company_country"])
                                {
                                    curRow["company_country"] =
                                        convertCountry((string)curRow["company_country"]);
                                }
                            }

                            //SortOrder sortOrder = SortOrder.Descending;

                            //if (sortOrder == SortOrder.Ascending)
                            //    orderByFunc = item => item.CONO;
                            //else if (sortOrder == SortOrder.Descending)
                            //    orderByFunc = item => item.CONAME;
                            //db.CSCOMSTRs.OrderBy(orderByFunc);
                        }
                    }
                    else
                    {
                        if (IsHeader)
                        {
                            IsHeader = false;
                            List <string> myCol = new List <string>();
                            myCol.Add("New");

                            foreach (string cell in row.Split('|'))
                            {
                                try
                                {
                                    myCol.Add(cell);
                                }
                                catch (Exception e)
                                {
                                    Console.WriteLine(rowcnt.ToString() + " | " + e.Message);
                                }
                                finally
                                {
                                }
                            }
                            if ((dbTableName == "CSCOSTAT") || (dbTableName == "CSCOAR"))
                            {
                                myCol.Add("sort_date");
                            }

                            string[] myArray = new string[myCol.Count];
                            for (int c = 0; c < myCol.Count; c++)
                            {
                                myArray[c] = myCol[c];
                            }
                            addColumns(dt, myArray);
                        }
                    }
                }
                var datarow = dt.AsEnumerable();

                if (dbTableName == "CSCOAR")
                {
                    datarow = datarow.OrderBy(x => x.Field <string>("company_id")).ThenBy(n => n.Field <int>("ar_id")).Select(x => x);

                    refTable = OpenTable(usefile);
                    var csRefs = refTable.AsEnumerable();


                    int      idx  = 0;
                    int      coid = 0;
                    string   cono = "";
                    DateTime sdate;
                    CSCOAR   csRec = null;
                    foreach (DataRow row in datarow)
                    {
                        templine = (string)row["company_id"];
                        coid     = int.Parse(templine);
                        cono     = null;
                        try
                        {
                            var corec = csRefs.Where(x => x.Field <int?>("company_id") == coid).FirstOrDefault();
                            if (corec != null)
                            {
                                cono = (string)corec["company_no"];
                            }
                            else
                            {
                                cono = null;
                            }

                            if (cono != null)
                            {
                                datarow.ElementAt(idx)["New"] = cono;

                                sdate = DateTime.Parse((string)(datarow.ElementAt(idx)["ar_date"]));
                                csRec = ((List <CSCOAR>)csRecs).Where(item => item.CONO == cono && item.ARTOFILE == sdate).FirstOrDefault();
                                if (csRec != null)
                                {
                                    datarow.ElementAt(idx)[7] = "Exist";
                                }
                                else
                                {
                                    CSCOAR cSCOAR = new CSCOAR();
                                    try
                                    {
                                        ModelState.Clear();

                                        cSCOAR.STAMP    = 999;
                                        cSCOAR.CONO     = cono;
                                        cSCOAR.ARTOFILE = sdate;
                                        // cSCOAR.SUBMITDATE = DateTime.Parse((string)row["ar_submissiondate"]);
                                        cSCOAR.REMINDER1 = DateTime.Parse((string)row["ar_reminderdate"]);
                                        cSCOAR.FILEDAR   = DateTime.Parse((string)row["ar_fileddate"]);

                                        if (ModelState.IsValid)
                                        {
                                            int?lastRowNo = 0;
                                            try
                                            {
                                                lastRowNo = db.CSCOARs.Where(m => m.CONO == cSCOAR.CONO).Max(n => n.ARNO);
                                            }
                                            catch (Exception e) { lastRowNo = -1; }
                                            finally { };


                                            cSCOAR.ARNO = (short)((lastRowNo ?? 0) + 1);
                                            datarow.ElementAt(idx)[6] = cSCOAR.ARNO.ToString();

                                            db.CSCOARs.Add(cSCOAR);
                                            if (cSCOAR.FILEDAR != null) // create next year record if AR is filed
                                            {
                                                string sid     = cSCOAR.CONO;
                                                CSCOAR lastRec = db.CSCOARs.Where(m => m.CONO == sid).OrderByDescending(n => n.ARNO).FirstOrDefault();

                                                if (cSCOAR.ARNO == lastRec.ARNO) // add next year record only if editing the last record
                                                {
                                                    CSCOAR csRec1 = createNextYearAR(cSCOAR);
                                                    db.CSCOARs.Add(csRec1);
                                                }
                                            }
                                            db.SaveChanges();
                                        }
                                    }
                                    catch (Exception e)
                                    {
                                        datarow.ElementAt(idx)[6] = e.Message + "!!!";
                                        db.CSCOARs.Remove(cSCOAR);
                                    }
                                    finally
                                    {; };
                                };
                            }
                        }

                        catch (Exception e)
                        {
                            datarow.ElementAt(idx)["New"] = e.Message;
                        }
                        finally
                        {
                            idx++;
                        }
                    }
                    datarow = datarow.Where(y => y.Field <string>(7) != "Exist").OrderBy(x => x.Field <string>("New")).ThenBy(y => y.Field <int>("status_id"));
                }
                else if (dbTableName == "CSCOMSTR")
                {
                    datarow = datarow.Where(x => x.Field <string>("New") == "***" && x.Field <string>("company_no") != "");
                    datarow = datarow.OrderBy(x => x.Field <int?>("company_id")).Select(x => x);

                    int idx = 0;
                    foreach (DataRow row in datarow)
                    {
                        templine = (string)row["company_no"];

                        CSCOMSTR cSCOMSTR = new CSCOMSTR();

                        try
                        {
                            ModelState.Clear();

                            cSCOMSTR.STAMP      = 999;
                            cSCOMSTR.ARRE       = "N";
                            cSCOMSTR.SPECIALRE  = "N";
                            cSCOMSTR.SEQNO      = 1; // set inital seqno
                            cSCOMSTR.CONO       = (string)row["company_no"];
                            cSCOMSTR.CONAME     = (string)row["company_name"];
                            cSCOMSTR.INTYPE     = (string)row["company_intype"];
                            cSCOMSTR.CONSTCODE  = (string)row["company_constitution"];
                            cSCOMSTR.COSTATD    = DateTime.Now;
                            cSCOMSTR.INCDATE    = DateTime.Parse((string)(row["company_incorporation"]));
                            cSCOMSTR.PRINOBJStr = (string)row["company_objectives"] ?? "";
                            cSCOMSTR.PINDCODE   = (string)row["company_industrya"] ?? "";
                            cSCOMSTR.SINDCODE   = (string)row["company_industryb"] ?? "";
                            cSCOMSTR.WEB        = (string)row["company_website"] ?? "";
                            cSCOMSTR.STAFFCODE  = (string)row["company_staffid"];
                            cSCOMSTR.CMMTStr    = (string)row["company_comment"] ?? "";
                            cSCOMSTR.INCCTRY    = "MY";
                            cSCOMSTR.COSTAT     = "Active";

                            if (DBNull.Value != row["company_remark"])
                            {
                                cSCOMSTR.REM = (string)row["company_remark"] ?? "";
                            }
                            if (DBNull.Value != row["company_country"])
                            {
                                cSCOMSTR.INCCTRY = (string)row["company_country"];
                            }
                            ;
                            if (row["company_activate"] != DBNull.Value)
                            {
                                cSCOMSTR.COSTAT = (string)row["company_activate"] == "t" ? "Active" : "NotActive";
                            }
                            ;


                            if (ModelState.IsValid)
                            {
                                db.CSCOMSTRs.Add(cSCOMSTR);
                                db.SaveChanges();
                            }
                        }
                        catch (Exception e)
                        {
                            datarow.ElementAt(idx)["company_industryb"] = "!!!";
                            db.CSCOMSTRs.Remove(cSCOMSTR);
                        }
                        finally
                        {
                            // db.CSCOMSTRs.Add(cSCOMSTR);
                            idx++;
                        }



                        // Console.WriteLine( templine);
                    }
                    //db.SaveChanges();
                }
                else if (dbTableName == "CSCOSTAT")
                {
                    datarow  = datarow.OrderBy(x => x.Field <string>("company_id")).ThenBy(n => n.Field <string>("sort_date")).Select(x => x);
                    refTable = OpenTable(usefile);
                    var csRefs = refTable.AsEnumerable();


                    int      idx  = 0;
                    int      coid = 0;
                    string   cono = "";
                    DateTime sdate;
                    CSCOSTAT csRec = null;
                    foreach (DataRow row in datarow)
                    {
                        templine = (string)row["company_id"];
                        coid     = int.Parse(templine);
                        cono     = null;
                        try
                        {
                            var corec = csRefs.Where(x => x.Field <int?>("company_id") == coid).FirstOrDefault();
                            if (corec != null)
                            {
                                cono = (string)corec["company_no"];
                            }
                            else
                            {
                                cono = null;
                            }
                            if (cono != null)
                            {
                                datarow.ElementAt(idx)["New"] = cono;

                                sdate = DateTime.Parse((string)(datarow.ElementAt(idx)["status_date"]));
                                csRec = ((List <CSCOSTAT>)csRecs).Where(item => item.CONO == cono && item.SDATE == sdate).FirstOrDefault();
                                if (csRec != null)
                                {
                                    datarow.ElementAt(idx)[7] = "Exist";
                                }
                                else
                                {
                                    CSCOSTAT cSCOSTAT = new CSCOSTAT();
                                    try
                                    {
                                        ModelState.Clear();

                                        cSCOSTAT.STAMP    = 999;
                                        cSCOSTAT.CONO     = cono;
                                        cSCOSTAT.SDATE    = sdate;
                                        cSCOSTAT.FILETYPE = "A";
                                        cSCOSTAT.COSTAT   = (string)row["status_status"];
                                        cSCOSTAT.FILELOC  = (string)row["status_fileno"];
                                        cSCOSTAT.SEALLOC  = (string)row["status_sealno"];

                                        if (ModelState.IsValid)
                                        {
                                            int?lastRowNo = 0;
                                            try
                                            {
                                                lastRowNo = db.CSCOSTATs.Where(m => m.CONO == cSCOSTAT.CONO).Max(n => n.ROWNO);
                                            }
                                            catch (Exception e) { lastRowNo = -1; }
                                            finally { };

                                            cSCOSTAT.EDATE            = cSCOSTAT.SDATE.AddDays(30000);
                                            cSCOSTAT.ROWNO            = (lastRowNo ?? 0) + 1;
                                            datarow.ElementAt(idx)[6] = cSCOSTAT.ROWNO.ToString();

                                            db.CSCOSTATs.Add(cSCOSTAT);
                                            UpdatePreviousRow(cSCOSTAT);
                                            db.SaveChanges();
                                        }
                                    }
                                    catch (Exception e)
                                    {
                                        datarow.ElementAt(idx)[6] = e.Message + "!!!";
                                        db.CSCOSTATs.Remove(cSCOSTAT);
                                    }
                                    finally
                                    {
                                    }
                                }
                            }
                        }
                        catch (Exception e)
                        {
                            datarow.ElementAt(idx)["New"] = e.Message;
                        }
                        finally
                        {
                            idx++;
                        }
                    }
                    datarow = datarow.Where(y => y.Field <string>(7) != "Exist").OrderBy(x => x.Field <string>("New")).ThenBy(y => y.Field <int>("status_id"));
                }

                DataTable ndt = datarow.CopyToDataTable <DataRow>();


                return(View(ndt));

                string conString = ConfigurationManager.ConnectionStrings["SirisCS"].ConnectionString;



                using (FbConnection con = new FbConnection(conString))
                {
                    //datarow = dt.AsEnumerable();
                    //newrow = datarow.Where(x => x.Field<int>("Id") == 2);
                };

                //using (SqlConnection con = new SqlConnection(conString))

                //{

                //    using (SqlBulkCopy sqlBulkCopy = new SqlBulkCopy(con))

                //    {

                //        //Set the database table name.

                //        sqlBulkCopy.DestinationTableName = "dbo.Customers";



                //        //[OPTIONAL]: Map the DataTable columns with that of the database table

                //        sqlBulkCopy.ColumnMappings.Add("Id", "CustomerId");

                //        sqlBulkCopy.ColumnMappings.Add("Name", "Name");

                //        sqlBulkCopy.ColumnMappings.Add("Country", "Country");



                //        con.Open();

                //        sqlBulkCopy.WriteToServer(dt);

                //        con.Close();

                //    }

                //        }
            }



            return(View());
        }
Пример #16
0
        public ActionResult Post(string[] cono)
        {
            CSPRFsController CSPRFControl = new CSPRFsController();

            try
            {
                SALASTNO serialTbl0 = db.SALASTNOes.Find("CSBILL");
                if ((serialTbl0 != null))
                {
                    foreach (string item in cono)
                    {
                        var      conofee  = item.Split('|');
                        var      myCono   = conofee[0];
                        var      myFee    = conofee[1];
                        string   lastCono = "";
                        CSCOMSTR cSCOMSTR = null;
                        myCono = myCono.Trim();
                        myFee  = myFee.Trim();



                        var     csFees  = db.CSCOFEEs.Where(x => x.CONO == myCono && x.FEETYPE == myFee);
                        decimal taxrate = 0;
                        string  taxcode = "SSTN01";
                        CSPRF   cSPRF   = null;
                        int     prfId   = 0;
                        foreach (var feerec in csFees)
                        {
                            CSITEM cSITEM = db.CSITEMs.Find(feerec.FEETYPE);
                            if (cSITEM != null)
                            {
                                taxrate = cSITEM.GSTRATE ?? 0;
                            }

                            if (lastCono != feerec.CONO)
                            {
                                cSCOMSTR                 = db.CSCOMSTRs.Find(feerec.CONO);
                                cSCOMSTR.SEQNO           = cSCOMSTR.SEQNO + 1;
                                cSCOMSTR.STAMP           = cSCOMSTR.STAMP;
                                db.Entry(cSCOMSTR).State = EntityState.Modified;
                            }

                            var feedate = feerec.LASTTOUCH;


                            feerec.LASTTOUCH       = feedate.AddMonths(feerec.FEEMTH);
                            feerec.STAMP           = feerec.STAMP + 1;
                            db.Entry(feerec).State = EntityState.Modified;


                            SALASTNO serialTbl = db.SALASTNOes.Find("CSPRF");
                            if ((serialTbl != null) && (lastCono != feerec.CONO))
                            {
                                string prefix  = serialTbl.LASTPFIX;
                                int    MaxNo   = serialTbl.LASTNOMAX;
                                bool   AutoGen = serialTbl.AUTOGEN == "Y";
                                serialTbl.LASTNO = serialTbl.LASTNO + 1;


                                cSPRF         = new CSPRF();
                                cSPRF.STAMP   = 0;
                                cSPRF.VDATE   = feedate;
                                cSPRF.DUEDATE = feedate;
                                cSPRF.DUEDAYS = 0;
                                cSPRF.SEQNO   = cSCOMSTR.SEQNO;
                                cSPRF.CONO    = feerec.CONO;
                                short?coid = db.CSCOADDRs.Where(x => x.CONO == feerec.CONO && x.MAILADDR == "Y").Select(y => y.ADDRID).FirstOrDefault();
                                if (coid == 0)
                                {
                                    coid = db.CSCOADDRs.Where(x => x.CONO == feerec.CONO && x.MAILADDR == "N").Select(y => y.ADDRID).FirstOrDefault();
                                }
                                if (coid != 0)
                                {
                                    cSPRF.COADDRID = coid;
                                }

                                cSPRF.ATTN     = "The Board of Directors";
                                cSPRF.PRFNO    = serialTbl.LASTNO.ToString("D10");
                                cSPRF.INVALLOC = "N";

                                serialTbl.STAMP           = serialTbl.STAMP + 1;
                                db.Entry(serialTbl).State = EntityState.Modified;
                                db.CSPRFs.Add(cSPRF);
                                prfId = 0;
                            }

                            prfId++;
                            serialTbl0.LASTNO = serialTbl0.LASTNO + 1;
                            string prefix0  = serialTbl0.LASTPFIX;
                            int    MaxNo0   = serialTbl0.LASTNOMAX;
                            bool   AutoGen0 = serialTbl0.AUTOGEN == "Y";
                            CSBILL cSBILL   = new WebApplication1.CSBILL();
                            cSBILL.STAMP    = 0;
                            cSBILL.CONO     = feerec.CONO;
                            cSBILL.PRFALLOC = "Y";
                            cSBILL.SYSGEN   = "Y";
                            cSBILL.PRFNO    = cSPRF.PRFNO;
                            cSBILL.PRFID    = prfId;
                            cSBILL.BILLNO   = serialTbl0.LASTNO.ToString("D10");;
                            cSBILL.ENTDATE  = feedate;
                            cSBILL.CASECODE = feerec.FEECODE;
                            cSBILL.ITEMTYPE = feerec.FEETYPE;
                            cSBILL.ITEMDESC = feerec.CSCASE.CASEDESC;
                            cSBILL.ITEMSPEC = "- From " + feedate.ToString("dd/MM/yyyy") + " To " + feedate.AddMonths(feerec.FEEMTH).ToString("dd/MM/yyyy");

                            cSBILL.ITEMAMT = feerec.FEEAMT;
                            cSBILL.TAXAMT  = taxrate * feerec.FEEAMT / 100;
                            cSBILL.NETAMT  = cSBILL.ITEMAMT + cSBILL.TAXAMT;

                            cSBILL.ITEMAMT1 = feerec.FEEAMT;
                            cSBILL.TAXAMT1  = taxrate * feerec.FEEAMT / 100;
                            cSBILL.NETAMT1  = cSBILL.ITEMAMT1 + cSBILL.TAXAMT1;

                            cSBILL.ITEMAMT2 = 0;
                            cSBILL.TAXAMT2  = 0;
                            cSBILL.NETAMT2  = 0;
                            cSBILL.TAXRATE  = taxrate;

                            taxcode        = db.CSTAXTYPEs.Where(x => x.TAXRATE == taxrate && x.EFFECTIVE_START <= cSBILL.ENTDATE && x.EFFECTIVE_END >= cSBILL.ENTDATE).Select(y => y.TAXCODE).FirstOrDefault() ?? taxcode;
                            cSBILL.TAXCODE = taxcode;
                            db.CSBILLs.Add(cSBILL);


                            CSTRANM cSTRANM = new CSTRANM();
                            cSTRANM.STAMP = 0;
                            CSPRFControl.BD_UpdateCSTRANM(cSPRF, cSBILL, cSTRANM);

                            db.CSTRANMs.Add(cSTRANM);

                            lastCono = feerec.CONO;
                        }
                        //db.Entry(serialTbl0).State = EntityState.Modified;
                        //db.SaveChanges();
                    }
                    db.Entry(serialTbl0).State = EntityState.Modified;
                    db.SaveChanges();
                }
            }
            catch (DbEntityValidationException dbEx)
            {
                foreach (var validationErrors in dbEx.EntityValidationErrors)
                {
                    foreach (var validationError in validationErrors.ValidationErrors)
                    {
                        //string message = string.Format("{0}:{1}",
                        //    validationErrors.Entry.Entity.ToString(),
                        //   validationError.ErrorMessage);
                        // raise a new exception nesting
                        // the current instance as InnerException
                        ModelState.AddModelError(validationError.PropertyName, validationError.ErrorMessage);
                    }
                }
            }
            catch (DbUpdateException ex)
            {
                UpdateException updateException = (UpdateException)ex.InnerException;
                if (updateException != null)
                {
                    if (updateException.InnerException != null)
                    {
                        var sqlException = (FirebirdSql.Data.FirebirdClient.FbException)updateException.InnerException;

                        foreach (var error in sqlException.Errors)
                        {
                            if (error.Message != null)
                            {
                                ModelState.AddModelError(string.Empty, error.Message);
                            }
                        }
                    }
                    else
                    {
                        ModelState.AddModelError(string.Empty, updateException.Message);
                    }
                }
                else
                {
                    ModelState.AddModelError(string.Empty, updateException.Message);
                }
            }
            catch (Exception e)
            {
                ModelState.AddModelError(string.Empty, e.Message);
            }
            finally
            {
                CSPRFControl.Dispose();
            }

            return(new HttpStatusCodeResult(HttpStatusCode.OK));
        }