public void LocationCheckUpdate(LocationCheck locationCheck)
 {
     using (DbManager db = new DbManager("HandHeldDB"))
     {
         SqlQuery <LocationCheck> query = new SqlQuery <LocationCheck>();
         query.Update(db, locationCheck);
     }
 }
        public void LocationCheckUpdate(LocationCheck locationCheck, List <LocationCheckDetail> locationCheckDetail)
        {
            using (DbManager db = new DbManager("HandHeldDB"))
            {
                db.BeginTransaction();
                //master
                locationCheck.OfficerName = GetUserByCode(locationCheck.BranchCode, locationCheck.OfficerCode).Name;
                db.SetCommand(GetSql(57)
                              , db.Parameter("@Id", locationCheck.Id)
                              , db.Parameter("@Remark", locationCheck.Remark)
                              , db.Parameter("@OfficerCode", locationCheck.OfficerCode)
                              , db.Parameter("@OfficerName", locationCheck.OfficerName)).ExecuteNonQuery();

                //detail
                db.SetCommand(GetSql(58)).ExecuteForEach <LocationCheckDetail>(locationCheckDetail);

                db.CommitTransaction();
            }
        }
        public void LocationCheckAdd(string branchCode, LocationCheck locationCheck, List <LocationCheckDetail> locationCheckDetail)
        {
            using (DbManager db = new DbManager("HandHeldDB"))
            {
                try
                {
                    db.BeginTransaction();

                    var queryMaster = new SqlQuery <LocationCheck>();
                    locationCheck.CheckDate   = DateTime.Now;
                    locationCheck.BranchCode  = branchCode;
                    locationCheck.CheckerName = GetUserByCode(branchCode, locationCheck.CheckerCode).Name;
                    locationCheck.OfficerName = GetUserByCode(branchCode, locationCheck.OfficerCode).Name;

                    var locationCheckId = queryMaster.InsertWithIdentity(db, locationCheck);
                    var queryDetail     = new SqlQuery <LocationCheckDetail>();

                    var agendas = LocationCheckPeriodAgendaGetAll();

                    LocationCheckPeriodAgenda agenda;
                    foreach (var item in locationCheckDetail)
                    {
                        agenda = agendas.Find(p => p.Id == item.PeriodAgendaId);
                        item.LocationCheckID = locationCheckId;
                        item.AgendaCode      = agenda.AgendaTemplateCode;
                        item.AgendaName      = agenda.AgendaTemplateName;
                        if (item.IsChecked)
                        {
                            item.Score = agenda.MaxPoint;
                        }
                        else
                        {
                            item.Score = 0;
                        }
                        // no insert list because bug in bltoolkit transaction.
                        queryDetail.Insert(db, item);
                    }

                    var queryDepartment = new SqlQuery <LocationCheckDepartment>();
                    var depts           = SapDepartmentGetByLocationCode(locationCheck.BranchCode, locationCheck.WarehouseCode, locationCheck.Location);
                    foreach (var item in depts)
                    {
                        queryDepartment.Insert(db, new LocationCheckDepartment
                        {
                            LocationCheckId = locationCheckId,
                            Code            = item.DepartmentCode,
                            Name            = item.DepartmentName
                        });
                    }


                    //throw new Exception("blah?");
                    db.CommitTransaction();
                }
                catch (Exception ex)
                {
                    db.RollbackTransaction();
                    throw ex;
                }
            }
        }