private CodeMemberMethod ResetChartControls()
        {
            CodeMemberMethod ResetChartControls = null;

            try
            {
                ResetChartControls = new CodeMemberMethod
                {
                    Name       = "ResetChartControls",
                    Attributes = MemberAttributes.Public | MemberAttributes.Final,
                    ReturnType = new CodeTypeReference(typeof(bool)),
                };

                CodeParameterDeclarationExpression parameter = new CodeParameterDeclarationExpression();
                parameter.Name      = "cContextItemsChart";
                parameter.Type      = new CodeTypeReference(typeof(Dictionary <String, Object>));
                parameter.Direction = FieldDirection.Ref;

                ResetChartControls.Parameters.Add(parameter);

                CodeTryCatchFinallyStatement tryBlock = new CodeTryCatchFinallyStatement();
                foreach (string sChartName in _ilbo.Charts.Select(c => c.Name).Distinct())
                {
                    CodeConditionStatement ifKeyExists = IfCondition();
                    ifKeyExists.Condition = BinaryOpertorExpression(MethodInvocationExp(MethodInvocationExp(VariableReferenceExp("cContextItemsChart"), "ContainsKey").AddParameter(PrimitiveExpression(string.Format("ICT_ILBO_CHART_{0}", sChartName))), "ToString"), CodeBinaryOperatorType.IdentityEquality, PrimitiveExpression("True"));
                    ifKeyExists.TrueStatements.Add(MethodInvocationExp(VariableReferenceExp("cContextItemsChart"), "Remove").AddParameter(PrimitiveExpression(string.Format("ICT_ILBO_CHART_{0}", sChartName))));
                    tryBlock.AddStatement(ifKeyExists);
                }
                tryBlock.AddStatement(ReturnExpression(PrimitiveExpression(true)));

                CodeCatchClause catchBlock = AddCatchBlock(tryBlock, "e");
                catchBlock.AddStatement(MethodInvocationExp(TypeReferenceExp("Trace"), "WriteLineIf").AddParameters(new CodeExpression[] { PrimitiveExpression(false), PrimitiveExpression("ResetChartControls"), MethodInvocationExp(GetProperty("e", "Message"), "ToString") }));

                ResetChartControls.AddStatement(tryBlock);

                ResetChartControls.AddStatement(ReturnExpression(PrimitiveExpression(false)));

                return(ResetChartControls);
            }
            catch (Exception ex)
            {
                throw new Exception(string.Format("ResetChartControls->{0}", ex.InnerException != null ? ex.InnerException.Message : ex.Message));
            }
        }
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        private CodeMemberMethod Set_DefaultNodeConfig_Tree()
        {
            CodeMemberMethod           Set_DefaultNodeConfig_Tree = null;
            CodeMethodInvokeExpression MethodInvokation           = null;

            try
            {
                Set_DefaultNodeConfig_Tree = new CodeMemberMethod
                {
                    Name       = "Set_DefaultNodeConfig_Tree",
                    Attributes = MemberAttributes.Public | MemberAttributes.Final,
                    ReturnType = new CodeTypeReference(typeof(Object))
                };

                //try block
                CodeTryCatchFinallyStatement tryblock = AddTryBlock(Set_DefaultNodeConfig_Tree);

                IEnumerable <IGrouping <string, Tree> > treeGroups = _ilbo.Trees.GroupBy(t => t.Name);

                foreach (IGrouping <string, Tree> treeGrp in treeGroups)
                {
                    Tree tree = treeGrp.First();

                    foreach (TreeInfo treeinfo in tree.Info)
                    {
                        tryblock.AddStatement(MethodInvocationExp(TypeReferenceExp("oDefaultNTConfig"), "Add").AddParameters(new Object[] { Convert.ToString(treeinfo.OpenImage), string.Format("{0}~~{1}~~{2}", tree.Name, treeinfo.NodeType, "vwt_openimage") }));
                        tryblock.AddStatement(MethodInvocationExp(TypeReferenceExp("oDefaultNTConfig"), "Add").AddParameters(new Object[] { Convert.ToString(treeinfo.NotExpandedImage), string.Format("{0}~~{1}~~{2}", tree.Name, treeinfo.NodeType, "vwt_notexpandedimage") }));
                        tryblock.AddStatement(MethodInvocationExp(TypeReferenceExp("oDefaultNTConfig"), "Add").AddParameters(new Object[] { Convert.ToString(treeinfo.ExpandableImage), string.Format("{0}~~{1}~~{2}", tree.Name, treeinfo.NodeType, "vwt_expandableimage") }));
                        tryblock.AddStatement(MethodInvocationExp(TypeReferenceExp("oDefaultNTConfig"), "Add").AddParameters(new Object[] { Convert.ToString(treeinfo.ExpandedImage), string.Format("{0}~~{1}~~{2}", tree.Name, treeinfo.NodeType, "vwt_expandedimage") }));
                        tryblock.AddStatement(MethodInvocationExp(TypeReferenceExp("oDefaultNTConfig"), "Add").AddParameters(new Object[] { Convert.ToString(treeinfo.CloseImage), string.Format("{0}~~{1}~~{2}", tree.Name, treeinfo.NodeType, "vwt_closeimage") }));
                        tryblock.AddStatement(MethodInvocationExp(TypeReferenceExp("oDefaultNTConfig"), "Add").AddParameters(new Object[] { Convert.ToString(treeinfo.CheckImage), string.Format("{0}~~{1}~~{2}", tree.Name, treeinfo.NodeType, "vwt_checkimage") }));
                        tryblock.AddStatement(MethodInvocationExp(TypeReferenceExp("oDefaultNTConfig"), "Add").AddParameters(new Object[] { Convert.ToString(treeinfo.UnCheckImage), string.Format("{0}~~{1}~~{2}", tree.Name, treeinfo.NodeType, "vwt_uncheckimage") }));
                        tryblock.AddStatement(MethodInvocationExp(TypeReferenceExp("oDefaultNTConfig"), "Add").AddParameters(new Object[] { Convert.ToString(treeinfo.PartialCheckImage), string.Format("{0}~~{1}~~{2}", tree.Name, treeinfo.NodeType, "chkbox_parial_chkimg") }));
                    }
                }

                tryblock.TryStatements.Add(ReturnExpression(SnippetExpression("null")));

                //catch block
                CodeCatchClause catchblock = AddCatchBlock(tryblock);

                MethodInvokation = MethodInvocationExp(TypeReferenceExp("Trace"), "WriteLineIf");
                AddParameters(MethodInvokation, new Object[] { PrimitiveExpression(false), PrimitiveExpression("Set_DefaultNodeConfig_Tree"), SnippetExpression("e.Message.ToString()") });
                catchblock.Statements.Add(MethodInvokation);

                catchblock.Statements.Add(ReturnExpression(SnippetExpression("null")));
            }
            catch (Exception ex)
            {
                throw new Exception(string.Format("GenerateTreeClass.Set_DefaultNodeConfig_Tree()->{0}", !object.Equals(ex.InnerException, null) ? ex.InnerException.Message : ex.Message));
            }
            return(Set_DefaultNodeConfig_Tree);
        }
