예제 #1
0
        public bool AddProject(tblProject model, long parentProjectID)
        {
            try
            {
                tblProjectDap newDap = new tblProjectDap();
                if (parentProjectID == 0)
                {

                    string strMaxnum =
                        (newDap.Query<string>(
                            "select max(fldProjectTreeID) from tblProject where len(fldProjectTreeID) =5 "))
                            .FirstOrDefault().ToString();
                    long lngMaxnum = long.Parse(strMaxnum);
                    lngMaxnum += 1;
                    strMaxnum = ("0000" + lngMaxnum.ToString()).ToString();
                    strMaxnum = strMaxnum.Substring(strMaxnum.Length - 5);
                    model.fldProjectTreeID = strMaxnum;
                    model.fldProjectTreeCode = lngMaxnum.ToString();
                }
                else
                {
                    tblProject parentProject = new tblProject();
                    parentProject = GetByfldProjectID(parentProjectID);

                    int fldProjectTreeIDLen = parentProject.fldProjectTreeID.Length;
                    //string qry = "select max(fldProjectTreeID) from tblProject where len(fldProjectTreeID) = " +
                    //             (fldProjectTreeIDLen + 5).ToString() + " and tblProject.fldProjectTreeID like '" +
                    //             parentProjectID + "%' ";
                    string qry = "select max(fldProjectTreeID) from tblProject where len(fldProjectTreeID) = " +
                                (fldProjectTreeIDLen + 5).ToString() + " and tblProject.fldProjectTreeID like @parentProjectID ";
                    //var res = (newDap.Query<string>(qry)).FirstOrDefault();
                    var res = (newDap.Query<string>(qry, new { parentProjectID = parentProject.fldProjectTreeID  + "%" })).FirstOrDefault();
                    if (res != null)
                    {

                        long lngMaxnum = long.Parse(res.ToString().Right(5));
                        lngMaxnum += 1;
                        string strMaxnum = ("0000" + lngMaxnum.ToString()).ToString();
                        strMaxnum = strMaxnum.Right(5);
                        model.fldProjectTreeID = res.ToString().Left(res.ToString().Length - 5) + strMaxnum;
                        model.fldParentID = parentProject.fldProjectID;
                        model.fldProjectTreeCode =
                            StringExtensions.ConvertHierachicaltoCode(model.fldProjectTreeID, 5);
                    }
                    else
                    {
                        model.fldProjectTreeID = parentProject.fldProjectTreeID + "00001";
                        model.fldParentID = parentProject.fldProjectID;
                        model.fldProjectTreeCode =
                            StringExtensions.ConvertHierachicaltoCode(model.fldProjectTreeID, 5);
                    }

                }

                newDap.Insert(model);
                return true;
            }
            catch
            {
                return false;
            }
        }
예제 #2
0
        public ActionResult CreatePartial(tblProject tblProject)
        {
            try
            {
                tblProjectDap newDap = new tblProjectDap();
                if (tblProject.fldProjectID == 0)
                {

                    string strMaxnum =
                        (newDap.Query<string>(
                            "select max(fldProjectTreeID) from tblProject where len(fldProjectTreeID) =5 "))
                            .FirstOrDefault().ToString();
                    long lngMaxnum = long.Parse(strMaxnum);
                    lngMaxnum += 1;
                    strMaxnum = ("0000" + lngMaxnum.ToString()).ToString();
                    strMaxnum = strMaxnum.Substring(strMaxnum.Length - 5);
                    tblProject.fldProjectTreeID = strMaxnum;
                    tblProject.fldProjectTreeCode = lngMaxnum.ToString();
                }
                else
                {
                    int fldProjectTreeIDLen = tblProject.fldProjectTreeID.Length;
                    string qry = "select max(fldProjectTreeID) from tblProject where len(fldProjectTreeID) = " +
                                 (fldProjectTreeIDLen + 5).ToString() + " and tblProject.fldProjectTreeID like '" +
                                 tblProject.fldProjectTreeID + "%' ";
                    var res = (newDap.Query<string>(qry)).FirstOrDefault();
                    if (res != null)
                    {

                        long lngMaxnum = long.Parse(res.ToString().Right(5));
                        lngMaxnum += 1;
                        string strMaxnum = ("0000" + lngMaxnum.ToString()).ToString();
                        strMaxnum = strMaxnum.Right(5);
                        tblProject.fldProjectTreeID = res.ToString().Left(res.ToString().Length-5) + strMaxnum;
                        tblProject.fldParentID = tblProject.fldProjectID;
                        tblProject.fldProjectTreeCode =
                            StringExtensions.ConvertHierachicaltoCode(tblProject.fldProjectTreeID,5);
                    }
                    else
                    {
                        tblProject.fldProjectTreeID = tblProject.fldProjectTreeID + "00001";
                        tblProject.fldParentID = tblProject.fldProjectID;
                        tblProject.fldProjectTreeCode =
                            StringExtensions.ConvertHierachicaltoCode(tblProject.fldProjectTreeID, 5);
                    }

                }

                newDap.Insert(tblProject);

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }