Exemplo n.º 1
0
 /// <summary>
 /// Create a new instance of frmValue
 /// </summary>
 /// <param name="value">The expression value to edit</param>
 /// <param name="officeplate">The officeplate to edit</param>
 /// <param name="icon">The container of the component</param>
 public frmValue(string value, IOfficePlate officeplate, List<IComponent> list)
 {
     InitializeComponent();
     tbScript.Text = value;
     op = officeplate;
     listcomponent = list;
 }
Exemplo n.º 2
0
 /// <summary>
 /// Create a new instance of WordAutomationCom
 /// </summary>
 /// <param name="filename">Name of word file</param>
 /// <param name="plate">The WordPlate whose defination is used</param>
 public WordAutomationCom(string filename, IOfficePlate plate)
     : this()
 {
     FileName = filename;
     Plate = plate;
     ErrorReport = plate.MarkException;
 }
Exemplo n.º 3
0
 /// <summary>
 /// Analyze the type of tag and split type of tag and parameters of tag
 /// </summary>
 /// <param name="op">the officeplate whose tags defination is used</param>
 /// <param name="sTag">the whole string of Tag in Excel</param>
 /// <returns>object consists of type of tag and parameters of tag</returns>
 public static object[] AnalyzeTag(IOfficePlate op, string sTag)
 {
     int indexleftb = sTag.IndexOf('(');
     int indexrightb = sTag.IndexOf(')');
     if (indexleftb == -1 && indexrightb == -1)
     {
         return new object[] { TagType.Constant, new object[] { sTag.Trim() } };
     }
     else if (indexleftb > 0 && indexrightb > indexleftb)
     {
         string tagname = sTag.Substring(0, indexleftb).Trim();
         for(int i =0; i < op.DataSource.Count; i ++)
         {
             if((op.DataSource[i] as DataSourceItem).Caption == tagname)
             {
                 if (indexrightb > indexleftb + 1)
                 {
                     string tagparam = sTag.Substring(indexleftb + 1, indexrightb - indexleftb - 1);
                     return new object[] { TagType.DataSource, new object[] { i, tagparam.Trim() } };
                 }
                 else
                 {
                     return new object[] { TagType.UnKnown, new object[] { "Recognized as datasource tag, but no params" } };
                 }
             }
         }
         string tagpar = string.Empty;
         if (indexrightb > indexleftb + 1)
         {
             tagpar = sTag.Substring(indexleftb + 1, indexrightb - indexleftb - 1);
         }
         return new object[] { TagType.Function, new object[] { tagname, tagpar } };
     }
     else
     {
         return new object[] { TagType.UnKnown, new object[] { "Tag Format can't be recognized" } };
     }
 }
Exemplo n.º 4
0
 /// <summary>
 /// Get define expression tag
 /// </summary>
 /// <param name="tagName">The name of tag</param>
 /// <param name="op">The officeplate whose tags defination is used</param>
 /// <param name="format">String of format</param>
 /// <returns>The expression of tag</returns>
 public static string GetTagDefineExpression(string tagName, IOfficePlate op, ref string format)
 {
     foreach (TagItem ti in op.Tags)
     {
         if (ti.DataField == tagName)
         {
             format = ti.Format;
             return ti.Exp;
         }
     }
     return null;
 }
