コード例 #1
0
        internal SampleEntity GetSampleEntityById(Guid id)
        {
            var sanpleEntitiy = new SampleEntity();

            try
            {
                SqlProcedureCommand cmd = CreateProcedureCommand("dbo.GetSampleById");
                cmd.AppendGuid("@guidId", id);
                using (SqlDataReader reader = ExecuteCommandAndReturnReader(cmd))
                {
                    while (reader.Read())
                    {
                        sanpleEntitiy.Id       = reader.IsDBNull(0) ? Guid.Empty : reader.GetGuid(0);
                        sanpleEntitiy.FullName = reader.IsDBNull(1) ? string.Empty : reader.GetString(1);
                        sanpleEntitiy.Age      = reader.IsDBNull(2) ? 0 : reader.GetInt32(2);
                    }
                }
            }
            catch (SqlException e)
            {
                throw ReportAndTranslateException(e, "SampleEntity::GetAllSample");
            }
            return(sanpleEntitiy);
        }
コード例 #2
0
        protected byte[] ExecuteCommandAndReturnBinary(SqlProcedureCommand cmd)
        {
            try
            {
                using (SqlDataReader reader = cmd.ExecuteReader(CommandBehavior.SequentialAccess))
                {
                    if (reader.Read())
                    {
                        var binary = (byte[])reader[0];

                        if (reader.Read())
                        {
                            throw new StorageException("Multiple binary rows return. Expected one.");
                        }

                        return(binary);
                    }

                    return(null);
                }
            }
            catch (SqlException e)
            {
                string message;
                try
                {
                    message = DataDiagnostics.FormatCommandExceptionMessage(cmd.Command, 0);
                }
                catch (System.Exception ex)
                {
                    message = ex.Message;
                }

                throw ReportAndTranslateException(e, message);
            }
        }
コード例 #3
0
        internal List <BatchItemContent> GetBatchContents(Guid tenantId, Guid batchItemId)
        {
            List <BatchItemContent> batches = new List <BatchItemContent>();

            try
            {
                SqlProcedureCommand cmd = CreateProcedureCommand("dbo.BatchItemContent_Get");
                cmd.AppendGuid("@guidTenantId", tenantId);
                cmd.AppendGuid("@guidBatchItemId", batchItemId);
                using (SqlDataReader reader = ExecuteCommandAndReturnReader(cmd))
                {
                    while (reader.Read())
                    {
                        batches.Add(ReadBatchContent(reader));
                    }
                }
            }
            catch (SqlException e)
            {
                throw ReportAndTranslateException(e, "DataBatchItem::BatchItemContent_Get");
            }

            return(batches);
        }
コード例 #4
0
        internal void CreatePicklistLayout(Guid tenantId, LayoutModel layoutModel)
        {
            try
            {
                SqlProcedureCommand cmd = CreateProcedureCommand("dbo.PicklistLayout_Create");
                cmd.AppendGuid("@guidTenantId", tenantId);
                cmd.AppendGuid("@guidId", layoutModel.Id);
                cmd.AppendXSmallText("@strPicklistId", layoutModel.EntityId);
                cmd.AppendMediumText("@strName", layoutModel.Name);

                cmd.AppendInt("@intType", (int)layoutModel.LayoutType);

                if (layoutModel.Context > 0)
                {
                    cmd.AppendInt("@intLayoutContext", (int)layoutModel.Context);
                }

                cmd.AppendGuid("@guidUpdatedBy", layoutModel.ModifiedBy);

                if (!string.IsNullOrEmpty(layoutModel.Layout))
                {
                    cmd.AppendXLargeText("@defaultLayout", layoutModel.Layout);
                }
                if (layoutModel.DefaultLayout)
                {
                    cmd.AppendBit("@isDefault", layoutModel.DefaultLayout);
                }

                ExecuteCommand(cmd);
            }
            catch (SqlException e)
            {
                _log.Error(e);
                throw ReportAndTranslateException(e, "LayoutData::CreatePicklistLayout");
            }
        }
コード例 #5
0
        internal DefaultResourcelanguage dashboard(Guid tenantId)
        {
            var language = new DefaultResourcelanguage();

            try
            {
                SqlProcedureCommand cmd = CreateProcedureCommand("dbo.Tenant_GetDefaultLanguageDetails");
                cmd.AppendGuid("@guidTenantId", tenantId);
                using (SqlDataReader reader = ExecuteCommandAndReturnReader(cmd))
                {
                    while (reader.Read())
                    {
                        language.Key  = reader.IsDBNull(0) ? string.Empty : reader.GetString(0);
                        language.Text = reader.IsDBNull(1) ? string.Empty : reader.GetString(1);
                    }
                }
            }
            catch (SqlException e)
            {
                _log.Error(e);
                throw ReportAndTranslateException(e, "DataResource::Tenant_GetDefaultLanguageDetails");
            }
            return(language);
        }
コード例 #6
0
        internal CounterInfo GetCounter(Guid tenantId, Guid counterId)
        {
            CounterInfo counters = null;

            try
            {
                SqlProcedureCommand cmd = CreateProcedureCommand("dbo.Counter_GetById");
                cmd.AppendGuid("@guidTenantId", tenantId);
                cmd.AppendGuid("@guidCounterId", counterId);
                using (SqlDataReader reader = ExecuteCommandAndReturnReader(cmd))
                {
                    while (reader.Read())
                    {
                        counters = ReadInfo(reader);
                    }
                }
            }
            catch (SqlException e)
            {
                throw ReportAndTranslateException(e, "DataCounter::Counter_GetById");
            }

            return(counters);
        }
コード例 #7
0
 protected int ExecuteCommandWithValidResults(SqlProcedureCommand cmd, params int[] validResults)
 {
     return(ExecuteCommand(cmd, new CommandResultRangeValidator(validResults)));
 }
コード例 #8
0
 protected int ExecuteCommand(SqlProcedureCommand cmd)
 {
     return(ExecuteCommand(cmd, new DefaultCommandResultValidator()));
 }
コード例 #9
0
 protected T[] ExecuteArrayCommand <T>(SqlProcedureCommand cmd, ProcessDataRecordFunction <T> processRecordFunction)
 {
     return(ExecuteListCommand(cmd, processRecordFunction).ToArray());
 }
コード例 #10
0
        internal void InitializePicklistValue(List <string> picklists, Guid rootTenantCode, Guid initilizedTenantCode, Guid userId)
        {
            try
            {
                SqlProcedureCommand cmd = CreateProcedureCommand("dbo.PickListValue_Clone");
                cmd.AppendGuid("@rootTenantId", rootTenantCode);
                cmd.AppendGuid("@targetTenantId", initilizedTenantCode);
                cmd.AppendGuid("@guidUserId", userId);
                // var xmlIds = GetXmlString(picklists);
                // cmd.AppendXml("@xmlIds", xmlIds);
                ExecuteCommand(cmd);

                // foreach (var picklist in picklists)
                // {
                //     if (picklist != null && picklist != "")
                //     {
                //         var match = true;
                //         switch (picklist)
                //         {
                //             case "20001":
                //                 spname += "_Currency_";
                //                 break;
                //             case "20002":
                //                 spname += "_Country_";
                //                 break;
                //             case "20003":
                //                 spname += "_Language_";
                //                 break;
                //             case "20004":
                //                 spname += "_Timezone_";
                //                 break;
                //             case "20005":
                //                 spname += "_State_";
                //                 break;
                //             case "20006":
                //                 spname += "_City_";
                //                 break;
                //             case "20007":
                //                 spname += "_Municipality_";
                //                 break;
                //             case "20008":
                //                 spname += "_SecurityFunction_";
                //                 break;
                //             // case "20012":
                //             //     spname += "_MenuGroup_";
                //             //     break;
                //             case "10015":
                //                 spname += "_MenuGroup_";
                //                 break;
                //             default:
                //                 Console.WriteLine("Default case");
                //                 match = false;
                //                 break;

                //         }
                //         if(!match) continue;
                //         spname += "Clone";
                //         cmd = CreateProcedureCommand(spname);
                //         cmd.AppendXSmallText("@picklistId", picklist);
                //         cmd.AppendGuid("@rootTenantId", rootTenantCode);
                //         cmd.AppendGuid("@initilizedTenantId", initilizedTenantCode);
                //         ExecuteCommand(cmd);
                //     }
                // }

                // foreach(var picklist in picklists)
                // {
                //     spname = "10001" + "_PV_Create";

                //     SqlProcedureCommand cmd = CreateProcedureCommand(spname);
                //     cmd.AppendXSmallText("@strPicklistId", "10001");
                //     cmd.AppendGuid("@rootTenantId", rootTenantCode);
                //     cmd.AppendGuid("@targetTenantId", initilizedTenantCode);
                //     ExecuteCommand(cmd);
                // }

                // SqlProcedureCommand cmd = CreateProcedureCommand("dbo.EntityLayouts_Clone");
                // cmd.AppendGuid("@rootTenantId", rootTenantCode);
                // cmd.AppendGuid("@targetTenantId", initilizedTenantCode);
                // var xmlIds = GetXmlString(picklists);
                // cmd.AppendXml("@xmlIds", xmlIds);
                // ExecuteCommand(cmd);
                // return true;
            }
            catch (SqlException e)
            {
                _log.Error(e);
                throw ReportAndTranslateException(e, "InitializeData::PickList_Clone");
            }
        }
コード例 #11
0
        internal List <LayoutModel> GetLayoutsByEntityName(Guid tenantId, string entityContext, int type, bool isPicklist)
        {
            var layouts = new List <LayoutModel>();

            try
            {
                if (isPicklist)
                {
                    SqlProcedureCommand cmd = CreateProcedureCommand("dbo.Picklist_GetBy_Type");
                    cmd.AppendGuid("@guidTenantId", tenantId);
                    cmd.AppendXSmallText("@strEntityId", entityContext);
                    cmd.AppendInt("@intType", type);

                    using (SqlDataReader reader = ExecuteCommandAndReturnReader(cmd))
                    {
                        while (reader.Read())
                        {
                            var layoutInfo = new LayoutModel();
                            {
                                layoutInfo.Id       = reader.IsDBNull(0) ? Guid.Empty : reader.GetGuid(0);
                                layoutInfo.EntityId = reader.IsDBNull(1) ? String.Empty : reader.GetString(1);
                                layoutInfo.Name     = reader.IsDBNull(2) ? String.Empty : reader.GetString(2);
                                var layouttype     = reader.IsDBNull(3) ? 0 : reader.GetInt32(3);
                                var layouttypename = "";

                                if (layouttype > 0)
                                {
                                    layouttypename = Enum.GetName(typeof(LayoutType), layouttype);
                                }

                                layoutInfo.LayoutType     = (LayoutType)layouttype;
                                layoutInfo.LayoutTypeName = layouttypename;

                                var context     = reader.IsDBNull(4) ? 0 : reader.GetInt32(4);
                                var contextname = "";
                                if (context > 0)
                                {
                                    contextname = Enum.GetName(typeof(LayoutContext), context);
                                }

                                layoutInfo.Context      = (LayoutContext)context;
                                layoutInfo.ContextName  = contextname;
                                layoutInfo.Layout       = reader.IsDBNull(5) ? string.Empty : reader.GetString(5);
                                layoutInfo.ModifiedDate = reader.IsDBNull(6) ? DateTime.MinValue : reader.GetDateTime(6);
                                //layoutInfo.ModifiedByName = reader.IsDBNull(7) ? string.Empty : reader.GetString(7);
                                layoutInfo.DefaultLayout = !reader.IsDBNull(8) && reader.GetBoolean(8);
                                layoutInfo.ShowDefault   = reader.IsDBNull(8) ? "false" : reader.GetBoolean(8) ? "true" : "false";
                            };
                            layouts.Add(layoutInfo);
                        }
                    }
                }
                else
                {
                    SqlProcedureCommand cmd = CreateProcedureCommand("dbo.EntityLayout_GetBy_Type");
                    cmd.AppendGuid("@guidTenantId", tenantId);
                    cmd.AppendXSmallText("@strEntityId", entityContext);
                    cmd.AppendInt("@intType", type);

                    using (SqlDataReader reader = ExecuteCommandAndReturnReader(cmd))
                    {
                        while (reader.Read())
                        {
                            var layoutInfo = new LayoutModel();
                            {
                                layoutInfo.Id       = reader.IsDBNull(0) ? Guid.Empty : reader.GetGuid(0);
                                layoutInfo.EntityId = reader.IsDBNull(1) ? String.Empty : reader.GetString(1);
                                layoutInfo.Name     = reader.IsDBNull(2) ? String.Empty : reader.GetString(2);
                                var layouttype     = reader.IsDBNull(3) ? 0 : reader.GetInt32(3);
                                var layouttypename = "";

                                if (layouttype > 0)
                                {
                                    layouttypename = Enum.GetName(typeof(LayoutType), layouttype);
                                }

                                layoutInfo.LayoutType     = (LayoutType)layouttype;
                                layoutInfo.LayoutTypeName = layouttypename;

                                var context     = reader.IsDBNull(4) ? 0 : reader.GetInt32(4);
                                var contextname = "";
                                if (context > 0)
                                {
                                    contextname = Enum.GetName(typeof(LayoutContext), context);
                                }

                                layoutInfo.Context      = (LayoutContext)context;
                                layoutInfo.ContextName  = contextname;
                                layoutInfo.Layout       = reader.IsDBNull(5) ? string.Empty : reader.GetString(5);
                                layoutInfo.ModifiedDate = reader.IsDBNull(6) ? DateTime.MinValue : reader.GetDateTime(6);
                                //layoutInfo.ModifiedByName = reader.IsDBNull(7) ? string.Empty : reader.GetString(7);
                                layoutInfo.DefaultLayout = !reader.IsDBNull(8) && reader.GetBoolean(8);
                                layoutInfo.ShowDefault   = reader.IsDBNull(8) ? "false" : reader.GetBoolean(8) ? "true" : "false";

                                layoutInfo.Subtype = reader.IsDBNull(9) ? String.Empty : reader.GetString(9);
                            };
                            layouts.Add(layoutInfo);
                        }
                    }
                }
            }
            catch (SqlException e)
            {
                _log.Error(e);
                throw ReportAndTranslateException(e, "LayoutData::GetLayoutsByEntityName");
            }

            return(layouts);
        }
