Exemplo n.º 1
0
 protected override string ReplaceTemplates(string fileTexts)
 {
     fileTexts = base.ReplaceTemplates(fileTexts);
     fileTexts = fileTexts.Replace("#TABLENAMEORIGINAL#", TableName);
     fileTexts = fileTexts.Replace("#TABLENAME#", TableName.ToCamelCase());
     fileTexts = fileTexts.Replace("#STABLENAME#", TableName.ToCamelCase().ToLower());
     return(fileTexts.Replace("#COLUMNCOUNT#", ColumnCount.ToString()));
 }
Exemplo n.º 2
0
        /// <summary>
        /// 异步写入单行数据, 可多次执行, 之后执行 Close 方法关闭写入流.
        /// </summary>
        /// <typeparam name="T">要写入的数据对象类型</typeparam>
        /// <param name="rowData">要写入的数据对象实例</param>
        /// <param name="expression">处理对象实例,返回字段集合的方法.</param>
        /// <returns>Task</returns>
        public async Task WriteLineAsync <T>(T rowData, Func <T, List <string> > expression) where T : new()
        {
            if (this.CancelToken.IsCancellationRequested)
            {
                this.CancelToken.ThrowIfCancellationRequested();
            }

            if (rowData == null)
            {
                throw new ArgumentNullException("rowData");
            }

            if (expression == null)
            {
                throw new ArgumentNullException("expression");
            }

            //取转换后的行数据
            var row = expression.Invoke(rowData);

            //如果写入过一条数据, 则字段数固定. 如果再次写入的字段数不同, 报异常.
            if (this.ColumnCount > 0 && this.ColumnCount != row.Count)
            {
                throw new ArgumentException("the rowData count must be equal to " + ColumnCount.ToString());
            }

            List <string> rows = this.SerializeRows(row);

            await this.CsvStream.WriteLineAsync(rows[0]);

            this.TotalRowCount++;

            //设置字段数
            if (this.ColumnCount == 0)
            {
                this.ColumnCount = row.Count;
            }

            //发送通知
            if (Progress != null)
            {
                //如果取余数=0, 发送通知.
                if (TotalRowCount % this.WriteProgressSize == 0L)
                {
                    CsvWriteProgressInfo info = new CsvHelperAsync.CsvWriteProgressInfo();
                    info.CurrentRowCount = this.WriteProgressSize;
                    info.WirteRowCount   = this.TotalRowCount;
                    Progress.Report(info);
                }
            }
        }
Exemplo n.º 3
0
        public void SaveSettings(object sender, RoutedEventArgs e)
        {
            DataBase.SetSetting("WIDTH", WindowWidth.ToString());
            DataBase.SetSetting("HEIGHT", WindowHeight.ToString());
            DataBase.SetSetting("COLS", ColumnCount.ToString());
            DataBase.SetSetting("ROWS", RowCount.ToString());
            DataBase.SetSetting("TOPMOST", IsTopMost ? "TRUE" : "FALSE");
            DataBase.SetSetting("STARTUP", StartUp ? "TRUE" : "FALSE");
            InstallStartUp(StartUp);

            DataBase.SetTabs(Tabs);

            // 재시작
            System.Diagnostics.Process.Start(Application.ResourceAssembly.Location);
            Application.Current.Shutdown();
        }
Exemplo n.º 4
0
 private void ResizeOurself(int r, int c)
 {
     //adjust rows and cols, do nothing if they equal
     //
     while (c < ColumnCount)
     {
         Columns.RemoveAt(ColumnCount - 1);
     }
     while (c > ColumnCount)
     {
         AddColumn(ColumnCount.ToString());
     }
     while (r < RowCount)
     {
         Rows.RemoveAt(RowCount - 1);
     }
     while (r > RowCount)
     {
         AddRow(RowCount.ToString());
     }
 }
