Ejemplo n.º 1
0
        /// <summary>Загружаем проект</summary>
        public AgrProject GetProject(int id)
        {
            lock (Db.Ds)
            {
                LogManager.LogDebug(IpClient(), "Запрос проекта " + id);
                AgrDataSet.ProjectsRow drProjects = Db.Ds.Projects.FindById(id);
                if (drProjects == null)
                {
                    return(null);
                }
                AgrDataSet.ProjectRow        drProject        = drProjects.GetProjectRows()[0];
                AgrDataSet.ClientProjectRow  drClientProject  = drProjects.GetClientProjectRows()[0];
                AgrDataSet.ClientRow         drClient         = drClientProject.ClientRow;
                AgrDataSet.ProjectProductRow drProjectProduct = drProjects.GetProjectProductRows()[0];
                AgrDataSet.ProductRow        drProduct        = drProjectProduct.ProductRow;
                var project = new AgrProject(drProject.Id)
                {
                    ID            = drProject.Name,
                    Customer      = drClient.Name,
                    CustomerName  = drProject.CustomerName,
                    Product       = drProduct.Name,
                    Options       = drProject.Options,
                    ChangedDate   = drProjects.Date,
                    TimeEndActual =
                        drProjects.TimeEndActual == DateTime.MinValue
                                   ? (DateTime?)null
                                   : drProjects.TimeEndActual,

                    IsManagerSetPlanDate = drProject.IsManagerSetPlanDate,

                    IsStop           = drProject.IsStop,
                    COM_Package_Type = drProject.COM_Package_Type,

                    #region ITO

                    #region G
                    Time_ITO_G_Plan =
                        drProject.Time_ITO_G_Plan == DateTime.MinValue
                                       ? (DateTime?)null
                                       : drProject.Time_ITO_G_Plan,

                    Time_ITO_G_Actual =
                        drProject.Time_ITO_G_Actual == DateTime.MinValue
                                       ? (DateTime?)null
                                       : drProject.Time_ITO_G_Actual,

                    Is_ITO_G_NotNeed = drProject.Is_ITO_G_NotNeed,
                    #endregion G

                    #region E
                    Time_ITO_E_Plan =
                        drProject.Time_ITO_E_Plan == DateTime.MinValue
                                       ? (DateTime?)null
                                       : drProject.Time_ITO_E_Plan,

                    Time_ITO_E_Actual =
                        drProject.Time_ITO_E_Actual == DateTime.MinValue
                                       ? (DateTime?)null
                                       : drProject.Time_ITO_E_Actual,

                    Is_ITO_E_NotNeed = drProject.Is_ITO_E_NotNeed,
                    #endregion E

                    #region R
                    Time_ITO_R_Plan =
                        drProject.Time_ITO_R_Plan == DateTime.MinValue
                                       ? (DateTime?)null
                                       : drProject.Time_ITO_R_Plan,

                    Time_ITO_R_Actual =
                        drProject.Time_ITO_R_Actual == DateTime.MinValue
                                       ? (DateTime?)null
                                       : drProject.Time_ITO_R_Actual,

                    ITO_R_Mode = drProject.ITO_R_Mode,

                    Is_ITO_R_NotNeed = drProject.Is_ITO_R_NotNeed,
                    #endregion R

                    #endregion ITO

                    #region WH

                    #region G
                    Time_WH_G_Plan =
                        drProject.Time_WH_G_Plan == DateTime.MinValue
                                   ? (DateTime?)null
                                   : drProject.Time_WH_G_Plan,

                    Time_WH_G_Actual =
                        drProject.Time_WH_G_Actual == DateTime.MinValue
                                   ? (DateTime?)null
                                   : drProject.Time_WH_G_Actual,

                    Is_WH_G_NotNeed = drProject.Is_WH_G_NotNeed,

                    Time_WH_G_Requests_Create =
                        drProject.Time_WH_G_Requests_Create == DateTime.MinValue
                                   ? (DateTime?)null
                                   : drProject.Time_WH_G_Requests_Create,

                    #endregion G

                    #region E
                    Time_WH_E_Plan =
                        drProject.Time_WH_E_Plan == DateTime.MinValue
                                   ? (DateTime?)null
                                   : drProject.Time_WH_E_Plan,

                    Time_WH_E_Actual =
                        drProject.Time_WH_E_Actual == DateTime.MinValue
                                   ? (DateTime?)null
                                   : drProject.Time_WH_E_Actual,

                    Is_WH_E_NotNeed = drProject.Is_WH_E_NotNeed,

                    Time_WH_E_Requests_Create =
                        drProject.Time_WH_E_Requests_Create == DateTime.MinValue
                                   ? (DateTime?)null
                                   : drProject.Time_WH_E_Requests_Create,
                    #endregion E

                    #region R
                    Time_WH_R_Plan =
                        drProject.Time_WH_R_Plan == DateTime.MinValue
                                   ? (DateTime?)null
                                   : drProject.Time_WH_R_Plan,

                    Time_WH_R_Actual =
                        drProject.Time_WH_R_Actual == DateTime.MinValue
                                   ? (DateTime?)null
                                   : drProject.Time_WH_R_Actual,

                    Is_WH_R_NotNeed = drProject.Is_WH_R_NotNeed,
                    #endregion R

                    #endregion WH

                    #region OMTS

                    #region G
                    Time_OMTS_G_Plan =
                        drProject.Time_OMTS_G_Plan == DateTime.MinValue
                                   ? (DateTime?)null
                                   : drProject.Time_OMTS_G_Plan,

                    Time_OMTS_G_Actual =
                        drProject.Time_OMTS_G_Actual == DateTime.MinValue
                                   ? (DateTime?)null
                                   : drProject.Time_OMTS_G_Actual,
                    #endregion G

                    #region E
                    Time_OMTS_E_Plan =
                        drProject.Time_OMTS_E_Plan == DateTime.MinValue
                                   ? (DateTime?)null
                                   : drProject.Time_OMTS_E_Plan,

                    Time_OMTS_E_Actual =
                        drProject.Time_OMTS_E_Actual == DateTime.MinValue
                                   ? (DateTime?)null
                                   : drProject.Time_OMTS_E_Actual,
                    #endregion E

                    #endregion OMTS

                    TimeBegin     = drProject.TimeBegin,
                    TimeEndPlaned = drProject.TimeEndPlaned,
                    Com_New_Time  =
                        drProject.Com_New_Time == DateTime.MinValue
                                   ? (DateTime?)null
                                   : drProject.Com_New_Time,
                    MF_Collector           = drProject.MF_Collector,
                    MF_Complete_Percentage = drProject.MF_Complete_Percentage,
                    MF_Level     = drProject.MF_Level,
                    MF_Rama      = drProject.MF_Rama,
                    MF_Post      = drProject.MF_Post,
                    MF_Agregat   = drProject.MF_Agregat,
                    MF_SH_Place  = drProject.MF_SH_Place,
                    MF_SH        = drProject.MF_SH,
                    MF_Time_Plan =
                        drProject.MF_Time_Plan == DateTime.MinValue
                                   ? (DateTime?)null
                                   : drProject.MF_Time_Plan,
                    MF_Time_Test_Actual =
                        drProject.MF_Time_Test_Actual == DateTime.MinValue
                                   ? (DateTime?)null
                                   : drProject.MF_Time_Test_Actual,
                    MF_Time = drProject.MF_Time == DateTime.MinValue ? (DateTime?)null : drProject.MF_Time,

                    #region OTK
                    Time_OTK_Plan =
                        drProject.Time_OTK_Plan == DateTime.MinValue
                                   ? (DateTime?)null
                                   : drProject.Time_OTK_Plan,

                    Time_OTK_G_Actual =
                        drProject.Time_OTK_G_Actual == DateTime.MinValue
                                   ? (DateTime?)null
                                   : drProject.Time_OTK_G_Actual,

                    Time_OTK_E_Actual =
                        drProject.Time_OTK_E_Actual == DateTime.MinValue
                                   ? (DateTime?)null
                                   : drProject.Time_OTK_E_Actual,
                    Is_OTK_G_NotNeed = drProject.Is_OTK_G_NotNeed,
                    Is_OTK_E_NotNeed = drProject.Is_OTK_E_NotNeed,

                    #endregion OTK
                };

                // Сообщения
                foreach (AgrDataSet.CommentRow drComment in drProjects.GetCommentRows())
                {
                    project.Messages.Add(new AgrProjectComment(drComment.Time, drComment.UserName,
                                                               drComment.Value));
                }

                // Недокомплект
                foreach (AgrDataSet.RequestRow drRequest in drProjects.GetRequestRows())
                {
                    project.Requests.Add(new AgrRequest((OMTSRequestType)drRequest.Type, drRequest.Name)
                    {
                        TotalCount        = drRequest.TotalCount,
                        ExistCount        = drRequest.ExistCount,
                        Article           = drRequest.Article,
                        DateComplete_Plan = drRequest.DateComplete_Plan == DateTime.MinValue
                                                    ? (DateTime?)null
                                                    : drRequest.DateComplete_Plan,
                        DateComplete = drRequest.DateComplete == DateTime.MinValue
                                               ? (DateTime?)null
                                               : drRequest.DateComplete,
                        IsCustomerMaterials = drRequest.IsCustomerMaterials
                    });
                }
                return(project);
            }
        }