コード例 #12
0
        public LayoutModel GetPicklistLayoutDetailsById(Guid tenantId, Guid id)
        {
            var layout = new LayoutModel();

            try
            {
                SqlProcedureCommand cmd = CreateProcedureCommand("dbo.PicklistLayout_GetBy_Id");
                cmd.AppendGuid("@guidTenantId", tenantId);
                cmd.AppendGuid("@guidId", id);
                using (SqlDataReader reader = ExecuteCommandAndReturnReader(cmd))
                {
                    while (reader.Read())
                    {
                        //layout = ReadLayout(reader);

                        //var layoutInfo = new LayoutModel();

                        layout.Id       = reader.IsDBNull(0) ? Guid.Empty : reader.GetGuid(0);
                        layout.EntityId = reader.IsDBNull(1) ? String.Empty : reader.GetString(1);
                        layout.Name     = reader.IsDBNull(2) ? String.Empty : reader.GetString(2);
                        var layouttype     = reader.IsDBNull(3) ? 0 : reader.GetInt32(3);
                        var layouttypename = "";
                        // if (layouttype > 0)
                        // {
                        //     if (layouttype == 1)
                        //         layouttypename = "View";
                        //     else if (layouttype == 2)
                        //         layouttypename = "Form";
                        //     else if (layouttype == 3)
                        //         layouttypename = "List";
                        //     else if (layouttype == 4)
                        //         layouttypename = "Edit";
                        // }
                        if (layouttype > 0)
                        {
                            layouttypename = Enum.GetName(typeof(LayoutType), layouttype);
                        }

                        layout.LayoutTypeName = layouttypename;
                        layout.LayoutType     = (LayoutType)layouttype;

                        var context = reader.IsDBNull(4) ? 0 : reader.GetInt32(4);
                        layout.Context = (LayoutContext)context;
                        var contextname = "";
                        // if (context > 0)
                        // {
                        //     if (context == 1)
                        //         contextname = "New";
                        //     else if (context == 2)
                        //         contextname = "Edit";
                        // }
                        if (context > 0)
                        {
                            contextname = Enum.GetName(typeof(LayoutContext), context);
                        }

                        layout.ContextName  = contextname;
                        layout.Layout       = reader.IsDBNull(5) ? String.Empty : reader.GetString(5);
                        layout.ModifiedDate = reader.IsDBNull(6) ? DateTime.MinValue : reader.GetDateTime(6);
                        layout.ShowDefault  = reader.IsDBNull(7) ? "false" : reader.GetBoolean(7) ? "true" : "false";
                    }
                }
            }
            catch (SqlException e)
            {
                throw ReportAndTranslateException(e, "LayoutData::GetLayoutsDetailsById");
            }

            return(layout);
        }