Exemplo n.º 5
0
 public void SetValue(Matrix4x4[] value)
 {
     // FIXME: All Matrix sizes... this will get ugly. -flibit
     unsafe
     {
         float *dstPtr = (float *)values;
         if (ColumnCount == 4 && RowCount == 4)
         {
             for (int i = 0; i < value.Length; i += 1, dstPtr += 16)
             {
                 dstPtr[0]  = value[i].M11;
                 dstPtr[1]  = value[i].M21;
                 dstPtr[2]  = value[i].M31;
                 dstPtr[3]  = value[i].M41;
                 dstPtr[4]  = value[i].M12;
                 dstPtr[5]  = value[i].M22;
                 dstPtr[6]  = value[i].M32;
                 dstPtr[7]  = value[i].M42;
                 dstPtr[8]  = value[i].M13;
                 dstPtr[9]  = value[i].M23;
                 dstPtr[10] = value[i].M33;
                 dstPtr[11] = value[i].M43;
                 dstPtr[12] = value[i].M14;
                 dstPtr[13] = value[i].M24;
                 dstPtr[14] = value[i].M34;
                 dstPtr[15] = value[i].M44;
             }
         }
         else if (ColumnCount == 3 && RowCount == 3)
         {
             for (int i = 0; i < value.Length; i += 1, dstPtr += 12)
             {
                 dstPtr[0]  = value[i].M11;
                 dstPtr[1]  = value[i].M21;
                 dstPtr[2]  = value[i].M31;
                 dstPtr[4]  = value[i].M12;
                 dstPtr[5]  = value[i].M22;
                 dstPtr[6]  = value[i].M32;
                 dstPtr[8]  = value[i].M13;
                 dstPtr[9]  = value[i].M23;
                 dstPtr[10] = value[i].M33;
             }
         }
         else if (ColumnCount == 4 && RowCount == 3)
         {
             for (int i = 0; i < value.Length; i += 1, dstPtr += 12)
             {
                 dstPtr[0]  = value[i].M11;
                 dstPtr[1]  = value[i].M21;
                 dstPtr[2]  = value[i].M31;
                 dstPtr[3]  = value[i].M41;
                 dstPtr[4]  = value[i].M12;
                 dstPtr[5]  = value[i].M22;
                 dstPtr[6]  = value[i].M32;
                 dstPtr[7]  = value[i].M42;
                 dstPtr[8]  = value[i].M13;
                 dstPtr[9]  = value[i].M23;
                 dstPtr[10] = value[i].M33;
                 dstPtr[11] = value[i].M43;
             }
         }
         else if (ColumnCount == 3 && RowCount == 4)
         {
             for (int i = 0; i < value.Length; i += 1, dstPtr += 16)
             {
                 dstPtr[0]  = value[i].M11;
                 dstPtr[1]  = value[i].M21;
                 dstPtr[2]  = value[i].M31;
                 dstPtr[4]  = value[i].M12;
                 dstPtr[5]  = value[i].M22;
                 dstPtr[6]  = value[i].M32;
                 dstPtr[8]  = value[i].M13;
                 dstPtr[9]  = value[i].M23;
                 dstPtr[10] = value[i].M33;
                 dstPtr[12] = value[i].M14;
                 dstPtr[13] = value[i].M24;
                 dstPtr[14] = value[i].M34;
             }
         }
         else if (ColumnCount == 2 && RowCount == 2)
         {
             for (int i = 0; i < value.Length; i += 1, dstPtr += 8)
             {
                 dstPtr[0] = value[i].M11;
                 dstPtr[1] = value[i].M21;
                 dstPtr[4] = value[i].M12;
                 dstPtr[5] = value[i].M22;
             }
         }
         else
         {
             throw new NotImplementedException(
                       "Matrix Size: " +
                       RowCount.ToString() + " " +
                       ColumnCount.ToString()
                       );
         }
     }
 }
Exemplo n.º 6
0
 public void SetValueTranspose(Matrix value)
 {
     // FIXME: All Matrix sizes... this will get ugly. -flibit
     unsafe
     {
         float *dstPtr = (float *)values;
         if (ColumnCount == 4 && RowCount == 4)
         {
             dstPtr[0]  = value.M11;
             dstPtr[1]  = value.M21;
             dstPtr[2]  = value.M31;
             dstPtr[3]  = value.M41;
             dstPtr[4]  = value.M12;
             dstPtr[5]  = value.M22;
             dstPtr[6]  = value.M32;
             dstPtr[7]  = value.M42;
             dstPtr[8]  = value.M13;
             dstPtr[9]  = value.M23;
             dstPtr[10] = value.M33;
             dstPtr[11] = value.M43;
             dstPtr[12] = value.M14;
             dstPtr[13] = value.M24;
             dstPtr[14] = value.M34;
             dstPtr[15] = value.M44;
         }
         else if (ColumnCount == 3 && RowCount == 3)
         {
             dstPtr[0] = value.M11;
             dstPtr[1] = value.M21;
             dstPtr[2] = value.M31;
             dstPtr[3] = value.M12;
             dstPtr[4] = value.M22;
             dstPtr[5] = value.M32;
             dstPtr[6] = value.M13;
             dstPtr[7] = value.M23;
             dstPtr[8] = value.M33;
         }
         else if (ColumnCount == 4 && RowCount == 3)
         {
             dstPtr[0]  = value.M11;
             dstPtr[1]  = value.M21;
             dstPtr[2]  = value.M31;
             dstPtr[3]  = value.M41;
             dstPtr[4]  = value.M12;
             dstPtr[5]  = value.M22;
             dstPtr[6]  = value.M32;
             dstPtr[7]  = value.M42;
             dstPtr[8]  = value.M13;
             dstPtr[9]  = value.M23;
             dstPtr[10] = value.M33;
             dstPtr[11] = value.M43;
         }
         else if (ColumnCount == 3 && RowCount == 4)
         {
             dstPtr[0]  = value.M11;
             dstPtr[1]  = value.M21;
             dstPtr[2]  = value.M31;
             dstPtr[3]  = value.M12;
             dstPtr[4]  = value.M22;
             dstPtr[5]  = value.M32;
             dstPtr[6]  = value.M13;
             dstPtr[7]  = value.M23;
             dstPtr[8]  = value.M33;
             dstPtr[9]  = value.M14;
             dstPtr[10] = value.M24;
             dstPtr[11] = value.M34;
         }
         else
         {
             throw new NotImplementedException(
                       "Matrix Size: " +
                       RowCount.ToString() + " " +
                       ColumnCount.ToString()
                       );
         }
     }
 }
Exemplo n.º 7
0
 public void SetValue(Matrix[] value)
 {
     // FIXME: All Matrix sizes... this will get ugly. -flibit
     unsafe
     {
         float *dstPtr    = (float *)values;
         int    curOffset = 0;
         if (ColumnCount == 4 && RowCount == 4)
         {
             for (int i = 0; i < value.Length; i += 1)
             {
                 dstPtr[curOffset++] = value[i].M11;
                 dstPtr[curOffset++] = value[i].M12;
                 dstPtr[curOffset++] = value[i].M13;
                 dstPtr[curOffset++] = value[i].M14;
                 dstPtr[curOffset++] = value[i].M21;
                 dstPtr[curOffset++] = value[i].M22;
                 dstPtr[curOffset++] = value[i].M23;
                 dstPtr[curOffset++] = value[i].M24;
                 dstPtr[curOffset++] = value[i].M31;
                 dstPtr[curOffset++] = value[i].M32;
                 dstPtr[curOffset++] = value[i].M33;
                 dstPtr[curOffset++] = value[i].M34;
                 dstPtr[curOffset++] = value[i].M41;
                 dstPtr[curOffset++] = value[i].M42;
                 dstPtr[curOffset++] = value[i].M43;
                 dstPtr[curOffset++] = value[i].M44;
             }
         }
         else if (ColumnCount == 3 && RowCount == 3)
         {
             for (int i = 0; i < value.Length; i += 1)
             {
                 dstPtr[curOffset++] = value[i].M11;
                 dstPtr[curOffset++] = value[i].M12;
                 dstPtr[curOffset++] = value[i].M13;
                 dstPtr[curOffset++] = value[i].M21;
                 dstPtr[curOffset++] = value[i].M22;
                 dstPtr[curOffset++] = value[i].M23;
                 dstPtr[curOffset++] = value[i].M31;
                 dstPtr[curOffset++] = value[i].M32;
                 dstPtr[curOffset++] = value[i].M33;
             }
         }
         else if (ColumnCount == 4 && RowCount == 3)
         {
             for (int i = 0; i < value.Length; i += 1)
             {
                 dstPtr[curOffset++] = value[i].M11;
                 dstPtr[curOffset++] = value[i].M12;
                 dstPtr[curOffset++] = value[i].M13;
                 dstPtr[curOffset++] = value[i].M21;
                 dstPtr[curOffset++] = value[i].M22;
                 dstPtr[curOffset++] = value[i].M23;
                 dstPtr[curOffset++] = value[i].M31;
                 dstPtr[curOffset++] = value[i].M32;
                 dstPtr[curOffset++] = value[i].M33;
                 dstPtr[curOffset++] = value[i].M41;
                 dstPtr[curOffset++] = value[i].M42;
                 dstPtr[curOffset++] = value[i].M43;
             }
         }
         else if (ColumnCount == 3 && RowCount == 4)
         {
             for (int i = 0; i < value.Length; i += 1)
             {
                 dstPtr[curOffset++] = value[i].M11;
                 dstPtr[curOffset++] = value[i].M12;
                 dstPtr[curOffset++] = value[i].M13;
                 dstPtr[curOffset++] = value[i].M14;
                 dstPtr[curOffset++] = value[i].M21;
                 dstPtr[curOffset++] = value[i].M22;
                 dstPtr[curOffset++] = value[i].M23;
                 dstPtr[curOffset++] = value[i].M24;
                 dstPtr[curOffset++] = value[i].M31;
                 dstPtr[curOffset++] = value[i].M32;
                 dstPtr[curOffset++] = value[i].M33;
                 dstPtr[curOffset++] = value[i].M34;
             }
         }
         else
         {
             throw new NotImplementedException(
                       "Matrix Size: " +
                       RowCount.ToString() + " " +
                       ColumnCount.ToString()
                       );
         }
     }
 }