Ejemplo n.º 2
0
        // после этого перестает падать надо блокировать доступ к базе во время чтения записи..
        // куча клиентов лезет одновременно
        //static readonly object lockObject = new object();
        //public static LProjects Projects(DateTime? fromDate, StateTime stateTime, int previousId)
        //{
        //    lock (lockObject)
        //    {
        //    }
        //}

        public static LProjects Projects(DateTime?fromDate, StateTime stateTime, int previousId)
        {
            lock (Db.Ds)
            {
                if (!Db.LoadProjects())
                {
                    return(null);
                }
                AgrDataSet.ProjectsRow[] drsProjects;
                if (fromDate == null)
                {
                    if (stateTime == StateTime.Worked)
                    {
                        if (previousId >= 0)
                        {
                            drsProjects = (AgrDataSet.ProjectsRow[])Db.Ds.Projects.
                                          Select("TimeEndActual = '" + DateTime.MinValue
                                                 + "' AND Id > " + previousId, "Id");
                        }
                        else
                        {
                            drsProjects = (AgrDataSet.ProjectsRow[])Db.Ds.Projects.
                                          Select("TimeEndActual = '" + DateTime.MinValue +
                                                 "'");
                        }
                    }
                    else
                    {
                        drsProjects = (AgrDataSet.ProjectsRow[])Db.Ds.Projects.Select();
                    }
                }
                else
                {
                    switch (stateTime)
                    {
                    case StateTime.Changed:
                        drsProjects = (AgrDataSet.ProjectsRow[])Db.Ds.Projects.
                                      Select("Date > '" + fromDate + "'");
                        break;

                    case StateTime.Worked:
                        //drsProject = (AgrDataSet.ProjectsRow[])Db.Ds.Projects.
                        //    Select("TimeEndActual = '" + DateTime.MinValue + "'");
                        if (previousId >= 0)
                        {
                            drsProjects = (AgrDataSet.ProjectsRow[])Db.Ds.Projects.
                                          Select(
                                "((TimeEndActual = '" +
                                DateTime.MinValue
                                + "') OR (TimeEndActual > '" + fromDate
                                + "')) AND Id > " + previousId, "Id");
                        }
                        else
                        {
                            drsProjects = (AgrDataSet.ProjectsRow[])Db.Ds.Projects.
                                          Select("(TimeEndActual = '" +
                                                 DateTime.MinValue
                                                 + "') OR (TimeEndActual > '" +
                                                 fromDate + "')");
                        }
                        break;

                    default:
                        drsProjects = (AgrDataSet.ProjectsRow[])Db.Ds.Projects.Select();
                        break;
                    }
                }
                var projects = new LProjects();
                int index1   = 0;
                for (int index = 0; index < drsProjects.Length; index++)
                {
                    if (index1 >= 10)
                    {
                        break;
                    }
                    AgrDataSet.ProjectsRow drProjects = drsProjects[index];
                    if ((previousId >= 0) && (previousId == drProjects.Id))
                    {
                        continue;
                    }
                    if (Db.LoadProject(drProjects.Id))
                    {
                        index1++;
                        AgrDataSet.ProjectRow         drProject        = drProjects.GetProjectRows()[0];
                        AgrDataSet.ClientProjectRow[] drsClientProject = drProjects.GetClientProjectRows();
                        if (drsClientProject.Length == 0)
                        {
                            continue;
                        }
                        AgrDataSet.ClientProjectRow drClientProject = drsClientProject[0];
                        AgrDataSet.ClientRow        drClient        = drClientProject.ClientRow;

                        AgrDataSet.ProjectProductRow[] drsProjectProduct = drProjects.GetProjectProductRows();
                        if (drsProjectProduct.Length == 0)
                        {
                            continue;
                        }
                        AgrDataSet.ProjectProductRow drProjectProduct = drsProjectProduct[0];
                        AgrDataSet.ProductRow        drProduct        = drProjectProduct.ProductRow;

                        var project = new AgrProject(drProject.Id)
                        {
                            ID            = drProject.Name,
                            Customer      = drClient.Name,
                            CustomerName  = drProject.CustomerName,
                            Product       = drProduct.Name,
                            Options       = drProject.Options,
                            ChangedDate   = drProjects.Date,
                            TimeEndActual =
                                drProjects.TimeEndActual == DateTime.MinValue
                                    ? (DateTime?)null
                                    : drProjects.TimeEndActual,

                            IsManagerSetPlanDate = drProject.IsManagerSetPlanDate,

                            IsStop           = drProject.IsStop,
                            COM_Package_Type = drProject.COM_Package_Type,

                            #region ITO

                            #region G
                            Time_ITO_G_Plan =
                                drProject.Time_ITO_G_Plan == DateTime.MinValue
                                    ? (DateTime?)null
                                    : drProject.Time_ITO_G_Plan,

                            Time_ITO_G_Actual =
                                drProject.Time_ITO_G_Actual == DateTime.MinValue
                                    ? (DateTime?)null
                                    : drProject.Time_ITO_G_Actual,

                            Is_ITO_G_NotNeed = drProject.Is_ITO_G_NotNeed,

                            #endregion G

                            #region E
                            Time_ITO_E_Plan =
                                drProject.Time_ITO_E_Plan == DateTime.MinValue
                                    ? (DateTime?)null
                                    : drProject.Time_ITO_E_Plan,

                            Time_ITO_E_Actual =
                                drProject.Time_ITO_E_Actual == DateTime.MinValue
                                    ? (DateTime?)null
                                    : drProject.Time_ITO_E_Actual,

                            Is_ITO_E_NotNeed = drProject.Is_ITO_E_NotNeed,

                            #endregion E

                            #region R
                            Time_ITO_R_Plan =
                                drProject.Time_ITO_R_Plan == DateTime.MinValue
                                    ? (DateTime?)null
                                    : drProject.Time_ITO_R_Plan,

                            Time_ITO_R_Actual =
                                drProject.Time_ITO_R_Actual == DateTime.MinValue
                                    ? (DateTime?)null
                                    : drProject.Time_ITO_R_Actual,

                            ITO_R_Mode = drProject.ITO_R_Mode,

                            Is_ITO_R_NotNeed = drProject.Is_ITO_R_NotNeed,

                            #endregion R

                            #endregion ITO

                            #region WH

                            #region G
                            Time_WH_G_Plan =
                                drProject.Time_WH_G_Plan == DateTime.MinValue
                                    ? (DateTime?)null
                                    : drProject.Time_WH_G_Plan,

                            Time_WH_G_Actual =
                                drProject.Time_WH_G_Actual == DateTime.MinValue
                                    ? (DateTime?)null
                                    : drProject.Time_WH_G_Actual,

                            Is_WH_G_NotNeed = drProject.Is_WH_G_NotNeed,

                            Time_WH_G_Requests_Create =
                                drProject.Time_WH_G_Requests_Create == DateTime.MinValue
                                    ? (DateTime?)null
                                    : drProject.Time_WH_G_Requests_Create,

                            #endregion G

                            #region E
                            Time_WH_E_Plan =
                                drProject.Time_WH_E_Plan == DateTime.MinValue
                                    ? (DateTime?)null
                                    : drProject.Time_WH_E_Plan,

                            Time_WH_E_Actual =
                                drProject.Time_WH_E_Actual == DateTime.MinValue
                                    ? (DateTime?)null
                                    : drProject.Time_WH_E_Actual,

                            Is_WH_E_NotNeed = drProject.Is_WH_E_NotNeed,

                            Time_WH_E_Requests_Create =
                                drProject.Time_WH_E_Requests_Create == DateTime.MinValue
                                    ? (DateTime?)null
                                    : drProject.Time_WH_E_Requests_Create,

                            #endregion E

                            #region R
                            Time_WH_R_Plan =
                                drProject.Time_WH_R_Plan == DateTime.MinValue
                                    ? (DateTime?)null
                                    : drProject.Time_WH_R_Plan,

                            Time_WH_R_Actual =
                                drProject.Time_WH_R_Actual == DateTime.MinValue
                                    ? (DateTime?)null
                                    : drProject.Time_WH_R_Actual,

                            Is_WH_R_NotNeed = drProject.Is_WH_R_NotNeed,

                            #endregion R

                            #endregion WH

                            #region OMTS

                            #region G
                            Time_OMTS_G_Plan =
                                drProject.Time_OMTS_G_Plan == DateTime.MinValue
                                    ? (DateTime?)null
                                    : drProject.Time_OMTS_G_Plan,

                            Time_OMTS_G_Actual =
                                drProject.Time_OMTS_G_Actual == DateTime.MinValue
                                    ? (DateTime?)null
                                    : drProject.Time_OMTS_G_Actual,

                            #endregion G

                            #region E
                            Time_OMTS_E_Plan =
                                drProject.Time_OMTS_E_Plan == DateTime.MinValue
                                    ? (DateTime?)null
                                    : drProject.Time_OMTS_E_Plan,

                            Time_OMTS_E_Actual =
                                drProject.Time_OMTS_E_Actual == DateTime.MinValue
                                    ? (DateTime?)null
                                    : drProject.Time_OMTS_E_Actual,

                            #endregion E

                            #endregion OMTS

                            TimeBegin     = drProject.TimeBegin,
                            TimeEndPlaned = drProject.TimeEndPlaned,
                            Com_New_Time  =
                                drProject.Com_New_Time == DateTime.MinValue
                                    ? (DateTime?)null
                                    : drProject.Com_New_Time,
                            MF_Collector           = drProject.MF_Collector,
                            MF_Complete_Percentage = drProject.MF_Complete_Percentage,
                            MF_Level     = drProject.MF_Level,
                            MF_Rama      = drProject.MF_Rama,
                            MF_Post      = drProject.MF_Post,
                            MF_Agregat   = drProject.MF_Agregat,
                            MF_SH_Place  = drProject.MF_SH_Place,
                            MF_SH        = drProject.MF_SH,
                            MF_Time_Plan =
                                drProject.MF_Time_Plan == DateTime.MinValue
                                    ? (DateTime?)null
                                    : drProject.MF_Time_Plan,
                            MF_Time_Test_Actual =
                                drProject.MF_Time_Test_Actual == DateTime.MinValue
                                    ? (DateTime?)null
                                    : drProject.MF_Time_Test_Actual,
                            MF_Time = drProject.MF_Time == DateTime.MinValue ? (DateTime?)null : drProject.MF_Time,

                            #region OTK
                            Time_OTK_Plan =
                                drProject.Time_OTK_Plan == DateTime.MinValue
                                    ? (DateTime?)null
                                    : drProject.Time_OTK_Plan,

                            Time_OTK_G_Actual =
                                drProject.Time_OTK_G_Actual == DateTime.MinValue
                                    ? (DateTime?)null
                                    : drProject.Time_OTK_G_Actual,

                            Time_OTK_E_Actual =
                                drProject.Time_OTK_E_Actual == DateTime.MinValue
                                    ? (DateTime?)null
                                    : drProject.Time_OTK_E_Actual,
                            Is_OTK_G_NotNeed = drProject.Is_OTK_G_NotNeed,
                            Is_OTK_E_NotNeed = drProject.Is_OTK_E_NotNeed,

                            #endregion OTK
                        };

                        // Сообщения
                        foreach (AgrDataSet.CommentRow drComment in drProjects.GetCommentRows())
                        {
                            project.Messages.Add(new AgrProjectComment(drComment.Time, drComment.UserName,
                                                                       drComment.Value));
                        }

                        // Недокомплект
                        foreach (AgrDataSet.RequestRow drRequest in drProjects.GetRequestRows())
                        {
                            project.Requests.Add(new AgrRequest((OMTSRequestType)drRequest.Type, drRequest.Name)
                            {
                                TotalCount        = drRequest.TotalCount,
                                ExistCount        = drRequest.ExistCount,
                                Article           = drRequest.Article,
                                DateComplete_Plan = drRequest.DateComplete_Plan == DateTime.MinValue
                                    ? (DateTime?)null
                                    : drRequest.DateComplete_Plan,
                                DateComplete = drRequest.DateComplete == DateTime.MinValue
                                    ? (DateTime?)null
                                    : drRequest.DateComplete,
                                IsCustomerMaterials = drRequest.IsCustomerMaterials
                            });
                        }

                        projects.Add(project);
                    }
                }
                return(projects);
            }
        }