Пример #1
0
        public Result InsertRecordToDb(InsertSqlRecordModel insertRecord)
        {
            using (SQLiteConnection connection = new SQLiteConnection("Data Source=" + dbPath))
            {
                connection.Open();

                var sql = insertRecord.CreateSqlInsertCmd();

                using (SQLiteCommand cmd = new SQLiteCommand(sql, connection))
                {
                    try
                    {
                        cmd.ExecuteNonQuery();
                    }
                    catch (Exception ex)
                    {
                        return(new Result {
                            success = false, msg = ex.Message
                        });
                    }
                }
            }

            return(new Result {
                success = true
            });
        }
Пример #2
0
        public Result InsertSupplyRowsToDb(int app_doc_id, ApplicationDocumentRow[] appDocRows)
        {
            using (SQLiteConnection connection = new SQLiteConnection("Data Source=" + dbPath))
            {
                connection.Open();

                foreach (var item in appDocRows)
                {
                    var ins = new SqlFieldModel[] {
                        new SqlFieldModel {
                            fieldName  = SUPPLY_DETAIL_TABLE.app_doc_id,
                            fieldValue = app_doc_id
                        },
                        new SqlFieldModel {
                            fieldName  = SUPPLY_DETAIL_TABLE.good_guid,
                            fieldValue = "'" + item.good_guid + "'"
                        },
                        new SqlFieldModel {
                            fieldName  = SUPPLY_DETAIL_TABLE.good_name,
                            fieldValue = "'" + item.good_name + "'"
                        },
                        new SqlFieldModel {
                            fieldName  = SUPPLY_DETAIL_TABLE.barcode,
                            fieldValue = "'" + item.barcode + "'"
                        },
                        new SqlFieldModel {
                            fieldName  = SUPPLY_DETAIL_TABLE.good_count_doc,
                            fieldValue = item.good_count_doc
                        },
                        new SqlFieldModel {
                            fieldName  = SUPPLY_DETAIL_TABLE.good_count_fact,
                            fieldValue = item.good_count_fact
                        },
                        new SqlFieldModel {
                            fieldName  = SUPPLY_DETAIL_TABLE.akcis,
                            fieldValue = item.akcis ? 1 : 0
                        },
                        new SqlFieldModel {
                            fieldName  = SUPPLY_DETAIL_TABLE.dopis,
                            fieldValue = item.dopis ? 1 : 0
                        },
                        new SqlFieldModel {
                            fieldName  = SUPPLY_DETAIL_TABLE.roworder,
                            fieldValue = 0
                        }
                    };

                    var insertRecord = new InsertSqlRecordModel
                    {
                        tableName = SUPPLY_DETAIL_TABLE.table_name,
                        Fields    = ins
                    };

                    var sql = insertRecord.CreateSqlInsertCmd();

                    using (SQLiteCommand cmd = new SQLiteCommand(sql, connection))
                    {
                        try
                        {
                            cmd.ExecuteNonQuery();
                        }
                        catch (Exception ex)
                        {
                            return(new Result {
                                success = false, msg = "Ошибка добавления в базу:" + Environment.NewLine +
                                                       item.good_name + Environment.NewLine + ex.Message
                            });
                        }
                    }
                }
            }

            return(new Result {
                success = true
            });
        }