Exemplo n.º 8
0
 public Matrix[] GetValueMatrixTransposeArray(int count)
 {
     // FIXME: All Matrix sizes... this will get ugly. -flibit
     Matrix[] result = new Matrix[count];
     unsafe
     {
         float *resPtr    = (float *)values;
         int    curOffset = 0;
         if (ColumnCount == 4 && RowCount == 4)
         {
             for (int i = 0; i < count; i += 1)
             {
                 result[i] = new Matrix(
                     resPtr[curOffset + 0],
                     resPtr[curOffset + 4],
                     resPtr[curOffset + 8],
                     resPtr[curOffset + 12],
                     resPtr[curOffset + 1],
                     resPtr[curOffset + 5],
                     resPtr[curOffset + 9],
                     resPtr[curOffset + 13],
                     resPtr[curOffset + 2],
                     resPtr[curOffset + 6],
                     resPtr[curOffset + 10],
                     resPtr[curOffset + 14],
                     resPtr[curOffset + 3],
                     resPtr[curOffset + 7],
                     resPtr[curOffset + 11],
                     resPtr[curOffset + 15]
                     );
                 curOffset += 16;
             }
         }
         else if (ColumnCount == 3 && RowCount == 3)
         {
             for (int i = 0; i < count; i += 1)
             {
                 result[i] = new Matrix(
                     resPtr[curOffset],
                     resPtr[curOffset + 3],
                     resPtr[curOffset + 6],
                     0.0f,
                     resPtr[curOffset + 1],
                     resPtr[curOffset + 4],
                     resPtr[curOffset + 7],
                     0.0f,
                     resPtr[curOffset + 2],
                     resPtr[curOffset + 5],
                     resPtr[curOffset + 8],
                     0.0f,
                     0.0f,
                     0.0f,
                     0.0f,
                     0.0f
                     );
                 curOffset += 9;
             }
         }
         else if (ColumnCount == 4 && RowCount == 3)
         {
             for (int i = 0; i < count; i += 1)
             {
                 result[i] = new Matrix(
                     resPtr[curOffset],
                     resPtr[curOffset + 4],
                     resPtr[curOffset + 8],
                     0.0f,
                     resPtr[curOffset + 1],
                     resPtr[curOffset + 5],
                     resPtr[curOffset + 9],
                     0.0f,
                     resPtr[curOffset + 2],
                     resPtr[curOffset + 6],
                     resPtr[curOffset + 10],
                     0.0f,
                     resPtr[curOffset + 3],
                     resPtr[curOffset + 7],
                     resPtr[curOffset + 11],
                     0.0f
                     );
                 curOffset += 12;
             }
         }
         else if (ColumnCount == 3 && RowCount == 4)
         {
             for (int i = 0; i < count; i += 1)
             {
                 result[i] = new Matrix(
                     resPtr[curOffset],
                     resPtr[curOffset + 3],
                     resPtr[curOffset + 6],
                     resPtr[curOffset + 9],
                     resPtr[curOffset + 1],
                     resPtr[curOffset + 4],
                     resPtr[curOffset + 7],
                     resPtr[curOffset + 10],
                     resPtr[curOffset + 2],
                     resPtr[curOffset + 5],
                     resPtr[curOffset + 8],
                     resPtr[curOffset + 11],
                     0.0f,
                     0.0f,
                     0.0f,
                     0.0f
                     );
                 curOffset += 12;
             }
         }
         else
         {
             throw new NotImplementedException(
                       "Matrix Size: " +
                       RowCount.ToString() + " " +
                       ColumnCount.ToString()
                       );
         }
     }
     return(result);
 }