コード例 #13
0
        internal List <LayoutModel> GetLayoutsByEntityName(Guid tenantId, string entityId)
        {
            var layouts = new List <LayoutModel>();

            try
            {
                SqlProcedureCommand cmd = CreateProcedureCommand("dbo.EntityLayout_GetBy_EntityId");
                cmd.AppendGuid("@guidTenantId", tenantId);
                cmd.AppendXSmallText("@strEntityId", entityId);
                using (SqlDataReader reader = ExecuteCommandAndReturnReader(cmd))
                {
                    while (reader.Read())
                    {
                        var layoutInfo = new LayoutModel();
                        {
                            layoutInfo.Id = reader.IsDBNull(0) ? Guid.Empty : reader.GetGuid(0);
                            //layoutInfo.Type = reader.IsDBNull(1) ? Guid.Empty : reader.GetGuid(1);
                            layoutInfo.EntityId = reader.IsDBNull(1) ? String.Empty : reader.GetString(1);
                            layoutInfo.Name     = reader.IsDBNull(2) ? String.Empty : reader.GetString(2);
                            var layouttype     = reader.IsDBNull(3) ? 0 : reader.GetInt32(3);
                            var layouttypename = "";
                            // if (layouttype > 0)
                            // {
                            //     if (layouttype == 1)
                            //         layouttypename = "View";
                            //     else if (layouttype == 2)
                            //         layouttypename = "Form";
                            //     else if (layouttype == 3)
                            //         layouttypename = "List";
                            //     else if (layouttype == 4)
                            //         layouttypename = "Edit";
                            // }

                            if (layouttype > 0)
                            {
                                layouttypename = Enum.GetName(typeof(LayoutType), layouttype);
                            }

                            layoutInfo.LayoutTypeName = layouttypename;

                            var subtype = reader.IsDBNull(4) ? "" : reader.GetString(4);
                            // var subtypename = "";
                            // if (subtype != "")
                            // {
                            //     if (subtype == "EN10003-ST01")
                            //         subtypename = "Employee";
                            //     else if (subtype == "EN10003-ST02")
                            //         subtypename = "Consultant";
                            //     else if (subtype == "EN10001-ST01")
                            //         subtypename = "Standard";
                            //     else if (subtype == "EN10002-ST01")
                            //         subtypename = "Department";
                            //      else if (subtype == "EN10002-ST02")
                            //         subtypename = "Company";
                            // }
                            layoutInfo.Subtype = subtype;
                            //layoutInfo.SubtypeeName = subtypename;

                            var context     = reader.IsDBNull(5) ? 0 : reader.GetInt32(5);
                            var contextname = "";
                            // if (context > 0)
                            // {
                            //     if (context == 1)
                            //     {
                            //         contextname = "New";
                            //         layoutInfo.Context = LayoutContext.New;
                            //     }
                            //     else if (context == 2)
                            //     {
                            //         contextname = "Edit";
                            //         layoutInfo.Context = LayoutContext.Edit;
                            //     }
                            // }
                            if (context > 0)
                            {
                                contextname = Enum.GetName(typeof(LayoutContext), context);
                            }

                            layoutInfo.Context        = (LayoutContext)context;
                            layoutInfo.ContextName    = contextname;
                            layoutInfo.ModifiedDate   = reader.IsDBNull(6) ? DateTime.MinValue : reader.GetDateTime(6);
                            layoutInfo.ModifiedByName = reader.IsDBNull(7) ? string.Empty : reader.GetString(7);
                            layoutInfo.Layout         = reader.IsDBNull(8) ? string.Empty : reader.GetString(8);
                            layoutInfo.DefaultLayout  = !reader.IsDBNull(9) && reader.GetBoolean(9);
                            layoutInfo.LayoutType     = (LayoutType)layouttype;
                            layoutInfo.ShowDefault    = reader.IsDBNull(9) ? "false" : reader.GetBoolean(9) ? "true" : "false";
                        };
                        layouts.Add(layoutInfo);
                    }
                }
            }
            catch (SqlException e)
            {
                _log.Error(e);
                throw ReportAndTranslateException(e, "LayoutData::GetLayoutsByEntityName");
            }

            return(layouts);
        }