예제 #3
0
        public override void AddMemberFunctions(ref CodeTypeDeclaration classObj)
        {
            foreach (Method method in this._brMethods)
            {
                CodeMemberMethod codeMemberMethod = new CodeMemberMethod
                {
                    Name       = string.Format("{0}Ex", method.Name.ToLower()),
                    Attributes = MemberAttributes.Public | MemberAttributes.Final,
                    ReturnType = new CodeTypeReference(typeof(long))
                };

                #region parameter addition
                if (method.AccessDatabase)
                {
                    codeMemberMethod.Parameters.Add(ParameterDeclarationExp(typeof(string), "szConnectionString"));
                    //if (_ecrOptions.InTD)
                    codeMemberMethod.Parameters.Add(ParameterDeclarationExp(typeof(string), "szInTD"));
                }
                foreach (Parameter param in method.Parameters.Where(p => p.Seg != null &&
                                                                    p.DI != null
                                                                    ).OrderBy(p => int.Parse(p.SequenceNo)))
                {
                    string sParamType = param.CategorizedDataType;
                    Object oParamtype = null;
                    switch (sParamType)
                    {
                    case DataType.INT:
                        oParamtype = typeof(long);
                        break;

                    case DataType.STRING:
                    case DataType.TIMESTAMP:
                    case DataType.VARBINARY:
                        oParamtype = typeof(string);
                        break;

                    case DataType.DOUBLE:
                        oParamtype = typeof(double);
                        break;

                    default:
                        oParamtype = typeof(string);
                        break;
                    }

                    CodeParameterDeclarationExpression parameter = new CodeParameterDeclarationExpression();
                    parameter.Name = param.Name;
                    parameter.Type = new CodeTypeReference((Type)oParamtype);
                    if (param.FlowDirection == FlowAttribute.OUT || param.FlowDirection == FlowAttribute.INOUT)
                    {
                        parameter.Direction = FieldDirection.Ref;
                    }
                    codeMemberMethod.Parameters.Add(parameter);
                }
                #endregion

                #region varibale declaration
                codeMemberMethod.AddStatement(DeclareVariable(typeof(SqlConnection), "con"));
                codeMemberMethod.AddStatement(DeclareVariable(typeof(SqlCommand), "command"));

                CodeTryCatchFinallyStatement tryBlock = AddTryBlock(codeMemberMethod);
                tryBlock.AddStatement(SnippetStatement("using(con = new SqlConnection())"));
                tryBlock.AddStatement(SnippetStatement("{"));
                tryBlock.AddStatement(SnippetStatement("using(command = new SqlCommand())"));
                tryBlock.AddStatement(SnippetStatement("{"));
                tryBlock.AddStatement(AssignVariable(GetProperty(VariableReferenceExp("con"), "ConnectionString"), VariableReferenceExp("szConnectionString")));
                tryBlock.AddStatement(MethodInvocationExp(VariableReferenceExp("con"), "Open"));
                tryBlock.AddStatement(AssignVariable(GetProperty(VariableReferenceExp("command"), "Connection"), VariableReferenceExp("con")));
                tryBlock.AddStatement(AssignVariable(GetProperty(VariableReferenceExp("command"), "CommandType"), GetProperty(VariableReferenceExp("CommandType"), "StoredProcedure")));
                tryBlock.AddStatement(AssignVariable(GetProperty(VariableReferenceExp("command"), "CommandText"), PrimitiveExpression(method.Name.ToLower() + "_sp")));


                foreach (Parameter param in method.Parameters.Where(p => p.Seg != null &&
                                                                    p.DI != null
                                                                    ).OrderBy(p => int.Parse(p.SequenceNo)))
                {
                    string sParamType = param.CategorizedDataType;
                    Object oParamtype = null;

                    CodeMethodInvokeExpression methodInvokation = MethodInvocationExp(GetProperty("command", "Parameters"), "Add");
                    methodInvokation.AddParameter(PrimitiveExpression(param.Name.ToLower()));

                    switch (sParamType)
                    {
                    case DataType.INT:
                        oParamtype = typeof(long);
                        methodInvokation.AddParameter(GetProperty(TypeReferenceExp(typeof(SqlDbType)), "Int"));
                        break;

                    case DataType.STRING:
                    case DataType.TIMESTAMP:
                    case DataType.VARBINARY:
                        oParamtype = typeof(string);
                        methodInvokation.AddParameter(GetProperty(TypeReferenceExp(typeof(SqlDbType)), "VarChar"));
                        break;

                    case DataType.DOUBLE:
                        oParamtype = typeof(double);
                        methodInvokation.AddParameter(GetProperty(TypeReferenceExp(typeof(SqlDbType)), "BigInt"));
                        break;

                    default:
                        oParamtype = typeof(string);
                        methodInvokation.AddParameter(GetProperty(TypeReferenceExp(typeof(SqlDbType)), "VarChar"));
                        break;
                    }
                    //tryBlock.AddStatement(AssignVariable(GetProperty(MethodInvocationExp(GetProperty(VariableReferenceExp("command"), "Parameters"), "Add").
                    //                                        AddParameters(new CodeExpression[] {    PrimitiveExpression(param.Name.ToLower()),
                    //                                                                                GetProperty(TypeReferenceExp(typeof(SqlDbType)),(oParamtype == typeof(long)) ?"Int":"VarChar")
                    //                                                                            }),
                    //                                        "Value"),
                    //                                     VariableReferenceExp(param.Name)));

                    tryBlock.AddStatement(AssignVariable(GetProperty(methodInvokation, "Value"), VariableReferenceExp(param.Name)));
                }
                if (_ecrOptions.InTD)
                {
                    tryBlock.AddStatement(AssignVariable(GetProperty(MethodInvocationExp(GetProperty("command", "Parameters"), "Add").AddParameters(new CodeExpression[] { PrimitiveExpression("intd"), GetProperty("SqlDbType", "Text") }), "Value"), VariableReferenceExp("szInTD")));
                }
                tryBlock.AddStatement(MethodInvocationExp(VariableReferenceExp("command"), "ExecuteNonQuery"));
                tryBlock.AddStatement(SnippetStatement("}"));
                tryBlock.AddStatement(SnippetStatement("}"));
                tryBlock.AddStatement(ReturnExpression(PrimitiveExpression(0)));

                #region catch and finally block
                tryBlock.AddCatch();
                tryBlock.FinallyStatements.Add(AssignVariable(VariableReferenceExp("con"), SnippetExpression("null")));
                tryBlock.FinallyStatements.Add(AssignVariable(VariableReferenceExp("command"), SnippetExpression("null")));
                #endregion

                codeMemberMethod.AddStatement(ReturnExpression(PrimitiveExpression(0)));
                #endregion

                classObj.Members.Add(codeMemberMethod);
            }
            //throw new NotImplementedException();
        }