Exemplo n.º 9
0
 public Matrix GetValueMatrixTranspose()
 {
     // FIXME: All Matrix sizes... this will get ugly. -flibit
     unsafe
     {
         float *resPtr = (float *)values;
         if (ColumnCount == 4 && RowCount == 4)
         {
             return(new Matrix(
                        resPtr[0],
                        resPtr[4],
                        resPtr[8],
                        resPtr[12],
                        resPtr[1],
                        resPtr[5],
                        resPtr[9],
                        resPtr[13],
                        resPtr[2],
                        resPtr[6],
                        resPtr[10],
                        resPtr[14],
                        resPtr[3],
                        resPtr[7],
                        resPtr[11],
                        resPtr[15]
                        ));
         }
         else if (ColumnCount == 3 && RowCount == 3)
         {
             return(new Matrix(
                        resPtr[0],
                        resPtr[3],
                        resPtr[6],
                        0.0f,
                        resPtr[1],
                        resPtr[4],
                        resPtr[7],
                        0.0f,
                        resPtr[2],
                        resPtr[5],
                        resPtr[8],
                        0.0f,
                        0.0f,
                        0.0f,
                        0.0f,
                        0.0f
                        ));
         }
         else if (ColumnCount == 4 && RowCount == 3)
         {
             return(new Matrix(
                        resPtr[0],
                        resPtr[4],
                        resPtr[8],
                        0.0f,
                        resPtr[1],
                        resPtr[5],
                        resPtr[9],
                        0.0f,
                        resPtr[2],
                        resPtr[6],
                        resPtr[10],
                        0.0f,
                        resPtr[3],
                        resPtr[7],
                        resPtr[11],
                        0.0f
                        ));
         }
         else if (ColumnCount == 3 && RowCount == 4)
         {
             return(new Matrix(
                        resPtr[0],
                        resPtr[3],
                        resPtr[6],
                        resPtr[9],
                        resPtr[1],
                        resPtr[4],
                        resPtr[7],
                        resPtr[10],
                        resPtr[2],
                        resPtr[5],
                        resPtr[8],
                        resPtr[11],
                        0.0f,
                        0.0f,
                        0.0f,
                        0.0f
                        ));
         }
         else
         {
             throw new NotImplementedException(
                       "Matrix Size: " +
                       RowCount.ToString() + " " +
                       ColumnCount.ToString()
                       );
         }
     }
 }