Exemplo n.º 5
0
        /// <summary>
        /// Convert expression to value
        /// </summary>
        /// <param name="expression">String of expression</param>
        /// <param name="dr">Datarow of Table</param>
        /// <param name="op">The officeplate whose tags defination is used</param>
        /// <param name="format">String of format</param>
        /// <returns>Value of result</returns>
        public static object[] GetExpressionValue(string expression, DataRow dr, IOfficePlate op, string format)
        {
            ArrayList list = SplitExpression(expression);

            bool isNumExp = true;
            object[] obj = ConvertExpToValue(list, ref isNumExp, dr, op);
            if ((PlateException)obj[0] != PlateException.None)
            {
                return obj;
            }
            else
            {
                if (isNumExp)
                {
                    ((ArrayList)obj[1]).Add("#");
                    ArrayList listRpn = ReversePN.GetRPN((ArrayList)obj[1]);
                    double dbrtn = ReversePN.CaculateValue(listRpn);
                    try
                    {
                        string strrtn = dbrtn.ToString(format);
                        return new object[] { PlateException.None, strrtn };
                    }
                    catch
                    {
                        return new object[] { PlateException.InvalidFormat, string.Format("Format:{0} is invalid", format) };
                    }
                }
                else
                {
                    return BuildString((ArrayList)obj[1]);
                }
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Convert each member of list to its value
        /// </summary>
        /// <param name="list">The list to process</param>
        /// <param name="isNumExp">The flag indicates whether is an digital expression</param>
        /// <param name="dr">Datarow of Table</param>
        /// <param name="op">The officeplate whose tags defination is used</param>
        /// <returns>A new list consist of value</returns>
        public static object[] ConvertExpToValue(ArrayList list, ref bool isNumExp, DataRow dr, IOfficePlate op)
        {
            isNumExp = true;
            string strop = "+-*/()^";
            for (int i = 0; i < list.Count; i++)
            {
                string member = list[i].ToString().Trim();
                if (!strop.Contains(member))
                {
                    object objmember = null;
                    if (member.StartsWith("_"))
                    {
                        objmember = GetSysParameters(member);
                        if (objmember == null)
                        {
                            return new object[] {PlateException.SystemParameterNotFound
                                , string.Format("Can not find system parameter:'{0}'", member) };
                        }
                    }
                    else if(member.StartsWith("\\"))
                    {
                        objmember = member.Substring(1);
                    }
                    else if (member.Split('{', '}').Length == 3)
                    {
                        string[] strfun = member.Split('{', '}');
                        string funcname = strfun[0];
                        string[] strparam = strfun[1].Split(',');
                        object[] objparam = new object[strparam.Length];
                        if (strparam.Length == 1 && strparam[0].Trim().Length == 0)
                        {
                            objparam = null;
                        }
                        else
                        {
                            for (int j = 0; j < strparam.Length; j++)
                            {
                                objparam[j] = strparam[j].Trim();
                            }
                        }
                        object[] obj;
                        if(op is OfficePlate)
                        {
                            obj = Expression.InvokeMethod(funcname, objparam, (op as OfficePlate).OwnerComp);
                        }
                        else
                        {
                            obj = Expression.InvokeMethod(funcname, objparam, (op as WebOfficePlate).Page);
                        }
                        if ((PlateException)obj[0] != PlateException.None)
                        {
                            return obj;
                        }
                        else
                        {
                            objmember = obj[1];
                        }
                    }
                    else if (member.Split('.').Length > 1)
                    {
                        try
                        {
                            objmember = Convert.ToDouble(member);
                        }
                        catch
                        {
                            object[] obj = null;
                            if (op is OfficePlate)
                            {
                                obj = GetPropertyValue(member, op as OfficePlate);
                            }
                            else
                            {
                                obj = GetPropertyValue(member, op as WebOfficePlate);
                            }
                            if ((PlateException)obj[0] != PlateException.None)
                            {
                                return obj;
                            }
                            else
                            {
                                objmember = obj[1];
                            }
                        }
                    }
                    else
                    {
                        try
                        {
                            objmember = Convert.ToDouble(member);
                        }
                        catch
                        {
                            if (dr == null)
                            {
                                return new object[] { PlateException.InvalidDataSourceItem
                                , string.Format("DataSource item can not be used in a non-datasouce tag's defination") };
                            }
                            if (dr.Table.Columns.Contains(member))
                            {
                                objmember = dr[member];
                            }
                            else
                            {
                                return new object[] { PlateException.ColumnNotFound
                                , string.Format("Can not find column:'{0}' in datasource", member) };
                            }
                        }

                    }
                    if (objmember is string || objmember is DateTime || objmember is bool)
                    {
                        isNumExp = false;
                    }
                    list[i] = objmember;
                }
            }
            return new object[] { PlateException.None, list };
        }
Exemplo n.º 7
0
 /// <summary>
 /// Run Automation
 /// </summary>
 /// <param name="op">The officeplate whose tags defination is used</param>
 /// <param name="sTag">The whole string of Tag in Excel</param>
 /// <returns>The value of Result</returns>
 public static object[] Run(IOfficePlate op, string sTag)
 {
     object[] objaTag = AnalyzeTag(op, sTag);
     return ProcessTag((TagType)objaTag[0], (object[])objaTag[1], op);
 }
Exemplo n.º 8
0
        /// <summary>
        /// Process all tag
        /// </summary>
        /// <param name="tagtp">The type of tag</param>
        /// <param name="Param">The param of tag</param>
        /// <param name="op">The officeplate whose tags defination is used</param>
        /// <returns>Object consist of plateexception and value</returns>
        public static object[] ProcessTag(TagType tagtp, object[] Param, IOfficePlate op)
        {
            switch (tagtp)
            {
                case TagType.Constant:
                    {
                        string param = Param[0].ToString();
                        return ProcessConstantTag(param,op);

                    }
                case TagType.DataSource:
                    {
                        int index = (int)Param[0];
                        string param = Param[1].ToString();
                        return ProcessDataSourceTag(index, param, op);
                    }
                case TagType.Function:
                    {
                        string name = Param[0].ToString();
                        string param = Param[1].ToString();
                        return ProcessFunctionTag(name, param, op);
                    }
                default:
                    {
                        string message = Param[0].ToString();
                        return new object[] { PlateException.InvalidTag, message };
                    }
            }
        }
Exemplo n.º 9
0
 /// <summary>
 /// process function tag
 /// </summary>
 /// <param name="funcname">The name of function to invoke</param>
 /// <param name="param">The parameters of function to invoke</param>
 /// <param name="op">The officeplate whose tags defination is used</param>
 /// <returns>Object consist of plateexception and value</returns>
 public static object[] ProcessFunctionTag(string funcname, string param, IOfficePlate op)
 {
     string format = string.Empty;
     string expression = GetTagDefineExpression(funcname, op, param, ref format);
     if (expression == null)
     {
         string[] strparam = param.Split(',');
         object[] objparam = new object[strparam.Length];
         if(strparam.Length == 1 && strparam[0].Trim().Length == 0)
         {
             objparam = null;
         }
         else
         {
             for (int i = 0; i < strparam.Length; i++)
             {
                 objparam[i] = strparam[i].Trim();
             }
         }
         if (op is OfficePlate)
         {
             return Expression.InvokeMethod(funcname, objparam, (op as OfficePlate).OwnerComp);
         }
         else
         {
             return Expression.InvokeMethod(funcname, objparam, (op as WebOfficePlate).Page);
         }
     }
     else
     {
         return Expression.GetExpressionValue(expression, null, op, format);
     }
 }
Exemplo n.º 10
0
        /// <summary>
        /// Process dataSource tag
        /// </summary>
        /// <param name="indexds">The index of datasource in offeceplate's datasource defination</param>
        /// <param name="param">The parameters of datasource tag</param>
        /// <param name="op">The officeplate whose tags defination is used</param>
        /// <returns>Object consist of plateexception and value</returns>
        public static object[] ProcessDataSourceTag(int indexds, string param, IOfficePlate op)
        {
            string[] strparam = param.Split(',');
            if (strparam.Length != 2)
            {
                return new object[] { PlateException.InvalidParameter, string.Format("Parameters of DataSource:'{0}' is invalid", ((DataSourceItem)op.DataSource[indexds]).Caption) };
            }
            //int rowindex = -1;
            DataView view = (DataView)((DataSourceItem)op.DataSource[indexds]).GetTable()[((DataSourceItem)op.DataSource[indexds]).DataMember];
            DataRow row = null;
            if(string.Compare(strparam[0].Trim(), "c",true) == 0)
            {
                if (((DataSourceItem)op.DataSource[indexds]).DataSource is Srvtools.InfoBindingSource)
                {
                    if (((((DataSourceItem)op.DataSource[indexds]).DataSource as Srvtools.InfoBindingSource).Current as DataRowView != null))
                    {
                        row = ((((DataSourceItem)op.DataSource[indexds]).DataSource as Srvtools.InfoBindingSource).Current as DataRowView).Row;
                    }
                    else
                    {
                        return new object[] { PlateException.None, string.Empty};
                    }
                }
                else if (((DataSourceItem)op.DataSource[indexds]).DataSource is Srvtools.WebDataSource)
                {
                    row = (((DataSourceItem)op.DataSource[indexds]).DataSource as Srvtools.WebDataSource).CurrentRow;
                    if (row == null)
                    {
                        return new object[] { PlateException.None, string.Empty };
                    }
                }
                else
                {
                    return new object[]{PlateException.InvalidParameter
                    ,string.Format("The first parameter of DataSource:'{0}' is invalid,'{1}' can not used in a non_bindingsource datasource",((DataSourceItem)op.DataSource[indexds]).Caption,strparam[0])};
                }
            }
            else
            {
                try
                {
                    int rowindex = Convert.ToInt32(strparam[0]);
                    if (rowindex < 0 || rowindex > view.Count - 1)
                    {
                        return new object[]{PlateException.InvalidParameter
                        ,string.Format("The first parameter of DataSource:'{0}' is invalid, row {1} does not exist",((DataSourceItem)op.DataSource[indexds]).Caption, rowindex.ToString())};
                    }
                    else
                    {
                        row = view[rowindex].Row;
                    }
                }
                catch
                {
                    return new object[]{PlateException.InvalidParameter
                    ,string.Format("The first parameter of DataSource:'{0}' is invalid,'{1}' can not be recognized as a number",((DataSourceItem)op.DataSource[indexds]).Caption,strparam[0])};
                }
            }

            string column = strparam[1].Trim();
            if(view.Table.Columns.Contains(column))
            {
                int indeximagecolumn = ((DataSourceItem)op.DataSource[indexds]).ImageColumns.IndexOf(column);
                if (indeximagecolumn == -1)
                {
                    return new object[] { PlateException.None, row[column] };
                }
                else
                {
                    if (view.Table.Columns[column].DataType == typeof(byte[]))
                    {
                        if (row[column] != DBNull.Value)
                        {
                            MemoryStream ms = new MemoryStream((byte[])row[column]);
                            try
                            {
                                Bitmap pic = new Bitmap(ms);
                                if (string.Compare(strparam[0].Trim(), "c", true) == 0)
                                {
                                    pic.Tag = false;
                                }
                                else
                                {
                                    pic.Tag = true;
                                }
                                return new object[] { PlateException.None, pic };
                            }
                            catch
                            {
                                return new object[] { PlateException.None, string.Empty };
                            }
                        }
                        else
                        {
                            return new object[] { PlateException.None, string.Empty };
                        }
                    }
                    else
                    {
                        string path = (((DataSourceItem)op.DataSource[indexds]).ImageColumns[indeximagecolumn] as DataSourceImageColumnItem).DefaultPath;
                        if (path.Length > 0)
                        {
                            path += "\\";
                        }
                        string filename = row[column].ToString();
                        if (filename.Length > 0)
                        {
                            byte[] objrtn = null;
                            if (op is OfficePlate)
                            {
                                object[] objcall = Srvtools.CliUtils.CallMethod("GLModule", "DownLoadFile", new object[] { path + filename });
                                if (objcall != null && objcall.Length == 3)
                                {
                                    objrtn = ((byte[])objcall[2]);
                                }
                            }
                            else
                            {
                                string mappath = (op as WebOfficePlate).Page.Server.MapPath(path + filename);
                                if (System.IO.File.Exists(mappath))
                                {
                                    objrtn = System.IO.File.ReadAllBytes(path + filename);
                                }
                            }
                            if (objrtn != null)
                            {
                                MemoryStream ms = new MemoryStream(objrtn);
                                Bitmap pic = new Bitmap(ms);
                                if (string.Compare(strparam[0].Trim(), "c", true) == 0)
                                {
                                    pic.Tag = false;
                                }
                                else
                                {
                                    pic.Tag = true;
                                }
                                return new object[] { PlateException.None, pic };
                            }
                            else
                            {
                                return new object[] { PlateException.None, string.Empty};
                            }
                        }
                        else
                        {
                            return new object[] { PlateException.None, string.Empty };
                        }
                    }
                }
            }
            else
            {
                string format = string.Empty;
                string expression = GetTagDefineExpression(column, op, ref format);
                if (expression == null)
                {
                    return new object[] { PlateException.TagDefineNotFound, string.Format("Can not find Constant Tag:'{0}' in TagDefination", column) };
                }
                else
                {
                    return Expression.GetExpressionValue(expression, row, op, format);
                }
            }
        }
Exemplo n.º 11
0
 /// <summary>
 /// Process constant tag
 /// </summary>
 /// <param name="param">The name of constant tag</param>
 /// <param name="op">The officeplate whose tags defination is used</param>
 /// <returns>Object consist of plateexception and value</returns>
 public static object[] ProcessConstantTag(string param, IOfficePlate op)
 {
     string format = string.Empty;
     string expression = GetTagDefineExpression(param, op, ref format);
     if (expression == null)
     {
         return new object[] { PlateException.TagDefineNotFound, string.Format("Can not find Constant Tag:'{0}' in TagDefination", param) };
     }
     else
     {
         return Expression.GetExpressionValue(expression, null,op, format);
     }
 }
Exemplo n.º 12
0
 /// <summary>
 /// Get define expression tag of function tag
 /// </summary>
 /// <param name="tagName">The name of tag</param>
 /// <param name="op">The officeplate whose tags defination is used</param>
 /// <param name="param">The param of function</param>
 /// <param name="format">String of format</param>
 /// <returns>The expression of tag</returns>
 public static string GetTagDefineExpression(string tagName, IOfficePlate op, string param, ref string format)
 {
     foreach (TagItem ti in op.Tags)
     {
         if (ti.DataField.StartsWith(tagName) && ti.DataField.Length > tagName.Length)
         {
             string defparam = ti.DataField.Substring(tagName.Length).Trim();
             if (defparam[0] == '(' && defparam[defparam.Length - 1] == ')')
             {
                 defparam = defparam.Replace("(", string.Empty).Replace(")", string.Empty);
                 string[] arrparam = param.Split(',');
                 string[] arrdefparm = defparam.Split(',');
                 if (arrparam.Length == arrdefparm.Length)
                 {
                     format = ti.Format;
                     string exp = ti.Exp;
                     for (int i = 0; i < arrparam.Length; i++)
                     {
                         exp = exp.Replace("@" + arrdefparm[i].Trim(), arrparam[i].Trim());
                     }
                     return exp;
                 }
             }
         }
     }
     return null;
 }