Beispiel #1
0
        private void BindGridView(string fileName, string filterOption)
        {
            var dbContext = new AFDDataContext();

            var where = new StringBuilder();
            var parms = new List <SqlParameter>();

            if (!fileName.Equals("All", StringComparison.CurrentCultureIgnoreCase))
            {
                where.Append("[file] = @file");
                parms.Add(new SqlParameter("@file", fileName));
            }
            if (filterOption.Equals("errorsonly", StringComparison.CurrentCultureIgnoreCase))
            {
                if (where.Length != 0)
                {
                    where.Append(" And ");
                }
                where.Append("checkResult > 1");
            }
            if (where.Length != 0)
            {
                where.Insert(0, "Where ");
            }
            this.GridView1.DataSource = dbContext.Customers.SqlQuery("Select * From CustomerDatas " + where.ToString(), parms.ToArray()).ToList();
            this.GridView1.DataBind();
        }
Beispiel #2
0
        public static void SaveItemsToDb(List <CustomerData> items)
        {
            var dbContext = new AFDDataContext();

            foreach (var item in items)
            {
                dbContext.Customers.Add(item);
            }
            dbContext.SaveChanges();
        }
Beispiel #3
0
        public static void TransferFinished(Dictionary <CustomerData, EvilReturn> results, Guid requestId)
        {
            var dbContext   = new AFDDataContext();
            var failedItems = new Dictionary <CustomerData, EvilReturn>();
            var builder     = new StringBuilder();
            int goodCount   = 0;

            foreach (var result in results)
            {
                var parms = new SqlParameter[] {
                    new SqlParameter("@status", System.Data.SqlDbType.TinyInt),
                    new SqlParameter("@hash", System.Data.SqlDbType.NVarChar),
                    new SqlParameter("@checkResult", System.Data.SqlDbType.TinyInt),
                    new SqlParameter("@checkerror", System.Data.SqlDbType.NVarChar),
                    new SqlParameter("@id", System.Data.SqlDbType.UniqueIdentifier)
                };
                if (result.Value.added.Equals("true", StringComparison.CurrentCultureIgnoreCase))
                {
                    goodCount++;
                    //result.Key.hash = result.Value.hash;
                    //result.Key.uploadstatus = 0;
                    parms[0].Value    = 3;
                    parms[1].Value    = result.Value.hash;
                    parms[2].Value    = result.Key.checkResult;
                    parms[3].SqlValue = ((result.Key.checkerror == null) ? DBNull.Value : (object)result.Key.checkerror);
                    parms[4].Value    = result.Key.id;
                    dbContext.Database.ExecuteSqlCommand(
                        "Update CustomerDatas " +
                        "Set uploadstatus = @status, hash = @hash, checkResult = @checkResult, checkerror = @checkerror " +
                        "Where id = @id",
                        parms.ToArray());
                }
                else
                {
                    //result.Key.hash = null;
                    //result.Key.uploadstatus = 2;    //  failed
                    parms[0].Value    = 2;
                    parms[1].Value    = "";
                    parms[2].Value    = result.Key.checkResult;
                    parms[3].SqlValue = result.Key.checkerror;
                    parms[4].Value    = result.Key.id;
                    dbContext.Database.ExecuteSqlCommand(
                        "Update CustomerDatas " +
                        "Set uploadstatus = @status, hash = @hash, checkResult = @checkResult, checkerror = @checkerror " +
                        "Where id = @id",
                        parms);
                    failedItems.Add(result.Key, result.Value);
                }
                //dbContext.Customers.Add(result.Key);
            }
            //dbContext.SaveChanges();
            builder.Append(string.Format("{0} orders successfully updated<br/>", goodCount));
            if (failedItems.Count != 0)
            {
                foreach (var item in failedItems)
                {
                    builder.Append(string.Format("Customer {0} was not updated. Error {1}<br/>", item.Key.customer, ((item.Value.errors.Length != 0) ? item.Value.errors[0] : "")));
                }
            }
            ThreadResult.Add(requestId.ToString(), builder.ToString()); // you  can add your result in second parameter.
        }