Exemplo n.º 10
0
        protected DataSet load(string stmt, string[] options, bool LogZero = false)
        {
            if (options != null)
            {
                if (options.Length > 0 && options[0] != null && options[0].Trim() != "")
                {
                    stmt = prepareStatement(stmt, options);
                }
            }
            //MessageBoxCustom.Show("Query = " + stmt);

            System.Data.SqlClient.SqlDataAdapter da = new System.Data.SqlClient.SqlDataAdapter(stmt, GlobalShared.CN.ConnectionString);
            DataSet ds = new DataSet(DS_DATA_SET);

            try
            {
                da.Fill(ds, (localTable == null || localTable.Trim().Equals("") ? "TABLE" : localTable));
                ColumnCount = ds.Tables[0].Columns.Count;
                if (LogZero && (ds == null || ds.Tables[0].Rows.Count == 0))
                {
                    GlobalShared.Log.Log((int)LogClass.logType.Warning, "No records returned [clsDb.load(stmt, options)]: columns=" + ColumnCount.ToString() + ", " + stmt, false);
                }
            }
            catch (System.Data.SqlClient.SqlException ex)
            {
                ErrorMessage = ex.Message;
                GlobalShared.Log.Log((int)LogClass.logType.ErrorCondition, "[clsDb.load(stmt, options)]: " + ex.Message + System.Environment.NewLine + "   Stmt: " + stmt, true);
                return(null);
            }
            catch (Exception ex)
            {
                ErrorMessage = ex.Message;
                GlobalShared.Log.Log((int)LogClass.logType.ErrorCondition, "[clsDb.load(stmt, options)]: " + ex.Message + System.Environment.NewLine + "   Stmt: " + stmt, true);
                return(null);
            }

            return(ds);
        }
Exemplo n.º 11
0
 protected DataSet loadAll(bool debug = false)
 {
     /* if (localCN.State != ConnectionState.Open)
      * {
      *  try
      *  {
      *      localCN.Open();
      *  }
      *  catch (System.Data.SqlClient.SqlException ex)
      *  {
      *      Log.Log((int)LogClass.logType.ErrorCondition, "Opening database: <" + localCN.ConnectionString + ">" + "\r\n" + "   " + loadAllStmt + "\r\n" + "   " + ex.Message, false, MessageBoxButtons.OK);
      *      return null;
      *  }
      *  catch (System.Exception ex)
      *  {
      *      Log.Log((int)LogClass.logType.ErrorCondition, "Opening database: <" + localCN.ConnectionString + ">" + "\r\n" + "   " + loadAllStmt + "\r\n" + "   " + ex.Message);
      *      return null;
      *  }
      * }   */
     try
     {
         if (debug)
         {
             GlobalShared.Log.debug = true;
             GlobalShared.Log.Log((int)LogClass.logType.Debug, "clsDB.loadAll [ConnectionString= " + GlobalShared.CN.ConnectionString + "]", false);
             GlobalShared.Log.debug = false;
         }
         if (debug)
         {
             GlobalShared.Log.debug = true;
             GlobalShared.Log.Log((int)LogClass.logType.Debug, "clsDB.loadAll [" + loadAllStmt + "]", false);
             GlobalShared.Log.debug = false;
         }
         //localCN.ConnectionString = connectionString;
         System.Data.SqlClient.SqlDataAdapter da = new System.Data.SqlClient.SqlDataAdapter(loadAllStmt, GlobalShared.CN.ConnectionString);
         DataSet ds = new DataSet(DS_DATA_SET);
         da.Fill(ds, DS_DATA_SET);
         ColumnCount = ds.Tables[0].Columns.Count;
         if (debug)
         {
             GlobalShared.Log.debug = true;
             GlobalShared.Log.Log((int)LogClass.logType.Debug, "clsDB.loadAll [ColumnCount= " + ColumnCount.ToString() + "]", false);
             GlobalShared.Log.debug = false;
         }
         return(ds);
     }
     catch (System.Data.SqlClient.SqlException ex)
     {
         ErrorMessage = ex.Message;
         Log.Log((int)LogClass.logType.ErrorCondition, "Error while retrieving records from " + localTable + ": " + ex.Message, false, MessageBoxButtons.OK);
         return(null);
     }
     catch (System.Exception ex)
     {
         ErrorMessage = ex.Message;
         Log.Log((int)LogClass.logType.ErrorCondition, "Error while retrieving records from " + localTable + ": " + ex.Message, false, MessageBoxButtons.OK);
     }
     return(null);
 }